The ps
command is a command-line utility in Linux used to display information about running processes on a system. It provides a snapshot of the current processes running in the system, including their process IDs (PIDs), CPU and memory usage, parent-child relationships, and various other details.
The basic syntax of the ps
command is:
ps [options]
Here are some commonly used options with the ps
command:
ps
: This option displays processes owned by the current user in a terminal window.ps aux
: This option displays all running processes on the system.ps -e
: This option displays all processes, regardless of the user.ps -f
: This option displays a full-format listing of processes, including additional details such as the UID, PPID, CPU usage, and start time.ps -l
: This option provides a long listing format, including additional information such as the process’s priority and scheduling information.ps -eF
: This option displays full-format listing of processes with extra fields.ps -ef
: This option displays all processes in a full-format listing.
Now, let’s look at a practical example to illustrate the usage of the ps
command:
ps aux | grep firefox
In this example, the ps aux
command is used to list all running processes on the system. The output is then piped (|
) to the grep
command, which filters the output to only display the processes related to Firefox. This can be helpful when you want to find specific processes or check if a particular application is running.
Note that the examples provided here are just a small glimpse into the capabilities of the ps
command. There are many more options available that can be used to customize the output and display different information about the processes. For more details and options, you can refer to the manual page of ps
by typing man ps
in your terminal.
How to use Linux ps command
Certainly! Let’s dive into a detailed example of using the ps
command in Linux.
- Displaying Running Processes:
To display all running processes on the system, you can use the following command:
ps aux
This will provide a detailed listing of all processes, including their user, PID, CPU usage, memory usage, start time, and command.
- Filtering Processes with
grep
:
If you want to filter the processes based on a specific criteria, you can combine theps
command withgrep
. For example, to find all processes related to the “firefox” application, you can use:
ps aux | grep firefox
This command will show the processes matching the keyword “firefox” in their command or process name.
- Displaying Process Hierarchy:
To visualize the parent-child relationships between processes, you can use the--forest
option. For example:
ps aux --forest
This command will display a hierarchical view of the processes, showing parent processes and their respective child processes.
- Customizing Output Format:
Theps
command allows you to customize the output format using various options. For example:
- To display a more detailed listing with extra fields, you can use
-f
:ps -ef
- To display a long listing format, including additional information such as process priority and scheduling, use
-l
:ps -l
- To display the full-format listing with additional fields, use
-F
:ps -eF
- Sorting Processes:
If you want to sort the processes based on a specific column, you can use the--sort
option followed by the column name. For example, to sort processes by CPU usage in descending order:
ps aux --sort=-%cpu
- Monitoring Processes:
Theps
command can also be used for process monitoring. By specifying a time interval and thewatch
command, you can continuously monitor the running processes. For example, to monitor the processes every 2 seconds:
watch -n 2 'ps aux'
These examples demonstrate some common use cases of the ps
command in Linux. Remember that the ps
command offers numerous options and combinations to suit various requirements. For a comprehensive understanding of the available options and their usage, you can refer to the man ps
command to access the manual page for ps
.