How do I use the `ps` command?

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

  1. Display Current User's Processes:

    ps

    This command shows processes running in the current shell.

  2. Display All Processes:

    ps -e

    This lists all processes running on the system.

  3. Display Processes with Full Format:

    ps -ef

    This 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=-%mem to sort by memory usage).

Examples

  1. Show All Processes with Detailed Information:

    ps -aux

    This command shows all processes with detailed information, including user, PID, CPU, and memory usage.

  2. Filter Processes by User:

    ps -u username

    Replace username with the actual username to see processes owned by that user.

  3. Show Processes Sorted by Memory Usage:

    ps aux --sort=-%mem

    This command lists all processes sorted by memory usage in descending order.

  4. Show Processes with a Specific Command:

    ps -ef | grep process_name

    Replace process_name with 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!

0 Comments

no data
Be the first to share your comment!