Linux command: PS (Process Status)
An overview of the Linux “ps” command
ps
— Process Status
ps
command displays information related to the processes running in a Linux system.
$ ps--------------------------------------------------------------------
PID TTY TIME CMD
54316 pts/0 00:00:00 bash
54341 pts/0 00:00:00 ps
PID
— Unique process ID TTY
— Type of terminal that the user is currently logged in. TIME
— CPU time this process has consumed since it first started running. CMD
— The command used to start the corresponding process.
ps with Arguments
If we pass arguments with a (-) dash then we will get the output in standard syntax. In contrast, if we pass arguments without any (-) dash then we will get output in BSD (Berkeley Software Distribution) syntax.
To view all running processes :
ps -e
orps -A
To view full formated list of all running processes:ps -efL
$ ps -efL | more # more for viewing from the beginning-------------------------------------------------------------------UID PID PPID LWP C NLWP STIME TTY TIME CMD
root 1 0 1 1 1 03:44 ? 00:00:20 /sbin/init
root 2 0 2 0 1 03:44 ? 00:00:00 [kthreadd]
...
...
We can use grep
along with ps
command to search for a specific process;
Let’s say we want to see our “httpd” server is running or not. We can do that in the following way:
$ ps -efL | grep httpd--------------------------------------------------------------------root 48778 39025 48778 0 1 04:22 pts/0 00:00:00 grep --color=auto httpd
To view all running processes by username and group:
$ ps -u root # by username
$ ps -G admin # by group
To view the process tree. Within a process there can be multiple processes running, we can use ps -ejH
to view the process tree:
$ ps -ejH | grep sshd --------------------------------------------------------------------
614 614 614 ? 00:00:00 sshd
22310 22310 22310 ? 00:00:00 sshd
30267 30267 30267 ? 00:00:00 sshd
33871 33871 33871 ? 00:00:00 sshd
In the above demonstration, we can see the process tree of the “sshd” process.
The most widely used ps
command is ps aux
: which will output all the running processes using the BSD syntax. The ps aux
displays the most amount of information a user usually needs to understand the current state of their systems running processes.
$ ps aux | more--------------------------------------------------------------------USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.6 0.5 169396 11312 ? Ss 03:44 0:24 /sbin/init
root 2 0.0 0.0 0 0 ? S 03:44 0:00 [kthreadd]
...
ps aux
provides additional information, such as :
%CPU
CPU time used by this process (in percentage)
%MEM
Physical memory used by this process (in percentage)
VSZ
displays the amount of virtual memory being consumed by the process.
RSS
is the actual physical wired-in memory that is being used.
START
shows the date or time when the process was started.
TIME
shows the total CPU time used by this process.
STAT
displays the state of a process. The most common state codes are described below:
R: Running or runnable.
S: Interruptible sleep, waiting for an event to complete, such as input from
the terminal.
D: Uninterruptible sleep, processes that cannot be killed or interrupted with a signal, usually to make them go away you have to reboot or fix the issue.
Z: Zombies are terminated processes that are waiting to have their statuses collected.
T: Stopped, a process that has been suspended/stopped.
If you found this article helpful, please don’t forget to hit the Follow and Clap buttons to help me write more articles like this.
Thank You 🖤