The ps
command is a Linux utility that reports the current system process status. It is used to display information about the processes running on the system, including their process ID (PID), CPU usage, memory usage, and other details. This command is commonly used by system administrators to monitor the system and troubleshoot issues related to processes.
Overview
The basic syntax of the ps
command is as follows:
ps [options]
When executed without any options, the ps
command displays information about the processes that are running in the current terminal session. The output includes the PID, TTY, TIME, CMD, and other details.
Here are some common use cases for the ps
command:
- To display information about all processes running on the system, use the following command:
ps -ef
- To display information about all processes running in the current terminal session, use the following command:
ps
- To display a hierarchical tree of processes, use the following command:
ps axjf
- To display information about a specific process, use the following command:
ps -p <pid>
- To display detailed information about a specific process, use the following command:
ps -p <pid> -o pid,ppid,user,%cpu,%mem,cmd
Here are some examples of the output of the ps
command:
PID TTY TIME CMD
1234 pts/0 00:00:00 bash
5678 pts/0 00:00:00 ps
Options
The ps
command supports a wide range of options that allow you to customize the output and filter the results. Here is a table of the most commonly used options:
Option | Description |
---|---|
-a |
Displays information about all processes, including those of other users. |
-e |
Displays information about all processes, including those that are not associated with a terminal. |
-f |
Displays a full listing of all processes, including the UID, PPID, C, STIME, TTY, TIME, and CMD. |
-h |
Hides the header from the output. |
-p |
Displays information about a specific process, identified by its PID. |
-u |
Displays information about all processes that are being run by a specific user. |
-x |
Displays information about all processes, including those that are not associated with a terminal. |
Troubleshooting Tips
Here are some common issues that you may encounter when using the ps
command, along with solutions to those issues:
- The output is too long to read. In this case, you can use the
less
command to scroll through the output one page at a time. For example:ps -ef | less
- The output is missing important information. In this case, you can use the
-o
option to specify which columns to display. For example:ps -ef -o pid,ppid,user,%cpu,%mem,cmd
- The output is not sorted in a useful way. In this case, you can use the
sort
command to sort the output based on a specific column. For example:ps -ef | sort -k 3
Notes
- The
ps
command is a powerful tool for monitoring the system and troubleshooting issues related to processes. However, it is important to use it with caution, as it can potentially display sensitive information about the system and its users. - The output of the
ps
command may vary depending on the version of Linux you are using. It is recommended to refer to the manual page for your specific version of Linux for more information.