Generate A Process Tree

This shouldn’t be a very long (or complicated) article as we’re simply going to cover one way to generate a process tree. This is more useful than it may sound, especially in process management.

We’ll be doing this in distros that support apt. So, that’d be distros like Debian, Ubuntu, Linux Mint, Elementary, and many others. That’s distros within the Debian family. That’s a good chunk of the available distros, so this will apply to many of you.

It’s not that this won’t work on other distros. It’s that I haven’t tested this on other distros. You can likely follow along and figure it out with your package manager, I’ve just not done so. I do have a limited amount of time and the only human resource I have is myself. Man, I could use an editor!

For the record, this seems like something you’ll find installed by default on any major system. You may not need to install anything at all. This might just be already available.

Anyhow… About processes…

Everything running on Linux is a process. There are a whole lot of processes that make up a running system. For the most part, you can ignore all this and keep computing. However, when you troubleshoot a system you may be interested in which processes are running. If you’re recovering from a slow system, you may be interested in killing processes.

One process may spawn other processes. For example, you may have a browser with open tabs. The browser is itself one process. The open tabs may be separate processes. This is a good thing for things like compartmentalization and even security, but that’s outside of the scope of this article.

So, what tools will we be using?

psmisc:

I believe the correct term for psmisc is that it’s a meta-package. That is, psmisc is a package that contains some other tools. If you want to follow along with this article, that’s the package you’ll likely want to install. I’ll cover installing it with apt, which is nice.

If you’re interested in psmisc, here’s the psmisc project page. The package includes the following applications:

  • fuser – Identifies processes using files or sockets
  • killall – kills processes by name, e.g. killall -HUP named
  • prtstat – prints statistics of a process
  • pslog – prints log path(s) of a process
  • pstree – shows the currently running processes as a tree
  • peekfd – shows the data travelling [sic] over a file descriptor

Of these, we’re interested in ‘pstree’. We have mentioned the killall command before and chances are that you won’t need to install anything for this at all. I did mention that above…

pstree:

This is the tool we’ll be using to generate a process tree. It comes with the above package and is one of those tools I think is likely available by default. I’ll cover how to use apt to install it below, but it seems like one of those things that you’re going to find on other distros. You’ll likely find that it’s installed by default on all those distros.

You can verify that you have this available with the following command:

The output should match this:

Don’t worry if that’s not available, we’ll install it below.

If you want to generate a process tree, you’ll see that the man page confirms that this is a good tool to do so, though the name should have clued you in. To read the man page, just run this command:

See? It’s not all that involved. It’s a pretty simple application.

Generate A Process Tree:

To generate a process tree in Linux, you’ll need an open terminal. Well, if you’re going to use pstree to generate a process tree in Linux, you will need an open terminal. Most of you can just open a terminal by pressing CTRL + ALT + T on your keyboard.

With your terminal open, let’s make sure that you have installed psmisc.

Now that you have psmisc installed, you can use the pstree command. Don’t blame me for this, I didn’t do it. 

You can simply run the command as it stands:

However, I previously wrote this article:

How To: Kill Processes By Their PID (Process ID)

I want to tie into that article. You can use the pstree command, which is a nice and easily understood output, to show the PID. That command would look like this command:

However, there’s a more useful command for those dealing with sudden issues. You can use a flag known as --color=age to get an idea about how new the processes are.

Green would be within the past 60 seconds, yellow would be within the past hour – or so I’m told. Every time I try, it shows up red. You can try it if you want, like so:

Good luck with that one! Seriously… Good luck!

Even if that doesn’t work, you can now generate a process tree to show the running processes on your system. This seems like a good thing to know.

Closure:

I was recently asked if I was running out of ideas for articles and the answer I gave them was that I am not. There’s always something to write about, even if it’s just a simple task like generating a process tree. Ideally, these articles will stand as a solution for those with specific problems. This is one of those articles.

Don’t forget that you can sponsor an article!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Monitor Wireless Link Quality

If you’ve ever had issues with your wireless connection, and many of us have, you might have wanted to monitor wireless link quality. This is a good task for an article, so let’s learn together one way to monitor wireless link quality. This will be a pretty easy article to follow.

