The ps
command, short for Process Status, is a command line utility that is used to display or view information related to the processes running in a Linux system. As we all know, Linux is a multitasking and multiprocessing system. Therefore, multiple processes can run concurrently without affecting each other. The ps command lists current running processes alongside their PIDs and other attributes. In this guide, we are going to focus on ps command usage. It retrieves information about the processes from virtual files which are located in the /proc file system
The ps command without arguments lists the running processes in the current shell
ps
Output The output consists of four columns PID
- This is the unique process ID TTY
- This is the typeof terminal that the user is logged in to TIME
- This is the time in minutes and seconds that the process has been running CMD
- The command that launched the process
To have a glance at all the running processes, execute the command below ps -A
Output or ps -e
Output
To view processes associated with the terminal run ps -T
Output
To view all processes with the exception of processes associated with the terminal and session leaders execute ps -a
A session leader is a process that starts other processes Output
To view all current processes execute
ps -ax
Output -a
flag stands for all processes -x
will display all processes even those not associated with the current tty
If you wish to display processes in BSD format, execute
ps au
OR
ps aux
Output
To view a full format listing run
ps -ef
OR
ps -eF
Output
If you wish to list processes associated with a specific user, use the -u
flag as shown
ps -u user
For example
ps -u jamie
Output
If you wish to know the thread of a particular process, make use of the -L
flag followed by the PID For example
ps -L 4264
Output
Sometimes, you may want to reveal all processes run by the root user. To achieve this run
ps -U root -u root
Output
If you wish to list all processes associated by a certain group run
ps -fG group_name
Or
ps -fG groupID
For example
ps -fG root
Output
Chances are that usually don’t know the PID to a process. You can search the PID of a process by running
ps -C process_name
For example
ps -C bash
Output
You can display processes by their PID as shown
ps -fp PID
For example
ps -fp 1294
Output
Usually, most processes are forked from parent processes. Getting to know this parent-child relationship can come in handy. The command below searches for processes going by the name apache2
ps -f --forest -C bash
Output
For example, If you wish to display all forked processes belonging to apache, execute
ps -o pid,uname,comm -C bash
Output The first process, which is owned by root is the main apache2 process and the rest of the processes have been forked from this main process To display all the child apache2 processes using the pid of the main apache2 process execute
ps --ppid PID no.
For example
ps --ppid 1294
Output
The ps command can be used to view threads along with the processes. The command below displays all the threads owned by the process with PID pid_no
ps -p pid_no -L
For example
ps -p 1294 -L
Output
You can use the ps command to display only the columns you need. For example ,
ps -e -o pid,uname,pcpu,pmem,comm
The command above will only display the PID, Username, CPU, memory and command columns Output
To rename column labels execute the command below
ps -e -o pid=PID,uname=USERNAME,pcpu=CPU_USAGE,pmem=%MEM,comm=COMMAND
Output
Elapsed time refers to how long the process has been running for
ps -e -o pid,comm,etime
Output The -o option enables the column for elapsed time
the ps command can be used with grep command to search for a particular process For example
ps -ef | grep systemd
Output
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.