Get to know Linux: ps command
Over the years there have been certain commands that have really helped me out of a bind. One of those commands is the ps command. The ps stands for process status and it tells you, as you would expect, the status of a process. This is a fast way to know if an application or command is running on a Linux system. Oh sure you could fire up a swell GUI for the same purpose, but that GUI does you no good if you are working on a headless server installation or working on a remote machine. In those instances the ps command is your best bet for helping to manage processes.
You will be glad to know that the ps command will most certainly be already installed on your Linux machine, so there is no need to worry about installation.
The basic command structure for ps is:
Of course every good Linux command offers a lot of options, and ps is no exception. For this command we will just outline the best groupings of options together instead of just listing all of (or the best) options. This way you can skip right down to the command you need to use.
Show list of processes owned by a specific user
Say I want to list all processes owned by user jlwallen. To do this I could enter one of two commands:
This will list out all processes that are owned by the user issuing the command. The results for this command will look like:
USERÂ Â Â Â Â Â PID %CPU %MEMÂ Â Â VSZÂ Â RSS TTYÂ Â Â Â Â STAT STARTÂ Â TIME COMMAND
jlwallenÂ Â 560Â 0.0Â 0.3Â 18312Â 7376 ?Â Â Â Â Â Â Â SNsÂ 19:40Â Â 0:00 /etc/alternativ
jlwallenÂ Â 561Â 0.0Â 0.1Â Â 7316Â 3932 pts/0Â Â Â SNsÂ 19:40Â Â 0:00 bash
jlwallenÂ 1137Â 0.0Â 0.0Â Â 1644Â Â 416 ?Â Â Â Â Â Â Â SÂ Â Â 19:47Â Â 0:00 sleep 8
jlwallenÂ 1141Â 0.0Â 0.0Â Â 1644Â Â 420 ?Â Â Â Â Â Â Â SÂ Â Â 19:47Â Â 0:00 sleep 8
jlwallenÂ 1142Â 0.0Â 0.0Â Â 4384Â 1012 pts/0Â Â Â RN+Â 19:48Â Â 0:00 ps ux
You can also get a similar listing with the command:
ps U jlwallen
The results of this command will be:
PID TTYÂ Â Â Â Â STATÂ Â TIME COMMAND
560 ?Â Â Â Â Â Â Â SNsÂ Â Â 0:00 /etc/alternatives/x-terminal-emulator
561 pts/0Â Â Â SNsÂ Â Â 0:00 bash
1223 ?Â Â Â Â Â Â Â SÂ Â Â Â Â 0:00 sleep 8
1227 ?Â Â Â Â Â Â Â SÂ Â Â Â Â 0:00 sleep 8
1228 pts/0Â Â Â RN+Â Â Â 0:00 ps U jlwallen
Show all processes
To see every process on your system you would enter the command:
The results of this command would look similar to that of ps ux only it would show the process of every user as well as the system.
List the details of a single process
What about when you want to see the details of only a single process? Imagine issuing the command ps ux and having to search through all of the listings to find the information about the one process you are trying to gain information about. Say, for example, you need to find the PID (Process ID) of the currently running daemon for Dansguardian. You can use the ps command and pipe the results to the grep command to search the listing for a specific string and print out only the matching strings. To do this issue the command:
ps aux | grep dansguardian
which will print out something like:
113Â Â Â Â Â Â 2596Â 0.0Â 0.5Â 17852 11460 ?Â Â Â Â Â Â Â SsÂ Â 06:49Â Â 0:00 /usr/sbin/dansguardian
Now you can see the PID of Dansguardian is 2596. You can kill this with the kill 2956 command.
There are many more uses for the ps command as well as many more ways to use the ps command. The above three examples are the most often used, but don't think you are limited to only those uses. Issue the command man ps and you will see a full listing of all the ps options available to you.Advertisement