You need a wireless adapter and wireless connection to follow along with this article. It’s not complicated, but you will need those things. Even if you don’t use wireless often, you might want to learn how to monitor the link’s quality – just in case you’re put in a position where you’re using wireless. It’s better to be prepared!

Wireless connectivity issues have plagued many people. Some of those people will jump to it being a hardware problem, like a driver acting up. They’ll try all sorts of things before checking the link quality. I’d suggest checking link quality early on in the troubleshooting process.

If you don’t know, wireless signal strength is measured in decibel milliwatts (dBm). They’re measured between 0 and -100 dBm. In this case, higher is better. -30 is perfect and -90 is disconnected. In simple terms, -30 is closer to 0. I don’t have a great connection, but it’s adequate. 

We won’t need to install any tools for this exercise. You have everything you need already installed and enabled, or you should. These are fairly basic low-level commands. They’ll be a part of any major distro for regular desktop use.

So, what will we be using?

The watch command:

The watch command is used with other applications, allowing you to monitor the process and to get continually updated information from that command. For example, the following command will watch your memory usage:

If you check the man page (with man watch), you’ll see that this is the correct tool for the job. You’ll also see that it’s not that difficult to learn how to use the watch command.

I’ve not yet written a watch article, but it’s pretty basic. In this case, we’ll introduce the -n flag but that’s just an indicator of frequency. You could simply use the watch command without any flag and it’ll refresh every two seconds. So, there’s that.

If you want to verify that watch is installed before going further, just run this:

The output should match this:

Which is where these sorts of things belong.

By the way, I’ve covered the which command before:

Find A Command’s Binary

You could also use the ‘whereis’ command.

Another Way To Find The Binary For A Specific Command

See? Lots of information is available. 

The cat Command:

We’ll also be using the cat command. The cat command is used to show the text in a file. When used in conjunction with the watch command, you can monitor a file to see if it changes. That’s exactly what we’ll be doing in this article.

Once again, you can check the man page ( man cat) for more information, but doing so will show you that the cat command is described as such:

cat – concatenate files and print on the standard output

The cat command is also useful for linking things together, such as the content from multiple files. We’re just concerned with the standard output (that’s what shows up in your terminal) and printing to said standard output. 

You can verify that cat is installed with:

Of course, the output is:

You can also read:

A Quick Look At The Cat Command

It’s not something you should have to install. Any desktop (or server) is going to include these two commands by default. They’re considered basic building blocks of a POSIX-compliant system. That’s something we all want!

Those are the only two tools you’ll need if you want to …

Monitor Wireless Link Quality:

If the commands mentioned in the intro section weren’t enough of a clue, this is one of those things you do in the terminal. That’s also something your distro came equipped with. Most folks should be able to open their default terminal emulator by pressing CTRL + ALT + T.

With your terminal open, you can check the current status of your wireless connection’s link quality. You simply need to run the following command:

That output is just for a single snapshot in time. If you’re having connectivity issues, you may want to monitor the state of your wireless connection over time. That’s why we use the watch command.

In its basic form, a command to monitor wireless link quality would look like:

That will run the cat /proc/net/wireless command every two seconds and output the results to your terminal (that is standard output). That’s all you need.

Of course, you can change that watch command a bit to change the frequency. You can make it more or less frequent, but the syntax is simple.

A reasonable interval might be every 10 seconds. That looks like this:

Every ten seconds, your system will run the command and output the results to the terminal you used to run said command. It’s quite basic, I’d think. 

While you probably don’t want to do so for this command, you could use decimal values. If you wanted the command to run 5 times every second, your input would be:

Here’s an example of that command. Yes, I made you a video!

The quality of the link is as a percentage. No, I do not know why. If you know why, leave a comment. The noise is measured according to dBm. If you’ve ever heard the expression ‘signal to noise ratio’ this is a good example of this. You want more signal and less noise, so you want a higher signal-to-noise ratio – which is something people often get backward when used conversationally.

This just shows you something you can do with just two basic Linux commands. That’s just two commands that you have installed already and you can use them to monitor wireless link quality. There’s nothing fancy here. There’s nothing advanced here. You can perform this sort of troubleshooting without any additional applications being installed – and you probably should do so if you’re having wireless connectivity issues.

