Posted: . At: 11:25 PM. This was 7 years ago. Post ID: 4683
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Useful Linux tips. Using the ps command to list processes with the command line.


The ps command in Linux has many useful command-line parameters that may be used to give more information. The –forest parameter will give a tree view of the ps output that will show the children of each parent process. That is like the pstree command and will enable you to better visualize the relationships of all of the processes that are running on your UNIX or Linux desktop or server. Keeping track of all running processes on your system is important. Another useful command for Debian based Linux distributions is the apt command-line package management tool. Using the sudo apt-get update && sudo apt-get upgrade command will enable command-line installation of updates easily. You must install updates for your Linux system promptly; keeping your software up to date will patch security holes in your software and install new versions of installed packages. Unlike Windows; Linux is able to install updates whilst the computer is up and running; you only need to re-boot if your GNU Libc or Kernel is updated and then it is prudent to re-boot and load the new kernel version. But still better than Windows prompting you to restart every so often to update the software. That is aggravating.

Windows should be able to update software whilst it is running; it is the dominant desktop operating system in the world; why is it so incapable of something that Linux could do for ages? Microsoft are hyping Windows 8 as the next best thing but they need to improve the core workings of the Windows operating system and security. You should not need a virus scanner and Internet security software in 2012. But that is what happens when an operating system is the market leader; it is a huge target for malware authors and virus writers. Linux being an open-source operating system is naturally more secure than a closed source operating system solution. Below is the output of the pstree command that shows the running processes in a useful tree view. This is obviously useful when attempting to understand the relationships between running processes on your machine.

ubuntu ~ $ pstree
init─┬─acpid
     ├─apache2───5*[apache2]
     ├─atd
     ├─cron
     ├─dbus-daemon
     ├─dhclient
     ├─7*[getty]
     ├─mysqld───17*[{mysqld}]
     ├─netserver
     ├─openvpn
     ├─pcscd───{pcscd}
     ├─rsyslogd───3*[{rsyslogd}]
     ├─sshd───sshd───sshd─┬─sh───sftp-server
     │                    └─sh───bash───pstree
     ├─systemd-logind
     ├─systemd-udevd
     ├─upstart-file-br
     ├─upstart-socket-
     └─upstart-udev-br

Use the -U parameter if you want to see Unicode characters used to draw the connections between the processes.

ubuntu ~ $ pstree -U
init─┬─acpid
     ├─apache2───5*[apache2]
     ├─atd
     ├─cron
     ├─dbus-daemon
     ├─dhclient
     ├─7*[getty]
     ├─mysqld───17*[{mysqld}]
     ├─netserver
     ├─openvpn
     ├─pcscd───{pcscd}
     ├─rsyslogd───3*[{rsyslogd}]
     ├─sshd───sshd───sshd─┬─sh───sftp-server
     │                    └─sh───bash───pstree
     ├─systemd-logind
     ├─systemd-udevd
     ├─upstart-file-br
     ├─upstart-socket-
     └─upstart-udev-br

If you are reading this post on a Windows system; there is a nice manual page concerning the ps command here: http://unixhelp.ed.ac.uk/CGI/man-cgi?ps. The below output is from the ps a --forest command. This is a mode that uses ascii art to draw the child-parent relationships between processes.

ubuntu ~ $ ps a --forest
  PID TTY      STAT   TIME COMMAND
27507 pts/0    Ss     0:00 -sh
27516 pts/0    S      0:00  \_ /bin/bash
27531 pts/0    R+     0:00      \_ ps a --forest
 1772 ttyS0    Ss+    0:00 /sbin/getty -8 38400 ttyS0
 1771 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1
 1245 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
 1242 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
 1241 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
 1237 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
 1234 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.