Linux Commands

Understanding ps command

Understanding ps command
Understanding ps command

Understanding ps command

Understanding ps command : Process is one of the most important concepts of the Linux OS. Once we run a shell command, a program is run and a process is created for it. Sometimes we want to check the background process in our Linux system and identify the unresponsive programs. We can use ps (process status) command utility from Linux for viewing information related to the process on a system. ps command read the process information from /proc file system.

ps command provides several options according to the user needs, the simplest form of ps is without any options:

ps

The output displays the shell (bash) and the process running in this shell (now ps):

PID TTY TIME CMD
1358 pts/0 00:00:00 bash
1373 pts/0 00:00:00 ps

Here:

PID – Process id. By knowing process id user can kill the problematic process.
TTY – Name of the controlling terminal.
TIME – CPU time of the process (in minutes and seconds).
CMD – Name of the command used to start that process.
Getting the man page:

man ps will display all available options related to ps command.

man ps
Some of the important options of ps are given below:

To display all the processes within the system.

ps -e

ps -e

To output displays with full format listing:

ps -ef

Sample Output:

UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun25 ? 00:01:09 /usr/lib/systemd/systemd --system --deserialize 22
root 76 1 0 Jun25 ? 00:00:29 /usr/lib/systemd/systemd-journald

Here some extra columns added:

UID – User id of the process owner.
PPID – Parent process id.
C – CPU utilization percentage.
STIME – Starting time of the process.

-F option will print extra full-format listing.

Search/Filter options:

-u option will search by user name:

ps -u root

Sample Output:

PID TTY TIME CMD
1 ? 00:01:09 systemd
76 ? 00:00:29 systemd-journal

-p option will filter based on the list of process ids:

ps -p 76,753

Sample Output:

PID TTY TIME CMD
76 ? 00:00:29 systemd-journal
753 ? 00:00:07 sshd

-C for searching a particular process by name:

ps -C httpd

Sample Output:

PID TTY TIME CMD
1876 ? 00:00:00 httpd
1881 ? 00:00:00 httpd

-G by group name, -g by group id

Some other important options are:

-a to view all processes except both session leaders and processes not associated with a terminal:

ps -a

Sample Output:

PID TTY TIME CMD
1357 pts/0 00:00:00 su
1358 pts/0 00:00:00 bash

To view all the processes except session leaders:

ps -d

-o option to show specific columns as per user requirement:

ps -efo pid,comm

Sample Output:

PID COMMAND
1803 bash
1922 \_ ps
ps command can also be used in BSD format:
ps aux

Is the syntax in BSD format:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.5 43428 5360 ? Ss Jun25 1:09 /usr/lib/systemd/systemd 
root 76 0.0 5.6 116768 59424 ? Ss Jun25 0:29 /usr/lib/systemd/system-
USER - The user who runs the process.
%CPU – The CPU utilization of the process.
%MEM - The percentage of the process’s set size to the physical memory on the machine.
VSZ - Virtual memory size of the process in Kib.
RSS - The size of the physical memory that the process is using (Real Memory)
STAT - The process state code, such as Z (zombie), S (sleeping), and R (running).
START - The time when the command started.

Conclusion:

In this quick reference, we covered some of the basic options of ps used for troubleshooting. All other options are available in the man page.

That’s it!

Also Read:

If you like the post Understanding top Command and wish to receive more articles from us, please like our FB page: GrepItOut

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments. For more details on our services, please drop us an E-mail at info@grepitout.com

Topics