Different commands are used to manage the processes in Linux for example, the kill command is most commonly used to terminate the processes. Similarly, the ps command reports the snapshot of the running processes on the screen.
In this blog, the ps command is explained with the help of some examples, and the sections covered in the blog are:
Let’s start this informative tutorial:
What is the ps Command in Linux?
The ps command displays the information of the specified process using its PID, and the general syntax of using the PS command is below:
Syntax:
$ ps [options]
The ps command can be run independently and with different options. The options which can be used with the ps command are
Options | Explanation |
---|---|
-a | It will display all the processes |
-m | It will display the PID, Time of initialization, terminal screen, and the command with which it is being executed |
-t | It will display the processes of the current terminal |
-o | It will display the output of the processes |
-l | It will list down the processes |
-s | It will display the simple processes |
For more detailed options, you can get them via the following command:
$ ps --help list
These options are explained in the next section.
How to Use the ps Command in Linux?
Different examples demonstrate the usage of the ps command in Linux. Before going into the options, let’s see how the “ps” command works without any options
$ ps
The output of the “p” command is described as:
- The “PID” and “TTY” shows the process ids and the currently logged in the terminal of the user.
- The “Time” shows how long this process is running.
- “CMD” represents the command (like the ps command is used to show the processes) that launched the process.
Example 1: List All the Processes
To display all running processes on Linux using the ps command, use the command:
$ ps -l
Example 2: Display the Processes Linked With the Specific User
To display all the processes which are associated with some other user using the ps command, use the “-u” option with the username:
$ ps -u itslinux
Example 3: Display All the Processes of the Terminal
All the processes which are associated with the terminal can be displayed using the command:
$ ps -t
Example 4: Display the Processes by the Duration of Time
The process can be displayed with the elapsed time using the ps command in Linux with the command:
$ ps -e -o pid,comm,etime
Example 5: Use of the ps aux Command
One of the most used options which are run with the ps command is aux options. The application of these options is tabulated in the table below:
a | The users running the processes in Linux are displayed with this option |
u | The important information regarding the processes is displayed using this option |
x | The processes which are not linked with any terminal screen are displayed with this option |
To use these options, with the ps command utility, run the command:
$ ps aux
The more information of the usage of the ps aux command can be found by visiting the link.
That’s all about this tutorial.
Conclusion
In Linux, the ps command displays all the running processes in the terminal, and in doing so, detailed information about the processes will be displayed. This post has detailed the working and usage of the “ps” command in Linux; also, for a clearer understanding, the ps command’s examples are provided in detail.