Oh, before I forget, you can exit the watch command by pressing CTRL + C. That’s about all you’ll really need to know.

Closure:

One of the reasons why I wrote this article was because I wanted to show something that looks advanced but isn’t. This isn’t something that requires much. You only need the tools you have installed already. These tools are going to be available on any Linux desktop (and server) you are likely to touch. 

It also seems like a good idea to share how you can monitor wireless link quality in the Linux terminal. It’s something everyone can do and it’s something you can remember easily enough. If you’re having wireless issues, check to ensure that you have a good signal. It’s as basic as checking to make sure the power cord is plugged in and the device is turned on.

Don’t forget that you can sponsor an article. LOL You can do this even without something to promote. It’d pretty much be a donation, but you’d get a cool message and a link to almost anything you want. (If it’s just a donation and a personal thing, you can do so for much cheaper than the listed price.) I’m hoping to turn this sponsorship thing into a thing, meaning no more of the ads folks are used to and block.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

View Disk Usage

This article might seem like it has been written before but this is an entirely new way to view disk usage. To write this article I had to write two other articles. Tell me that that doesn’t sound like fun!

So, let’s see here… And, yes, I’m aware that they’re not disks anymore.

Yup. It’s official. There are too many ways to view disk usage in Linux – especially in the terminal. Why am I writing yet another article on the subject of disk usage? Because I can! I love showing how there are many ways to do the same thing in Linux. This is great because you can pick and use your favorite methods.

As for the subject of monitoring disk usage…

Monitor Disk Usage With GDU
Show Disk Usage With ‘ncdu’
A Few Ways To Visualize Disk Usage In Linux
How To: Check Disk Usage With ‘df’
Yet Another Way To Check Filesystem Space Use

Those are just the first five links when I searched for ‘disk usage’. That’s just five ways to check disk usage in Linux. I’m willing to bet that we can easily come up with five more ways to do this.

What’s special about this way of viewing disk usage?

Well, today we’ll be monitoring your drive space with a tool written in Python. You’ll need to enable PIP, a Python packaging tool. Once you’ve done that, this is universal. It will work in any distro that supports PIP – which, as you’ll see, is just about every major distro on the planet.

Read the following before going further:

Install Python’s PIP Part One
Install Python’s PIP Part Two

If you haven’t already installed Python’s PIP, this article will be of no use to you. You’ll need PIP enabled to proceed. You should also add the $PATH as defined in the second article. From here on out, the article will assume you’ve done both of those things.

View Disk Usage With Vizex:

The tool we’ll be using is known as Vizex. You can see the Vizex project page here. If you bother going there, you’ll see that Vizex is indeed the correct tool for the job. You’ll see that this is (one of the many) correct tools for the job.

vizex is the terminal program for the UNIX/Linux systems which helps the user to visualize the disk space usage for every partition and media on the user’s machine. vizex is highly customizable and can fit any user’s taste and preferences.

Hmm… It is at this point that I noticed that they don’t capitalize it. I’m going to capitalize it because it’s keeping the system from saying I didn’t spell it properly. 

Anyhow, as you’re using PIP, you’ll need an open terminal. You can use your GUI to open your terminal. On many systems, just press CTRL + ALT + T and your default terminal will open.

To install Vizex, run the following command:

If you’ve never installed a Python package with PIP before, then be sure to keep an eye on the screen. It’s a fascinating process and watching stuff happen in the terminal is pretty sweet!

Now that you have Vizex installed, you simply run that command in the terminal. If you didn’t follow the 2nd part of the Python PIP article you’ll have to specify the path. That’s just silly. Follow the 2nd article (it’s really easy) and you don’t have to deal with that. 

Using Vizex:

Anyhow, that command is simply:

It will even color-code your drives. If they’re close to full, they’ll be red and blink (missed in the screenshot below). If you’re moderately full, they’ll be listed in the yellow. I wanted to use Vizex to view a computer will all sorts of drives, so I did! That’s how you ended up with this screenshot:

using vizex to view disk usage
If this isn’t self-explanatory, I don’t know what is! It’s so simple that I can figure it out!

