The ps command in Linux is used to display information about currently running processes. Here are some common usages and options for the ps command:
Basic Usage
-
Display Current User's Processes:
psThis command shows processes running in the current shell.
-
Display All Processes:
ps -eThis lists all processes running on the system.
-
Display Processes with Full Format:
ps -efThis provides a detailed view of all processes, including user, PID, CPU usage, and command.
Common Options
-a: Show processes for all users.-u: Display processes for a specific user.-x: Show processes not attached to a terminal.-f: Full-format listing, showing additional details.--sort: Sort the output based on a specified field (e.g.,--sort=-%memto sort by memory usage).
Examples
-
Show All Processes with Detailed Information:
ps -auxThis command shows all processes with detailed information, including user, PID, CPU, and memory usage.
-
Filter Processes by User:
ps -u usernameReplace
usernamewith the actual username to see processes owned by that user. -
Show Processes Sorted by Memory Usage:
ps aux --sort=-%memThis command lists all processes sorted by memory usage in descending order.
-
Show Processes with a Specific Command:
ps -ef | grep process_nameReplace
process_namewith the name of the process you want to find.
Summary
The ps command is a powerful tool for monitoring and managing processes in Linux. You can combine various options to customize the output according to your needs. If you have any specific scenarios or further questions, feel free to ask!
