Hi, this is Sandra Henry-Stocker, author of the “Unix as a Second Language” blog on NetworkWorld.
In this Linux tip, we’re going to look at the pstree command. It allows you to get a listing of running processes that clearly indicates the relationship between them – in particular, which processes have spawned other processes.
Here’s a very simple example. If we run the command pstree $$, you’re going to see a very simple display that looks like this:
This output is showing us that our login shell (represented by $$) has spawned a single process – the pstree command. In other words, bash just ran the pstree command for us. If we run a more complex example like pstree followed by a username, we’re going to see all the processes being run by that particular user. In this example, we see that jdoe, who is logged in remotely using ssh, is reading one of the man pages and that the man command is using less to display the man page one screen at a time.
If we were to look at what the root user is running, we’d see a lot more going on – including all the processes being run by systemd:
The pstree command allows you to view processes in a hierarchical fashion, making the relationships between running tasks very clear. That’s your Linux tip for pstree. If you liked this video, please hit the like and share buttons. For more Linux tips, be sure to follow us on Facebook, YouTube and NetworkWorld.com.