If that isn’t one of the easiest ways to view disk usage, I don’t know what is. This is just one of the many reasons why you should have Python’s PIP installed. There’s a bunch of software that’s available if you just know where to look. It took a while, but I finally got around to sharing this information. In my defense, it did take a couple of articles to share it properly.

Closure:

There are all sorts of ways to view disk usage. This is just another way, though it’s an interesting way. I’m quite sure that I’ll cover this very same subject again in another article. For now, I’ve covered a way to do so with Python and that’s something different than you’ve previously seen on the site.

I may not place ads on the site and just opt to accept sponsored articles as a way to cover the bills. That seems like a good thing to do. Some stuff may already be in the works, so look for that in the future. If you’re interested in sponsoring an article, be sure to hit me up. We get good traffic and rank well in the search engines. So, get some extra traffic and some SEO benefits by sponsoring an article!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Mastering Efficiency: Unleashing the Power of Bash Aliases

In the realm of command-line prowess, efficiency is king, such as Bash aliases. Every keystroke saved is a victory, and every shortcut mastered is a step toward domination over the terminal.

Among the arsenal of tools at your disposal, one weapon stands out as a champion of efficiency: Bash aliases. These humble shortcuts can transform your command-line experience from mundane to magnificent, allowing you to wield the power of complex commands with the simplicity of a single word.

Join us on a journey as we delve into the world of Bash aliases and unlock their full potential.

What are Bash Aliases?

Bash aliases are custom shortcuts or abbreviations that you can create to simplify and speed up your command-line tasks. They allow you to define your own commands or override existing ones with your preferred options or parameters.

Think of them as your personal command-line assistant, ready to execute your commands at a moment’s notice.

Why Use Bash Aliases?

The benefits of Bash aliases are manifold:

  1. Speed: With aliases, you can execute complex commands with just a few keystrokes, saving valuable time and effort.

  2. Simplicity: Long and convoluted commands can be distilled into concise aliases, making your command-line interactions more intuitive and less error-prone.

  3. Customization: Aliases are highly customizable, allowing you to tailor your command-line environment to suit your specific needs and preferences.

  4. Productivity: By automating repetitive tasks, aliases can significantly boost your productivity and streamline your workflow.

How to Create Bash Aliases

Creating Bash aliases is a breeze. Open your .bashrc  file, located in your home directory, using your favorite text editor (such as Nano). Then, add your alias definitions to the file using the following syntax:

Replace shortcut with the alias you want to create and command with the command you want to associate with the alias. For example:

This alias allows you to list all files in the current directory in a long listing format with file details.

Once you’ve added your aliases, save the .bashrc file and either restart your terminal or run source ~/.bashrc to apply the changes.

Examples of Useful Bash Aliases

Here are some examples of useful Bash aliases to get you started:

Best Practices for Bash Aliases

To make the most of Bash aliases, keep the following best practices in mind:

  1. Choose meaningful names: Use descriptive names for your aliases to make them easy to remember and understand.

  2. Avoid overriding existing commands: Be cautious when overriding existing commands with aliases to prevent confusion and unintended consequences.

  3. Document your aliases: Consider adding comments to your .bashrc  file to document your aliases and their purposes for future reference.

  4. Stay organized: Group related aliases together and organize them logically within your .bashrc  file for easier management.

Conclusion

In the fast-paced world of the command line, efficiency reigns supreme. Bash aliases empower you to wield the full power of the terminal with unparalleled speed and simplicity.

By mastering the art of aliases, you can elevate your command-line prowess to new heights and easily conquer even the most daunting tasks. So go forth, fellow command-line warriors, and unleash the power of Bash aliases upon the digital realm!

Can you tell that this was written by AI? The prompt I used for this was:

Write an article about Bash Aliases in the style of linux-tips.us.

It didn’t do very well at nailing my style and it used a lot of headers. It also rambled on quite a bit, but I do that too. I’m not sure how much time this saved. I still had to do quite a bit of formatting. A simple cut-and-paste would not match the mostly consistent formatting I have used as of late. That meant quite a bit of formatting.

I also ran the article through Grammarly. It’s too bad that they won’t accept me into the affiliate program. I quite like what they do for my writing. They make me look almost literate!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips