The ‘ps’ command is used to list processes that are running on the Linux system. This listing of processes is only a snapshot of the running processes, meaning
that it is simply a point-in-time copy of processes, on the system. By default, when run without any options, it shows only your own processes. When using other flags, it can show all processes from any user.
The ‘top’ and ‘htop’ commands are also used to list running processes. Unlike the ‘ps’ command, these utilities will show a real-time view of running processes. Additionally, these commands include information about the number of running processes, and CPU and memory usage. Note that the ‘htop’ utility is not installed by default on most Linux systems, but the Research IT systems have this utility available.
There are quite a few flags that are useful for the ‘ps’ command. Some of the more useful ones are discussed here:
- -e, which displays all processes on the machine that are attached to a terminal. The default is to only display your running processes that have been
started from your terminal window; - -a, which shows processes that are not running from a terminal window; - -f, -F, and -l which all do a different type of long (meaning detailed) listing – showing more data than the typical ‘ps’ command; - -u, which filters processes to only show the processes owned by the specified user; and - -o, which allows you to select the specific columns to print output to the terminal window.
There are even more options available to the ps command, but we recommend that you memorize one set of flags to run for most purposes, and build on that.
Terminal -- open terminal, run ‘ps –eaf’
Like the ‘ps’ command, the ‘top’ and ‘htop’ commands display a list of processes – along with plenty of useful information. But this utility does so in real-time – continually updating itself every couple seconds – until the program is shut down.
In order to thoroughly explain this information to you, we have taken a running ‘top’ command and printed out the first 9 lines so that we can explain each.
The first line gives us:
- the command name; - the current time (in this case, 11:41 and 15
seconds); - the amount of time that the system has been up and operational (in this case, 2 days, 20 hours, and 50 minutes); - the number of logged in users; and - the average load on the system.
All of this information can be useful, but most people find the average system load to be the most useful information. A properly running system should not have more than one unit of load for each CPU thread available. That is, a single core, single thread processor should not have a load of greater than 1.0 to run efficiently. Most HPC machines have large numbers of threads available, so this optimal number may be effectively 40.0 or higher for some machines. Please
contact your systems administrator for more information on your machine architecture.
The second line displays information about the currently running processes, including the number of “sleeping” processes – which are processes that are not currently being run by the system.
The third, fourth, and fifth lines tell us - the total percentage of CPU time, and how it is
being used; - the total amount of physical RAM in the machine and how much is being used; and - the total amount of swap space on the machine and how much is being used.
Finally, the last three lines are the process list, along with its attendant information.
A full discussion of these lines is out of scope for this video. For more information, see the top manual page.
While the top command provides a lot of useful information about System Load, Users, and Memory, much of this information can be obtained in other places.
Two such commands that provide this information are the ‘who’ and ‘free’ commands.
Terminal -- use ‘WHO’
As you can see in the terminal, the ‘who’ command will display a list of logged-in users, and the IP address or machine name from which they are connected. A bit more useful, the ‘w’ command shows not only the currently logged in users, but also the
- computer uptime; - number of logged in users; and - system load.
Terminal -- use ‘FREE’
The ‘free’ command displays the current memory profile of the machine. Note that this display is in bytes of memory.
If you want to see the free/available memory in human readable format that is scaled and suffixed with common units such as M for Megabytes or G for gigabytes, you can use the ‘-h’ flag.