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.

Subscribe to Newsletter!
Get notified when new articles are published!
We promise to never share your email!
icon

Author: KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.