Linux is a powerful multi-tasking and multi-user operating system. It allows multiple processes to operate simultaneously without any interfering with each other.
The ps (processes status) is a inbuilt command line utility that is used to display information about the processes running on the system. The ps command can be used to show all of the processes, or only those belonging to a specific user, or those belonging to a specific group.
Ps command is one of the most basic command in Linux Unix system that displays information about the process status and detailed information. It is a tool used to view brief information on tasks, processes and other parameters in Unix flavored systems vastly used throughout the web.
This is general purpose system administration utility capable of displaying task’s technical, dynamic and command line reporting related statistics. It can also show administrator’s VIA systems usage which make it one of the most commonly utilised utilities by administrators around the world.
In this article, we will help you to use the PS command with various options.
In the Linux, the global syntax of the ps command is show as below:
ps [options]
The ps
command provides several different types of options for manipulating the output:
- UNIX style options, preceded by a single dash.
- BSD style options, used without a dash.
- GNU long options, preceded by two dashes.
1. Display the processes from the current shell
# ps
Output
PID TTY TIME CMD
5502 pts/0 00:00:00 bash
5512 pts/0 00:00:00 ps
Note: when you are using the ‘p
s’ command without any options will display four columns of information for minimum two running processes from the current shell.
Where,
PID – It is the unique process ID Number.
TTY – It is the name of the controlling terminal for the process.
TIME – CPU time of the process in minutes and seconds.
CMD – Name of the command that was used to launched the process.
The ps command accepts many options that are used to display a specific group of processes and different information about the process.
2. Display all the active processes in the system (standard) format
# ps -A
OR
# ps -e
Note: The ‘ps’ command with the ‘-A or -e’ option will display all the processes in a standard format except the session leaders.
To Know more about the session leader Click Here to Check Wiki details.
3. Display the processes that are not associated with Terminal
# ps -a
Note: ‘ps’ command with the ‘-a’ option will display all the processes except both session leaders and processes that are not associated with a Terminal.
4. Display all the running processes in the system
# ps -x
Note: The ‘ps’ command with the ‘-x’ option will display all the processes on your system. It will also display the processes that are not associated with the current TTY.
5. Display all the processes in the system using BSD format
# ps aux
Note : The ps command can accept multiple options at once with two different formats i.e., BSD and Unix. In the BSD format, the options should not start with a dash and in UNIX format, it should start with a dash. Details of the arguments and outcome result as follows:
In the above command, we use combination of three options at once:
a
option is used to display the processes of all users.u
(user-oriented format) option provides detailed information of the processes.- x option used to list the processes without a controlling terminal.
The command above will display output as show below:
Output
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.6 88716 7614 ? Ss Feb25 0:01 /sbin/init
root 2 0.0 0.0 0 0 ? S Feb25 0:00 [kthreadd]
...
You can use the -f
option to display a tree view of parent to child processes:
$ ps auxf
6. How to perform the full format listing?
# ps -ef
OR
# ps -eF
Note: The ps command with ‘-ef’ option will display the full format list and with uppercase ‘-F’ option will display Extra full format.
In the above command, we use combination of two options at once:
-e option
used to display all processes.-f
(full-format listing) option provides detailed information of the processes.
The command above will display output as show below:
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Feb25 ? 00:00:05 /sbin/init
root 2 0 0 Feb25 ? 00:00:00 [kthreadd]
Run the command below to display only the processes running as a specific user(studiesonline):
ps -f -U studiesonline -u studiesonline
7. Display the information about the threading process?
# ps -eLF
Note: The ‘-L’ option with the ‘ps’ command will list the information about the threads.
8. Display all the running processes by a particular username
# ps -U linututorialhub
Note: The ‘ps’ command with ‘-U’ option will display all the processes running by the username.
If you need a full-format listing, Run the command below:
# ps -fU
9. Display all the running processes by a particular group
# ps -G gdm
Note: ‘ps’ command with the ‘-G’ option will display all the processes running by a particular group.
If you need a full-format listing, Run the command below:
# ps -fG
10. Get the process name using the PID
# ps -p 6061 -o comm=
Output:
kdesvn
Note: The above command will display the process name using with its corresponding PID.
Here :
- ‘-p’ option –> it is indicates the PID
- ‘-o’ option –> indicates the output format
- ‘comm=’ –> It is indicates the name of the Command.
11. Search for a Processes ID
# ps -C kdesvn
Output:
PID TTY TIME CMD
6061 ? 00:00:13 kdesvn
Note: The ‘ps’ command with ‘-C’ option will display the processes whose executable name is given in the command-list. With the help of it you can easily find the PID for running processes.
12. Find the uptime of the process
# ps -eo comm,lstart,etime,user | grep svnserve
Output:
svnserve Tue Jan 25 13:24:26 2022 258-20:24:33 root
Note: With the help of above command, you can easily find the start date of the executable command and its overall uptime.
Here:
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. Display the most 10 CPU consumption processes
# ps -e --sort=-pcpu -o pid,pcpu,comm | head -n 11
Note: The command above will show a list of the top 10 CPU consumption processes in your system.
14. Display the most 10 memory consuming processes
# ps -e --sort=-pmem -o pid,pmem,comm | head -n 11
Note: The command above will show a list of the top 10 memory consuming processes in your system.
Thank you so much for reading this article! I hope this article will help you to understand use of ‘ps’ commands to Monitor Process in Linux with examples .If you have any questions, feel free to leave a comment below and we will get back to you as soon as possible!
If you like this article, kindly please share it and it may help others as well.
If our tutorials helped you, please consider buying us a coffee. We appreciate your support!
Thank you for your support.