In a Unix-like operating system, a process is a program in execution. Linux or Unix is a multitasking operating system that means more than one program can be running at the same time. Whenever a command is issued a new process starts. Kernel identifies a process with a unique id called process id or PID. The processes communicate with each other and with the kernel to carry out a task.
In Linux/Unix ps command is used to display a snapshot of the current processes. Ahead in this article, we will discuss the ps command and its usages in Linux/Unix.
The ps command
The ps command is used to display information about a selection of active processes. It stands for process status. The information displayed using the ps command is a little bit different from that displayed using top command.
Syntax of ps command is given below –
ps [options]
A list of options is given in manual page of ps command you can see it by running –
man ps
List all processes for the current shell
If you run ps command without any options then it will display the list of all processes in the current shell.
ps
Where,
PID – Process ID
TTY -This is the terminal type that the user logged into
TIME -Total accumulated CPU utilization time
CMD – Name of the command which launches this process
Print the list of all the active processes in a system
If you are using a distribution of Linux then use the following command to display the list of active processes in a system –
ps -A | less
or
ps -e | less
In FreeBSD run the following command –
ps au
or
ps aux
Display a process by the process id or PID
You can display the process by using PID, Use the command as given below –
ps -fp PID
For example –
ps -fp 1
Display the threads of a process
To print all the threads of a process, use the following command in the terminal –
ps -fL -C chrome
The given command will print the threads or subprocesses of chrome.
View all the process owned by the parent process
You can use the parent process id or ppid to display the sub-processes of a process by using –
ps --ppid 1
This will display the processes owned by the parent process with ppid 1.
To know more about ps command and its usage see its manual page by executing –
man ps
Conclusion
If you want a repetitive update on the selection and displayed information then use top command instead of using ps. If you want to say something on this topic then write to us in the comments below.