15 basic 'ps' command to monitor Linux process with Examples

ps command in linux with options

In Linux/, Unix based system comes with an inbuilt utility 'ps' (processes status) to check the information on the running process. The process is nothing, but a program in Linux/Unix to execute a specific task. The ps command in linux is used to monitor all the currently running activities along with USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND. It helps, mostly to the System Administrators to find the PID (processes identifier) of all the running processes to monitor and troubleshoot.

This guide will help you, how to use various options with ps command. All the below examples are tested on RHEL/CENTOS 7.6

The Global Syntax of the ps command:

ps [options]

1. How to list the processes from the current shell?

# ps

ps command in linuxNote: Using the 'ps' command without any option will list only the running processes from the current shell. The result of the above command contains 4 columns, which are unsorted information.

 use of ps command in linux

2. How to list all the processes on the system (standard) format?

# ps -A                       OR                       # ps -e

how to use ps -ef command in linuxNote: Using '-A or -e' option with 'ps' command will list all the processes except the session leaders. To know more about the session leader(Click Wiki details). In the above example, it uses to list all the processes in a standard format.

3. How to list the processes not associated with Terminal?

# ps -a

How to use ps -a in linux commandNote: Using 'ps -a' option we can view all the processes except both session leaders and processes that are not associated with a Terminal.

4. How to list all the running processes on the system?

# ps -x

How to use ps -x in linux commandNote: Using the'-x' option with ps command will list all the processes on your system. You can also see the processes which are not associated with the current TTY. The x option is always combined with other flags like a, u.

5. How to list all the process on the system using BSD format?

# ps aux

How to use ps aux in linux commandNote : The ps command can accept options with two different format i.e., BSD and Unix. In BSD which we should not start the options with a dash and in UNIX which we should start the options with a dash. Details of the arguments and outcome result as follows:

how to use ps aux

6. How to perform full format listing?

# ps -ef                OR                  # ps -eF

ps -ef command in linuxNote: Using '-ef' option with ps command will display the full format list and with uppercase '-F' option will display Extra full format. Details of the arguments and outcome result as follows:

ps -eF command in Linux

7. How to list the information about threads processes?

# ps -eLF

how to use ps -eLF in linuxNote: Using the '-L' option with 'ps' command display the information about threads. Threads are also named as Light Weight Processes (LWP). Basically, it gives you an idea about how many concurrent threads are coming into the system, based on that you can analyze which of the processes are generating more threads. In the about output, you can see in column 4 and 6 (LWP and NLWP). LWP provides the Thread ID and NLWP provides the number of Threads. In the above example, you can see the PID 15111 (kdesvn) has 4 threads. It will be listed single as well as multi-thread processes.

8. How to list all the running processes by username?

# ps -U linuxteck

How to use ps -U in linuxNote: Using the '-U' option with 'ps' command will list all the processes running by the username. In the above example, it will list all the processes running by the liuxteck user. If you need a full-format listing, use '# ps -fU'.

9. How to list all the running processes by a particular group?

# ps -G gdm

how to use ps -G in linux commandNote: Using the '-G' option with 'ps' command will list all the processes running by a particular group. In the above example, it will list all the processes running by the gdm group. If you need a full-format listing, use '# ps -fG'.

10. How to get the process name using the corresponding PID?

# ps -p 6967 -o comm=

 

Output:

 

kdesvn

Note: Using the above command we can fetch the process name using with its corresponding PID. Here the option '-p' indicates the PID and '-o' option indicates the output format and the 'comm=' indicates the name of the Command. In the above example, it printed the process name (kdesvn) of the PID no "6967".

11. How to search for a Processes ID?

# ps -C kdesvn

 

Output:

PID        TTY      TIME          CMD
6967       ?        00:00:13     kdesvn

Note: Using the '-C' option with 'ps' command will get the processes whose executable name is given in the command-list. It can easily find the PID of running processes. In the above example, I have given the "kdesvn" name in the command list to execute and fetch the PID of the same.

12. How to find the uptime of a process?

# ps -eo comm,lstart,etime,user | grep svnserve

 

Output:

 

svnserve  Wed Feb 27  15:42:36  2019  228-20:54:53  root

Note: Using the above command you can find the start date of the executable command and it's overall uptime time. In the above example, you can see, the "svnserve" service was started on 27th Feb 2019 at 15:42:36 and the uptime of this service has been running almost 228 days, 20 hours,54 minutes and 53 seconds. The details of the above arguments as follows:

comm      -->    Indicates the command name
lstart       -->    Date/Time of the command executed
etime       -->   The elapsed time of a process
user          -->    Name of the User

13. How to list the top 10 CPU consuming processes?

# ps -e --sort=-pcpu -o pid,pcpu,comm | head -n 11

ps -e --sortNote: The above command will display the list of top 10 CPU consuming processes.

14. How to list the top 10 memory consuming processes?

# ps -e --sort=-pmem -o pid,pmem,comm | head -n 11

ps command in linux pidNote: The above command will display the list of top 10 Memory consuming processes.

15. How to kill the high CPU/Mem or unused programs/applications consuming processes in Linux?

# ps aux | grep firefox       OR               # ps -ef | grep firefox

 

Output:

 

linuxteck     2443     6.7       5.7       8895548       453380     ?    Sl     09:16     33:38         /usr/lib64/firefox/firefox
linuxteck     2604      8.7      7.1       3424284       562304      ?    Sl    09:17     43:23        /usr/lib64/firefox/plugin-container -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 2443 tab
root             17704     0.0     0.0          112664          968       pts/1   S+   17:35        0:00         grep --color=auto firefox

Note: The above command will list the PID of a particular application to kill. You can kill the processes eiher by process ID or process name. In the above example I have selected two PID's "2443 and 2604". Use the following command to kill the PID's.

Syntax : <kill SIGNAL PID>

# kill -9 2443 2604

OR following the command, if you wish to terminate the processes by process name

# killall -9 firefox

NB: '-9' is meant to Kill signal

Thank you for taking the time to read! I hope this article will help you to learn 'ps' commands with examples. Drop me your feedback/comments. If you like this article, kindly share it 🙂, so that it may help others as well.

Thank you!

If you like the article ? Please share it and help us grow 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *