A process is an executing instance of a program. Process is one of the important concept of the Linux OS. Linux provides
ps utiliy to view information about running processes. In this article, we will show you how to use the ps command to list the currently running processes and their PIDs along with other information.
How to Use
The basic syntax for the
ps command is as follows:
ps provides numerous options for manipulating the output according to our need.
- UNIX style options, preceded by a single dash.
- BSD style options, used without a dash.
- GNU long options, preceded by two dashes.
You can use different options types simultaneously, but in some specific situation conflicts can appear.
ps command without any options it will show four columns by default. It will show minimum two processes running in the current shell.
PID TTY TIME CMD
4402 pts/0 00:00:00 bash
4412 pts/0 00:00:00 ps
The above output shows information about shell (
bash) and and the processes that run in the shell (
You can see there are four columns
PID– Its ID of the process. Generally, user use
pscommand to know the PID, by knowing the PID you can kill a malfunctioning process.
TTY– The name of the controlling terminal for the process.
TIME– It will show the cumulative CPU time of the process, shown in minutes and seconds.
CMD– Name of the command that was used to start the process.
The ps command accepts many more options that can be used to display a specific group of processes and different information about the process. ps is most frequently used with the following combination of options:
Here, combination of three options:
aoption is used to display the processes of all users. It will also ignores the processes which are associated with a terminal.
ustands for a user-oriented format that provides detailed information about the processes.
- Option x tells
psto list the processes without a controlling terminal. Those are mainly processes that are started on boot time and running in the background.
The above command will show the output in eleven columns as given below:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 159668 8932 ? Ss Jun19 0:03 /sbin/init
root 2 0.0 0.0 0 0 ? S Jun19 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I Jun19 0:00 [kworker/0:0]
Below is an explanation of labels, we already shown
CMD labels before:
USER– Name of the user who runs the process.
%CPU– The cpu utilization of the process.
%MEM– The percentage of the process’s resident set size to the physical memory on the machine.
VSZ– Virtual memory size of the process in KiB.
RSS– Size of the physical memory that the process is using.
STAT– It’s showing process state code, such as
START– Showing the time when the command started.
You can use the
-f option to show a tree view of parent to child processes:
psto display all processes.
-fstands full-format listing, which provides detailed information about the processes.
The command will show output in eight columns named
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun19 ? 00:00:03 /sbin/init
root 2 0 0 Jun19 ? 00:00:00 [kthreadd]
Following is the explanation of remaining labels:
UID– It is same as USER, the user who runs the process.
PPID– The ID of the parent process.
C– Same as
%CPU, the process CPU utilization.
STIME– Same as
START, the time when the command started.
To show the processes running of a specific user, you would type:
ps -f -U tecnstuff -u tecnstuff
tecnstuff is the user name.
You can use o option with
ps command to show columns which you want to display.
For example, to display only
COMMAND, you should run one of below command:
ps -efo pid,ppid,comm
ps auxo pid,ppid,comm
ps command is one of the most frequently used commands when fixing issues on Linux machines. There many options you can use with ps command.
To know more about
man ps in your terminal.
If you have any questions or suggestion, please leave a comment below.