ps command in Linux
The “ps” command in Linux stands for “process status” and is one of the most fundamental tools for system monitoring and management. It offers a snapshot of the currently running processes on the Linux system. In addition, offering information that can be invaluable for both new and experienced users alike. It returns an informative report on the processes currently active. It is an essential command for system administrators and users alike, providing a snapshot of the system’s dynamic behavior.
The supported content of the comprehensive guide on the ps command in Linux is given below:
- Understanding the ps Command
- ps Command in Linux
- How to Use the ps Command in Linux?
- Alternatives of ps Command in Linux
- Conclusion
Let’s begin the guide with the basic working of the ps command in Linux.
Understanding the ps Command
At its core, the “ps” command allows users to view the active processes on the Linux system. Each process has a PID that assists users in identifying and managing it. When users execute only the “ps” command, it lists/displays the processes running in the shell:
ps
The output includes two running processes having columns such as PID (Process ID), TTY (controlling terminal), TIME (CPU time), and CMD (command used to start the process).
ps Command in Linux
The ps command in Linux is utilized to see/display information about active processes. Here’s a quick guide with practical usage:
Syntax of ps Command in Linux
The “ps” command can be used with various options that can be categorized into UNIX (single dash and can be grouped), BSD (do not require a dash and can also be grouped), and GNU (pipelined with more than one command) styles.
ps [options]
Options and Usage
Let’s enlist the possible options of the ps command along with the description:
| Options | Description |
|---|---|
| ps -e | Shows all processes. |
| ps -u [user] | Lists /Shows processes for the specified user. |
| ps -f | Displays a full-format listing. |
| ps -aux | Shows all processes for all users. (Detailed) |
| ps -e -o pid,uname,cmd | Lists all processes with custom columns (PID, username, and command). |
| ps -ef | grep [process_name] | Searches for a specific process by name. |
Note: Remember, users can combine options to customize the output as needed.
How to Use the ps command in Linux?
The “ps” command is an efficient utility for monitoring active processes. To use the “ps” command in Linux, simply type “ps” in the terminal to view the processes associated with the current terminal session.
Here are some common examples of how to use the “ps” command:
Example 1: List All Processes
In Linux, ps enlists processes running in the current shell. To list all processes with a terminal, use the “ps -a” command below:
ps -a
Example 2: View All Processes
Users can use “ps -e” or “ps -A” commands to display/view all processes in the Linux terminal:
ps -e
Example 3: Lists Specific User Processes
To list all processes owned by a specific user, use the “ps -u username” syntax as below. Here, “minhal” is the username of the current machine:
ps -u minhal
Example 4: Enlist Process in User-Oriented Format
To display processes in a user-oriented format, use the “ps” command with the “u” option as below:
ps -u
Example 5: Show a Full-Format Listing (Grouped)
Another popular option that gives a full-format listing of all processes. To show a full-format listing use the “ps -ef” command, where “-e” selects all processes and “-f” provides a full-format listing:
ps -ef
Example 6: List/Display All Processes for All Users
The “ps aux” where “a” lists all processes, “u” provides a user-oriented format, and “x” includes processes without a controlling terminal:
ps aux
Example 7: List All Processes and Threads
To list all processes and their threads, use the “ps” command with the “eLf” option:
ps -eLf
Example 8: List Process Hierarchy/Tree
To view parent-child relationships/hierarchy, use the “ps -ejH” or “ps axjf/” commands. Let’s display a process tree:
ps -ejH
To show processes not associated with a terminal, use the “ps” command with the “x” option:
ps -x
Example 9: Find and Kill Zombie Processes
To find all zombie processes, use the “ps aux | grep ‘Z’” command, where “aux” is an option combination that presents all processes in a user-oriented format, and “grep ‘Z’” filters the output to show only the zombie processes:
ps aux | grep 'Z'
Example 10: Locate the PID of a Specific Process
The “ps” command, combined with grep, allows users to locate the PID of a specific process quickly. For example, `ps aux | grep apache` would list all Apache-related processes, making it easier to manage them:
ps aux | grep apache
Example 11: Sort Processes Based on Resource Usage
Users can sort the processes based on resource usage and pinpoint the ones that may be causing system slowdowns. For this, use the “ps” command, with the “-o %cpu,%mem,pid,cmd” option. It is useful in performance tuning and ensuring that the system efficiently works:
ps -o %cpu,%mem,pid,cmd
Troubleshooting
Whether you’re troubleshooting, monitoring system resources, or just curious about what’s running on the machine, “ps” provides the necessary visibility into your system’s operations. For a deeper dive into the “ps” command, consider reading the manual page by typing “man ps” in the terminal.
Alternatives of ps Command in Linux
In the Linux environment, the “ps” command is a traditional tool for listing the processes running on the system. However, several alternatives can be used for similar purposes:
proc
One such alternative is exploring the “/proc” filesystem directly, which contains a directory for each currently running process identified by its process ID. Commands like “ls -l /proc/*/exe” can provide information about the executables for running processes.
top
Additionally, well-known commands like “top”, “htop”, and “atop” provide dynamic real-time views of the system, with “htop” being particularly popular for its interactive interface and ease of use.
procs
Another modern alternative is “procs”, a command-line tool written in Rust, which offers a more user-friendly and colorful output compared to the “ps” command.
Conclusion
The “ps” command is an essential tool for Linux system administration, providing insights into the performance and behavior of running processes. To list/display all running processes on Linux, use the “ps” ”top”, “htop”, and “atop” commands.
To list running processes in Linux, use the “ps”, “ps -A”, or “ps -e” commands. If users are required to display the full command line of the process, use “ps -f”. In addition, “ps aux” provides a detailed list of all processes. The “ps” command can be utilized with several commands like “grep” for filtering the output of “awk” for more complex processing. It can be utilized in several scenarios, such as monitoring system resources, troubleshooting issues as well as managing processes.













