Since Linux is a multi-tasking system, in which many different programs or program threads may be running simultaneously, Linux keeps track of all individual tasks and processes – much like the Task Manager within Windows. Although these processes are usually well-behaved and well-managed by Linux itself – it’s always helpful to be able to know how to view all the running processes, or stop a program if it hits a bug or a flaw.
To find out what processes are running we use the ps command. ps stands for “process status”, which generates a concise listing of your own processes.
[email protected] [~]# ps PID TTY TIME CMD 252270 ? 00:00:00 bash 252341 ? 00:00:00 ps
The information in the first column, titled PID, is the Process ID number, which is unique and which Linux uses to identify that particular process. You must know the PID in order to be able to kill a process.
The TTY column shows you which terminal the process was started from.
The STAT column gives you the current status of the process. The two most common entries in the status column are S for sleeping and R for running. A sleeping process is one that isn’t currently active, however do take note that a process can switch from sleeping to running within a matter of seconds.
The TIME column shows the amount of system time used by the process. Clearly, neither of our processes are taking up any real system time in our example above.
Finally we come to the COMMAND column – which contains the name of the program that is running. This will usually be the command you typed at the command line, however sometimes the command you type starts one or more child processes, and in this case you would see these additional processes show up as well, without ever actually having to have typed them in yourself.
If you are logged in as root, you will see a list of all the processes on your system. An ordinary user will simply see the processes that are running under their account only.
One extremely useful option with the ps command is the u argument. Although technically the u argument stands for “user” – it actually displays much more information than just the username. For example:
[email protected] [~]# ps u USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND user 252270 0.0 0.0 10952 1424 ? S 09:34 0:00 -jailshell user 270853 0.0 0.0 10480 924 ? R+ 09:40 0:00 ps u
As you can see in addition to the username in the USER column, we now also have the CPU column – which shows you what percentage of your computer’s processing power is being used by the process, and MEM – which shows you what percentage of your computers memory is being used by the process.