ps Command in Linux

Topics Covered

Overview

The ps command in Linux is a powerful tool for displaying information about running processes on your system. It allows you to view detailed information about the processes, including their resource usage, process IDs, and much more. In this article, we will explore the ps command in detail and learn how to use it effectively.

Linux ps Command Syntax

The syntax for the ps command is as follows:

Where:

  • Options: The various options available with the ps command

ps Command Options:

  • -a: Show processes for all users
  • -u: Display user-oriented format
  • -x: Include processes that do not have a controlling terminal
  • -e: Show information about all processes
  • -f: Display a full listing of processes with additional information

Example Usages

  • Viewing all running processes:

    Output:

    Explanation: This command displays a list of all running processes on the system. The output shows the process ID (PID), the terminal or pseudo terminal associated with the process (TTY), the amount of CPU time consumed by the process (TIME), and the command that started the process (CMD).

  • Viewing processes for all users:

    Output:

    Explanation: The -e option shows information about all processes, while the -f option provides a full listing of processes with additional information. The UID field displays the user ID of the owner of the process, while the PPID field shows the parent process ID. The C field displays the CPU utilization of the process, and the STIME field shows the start time of the process. The CMD field displays the command that started the process.

  • Viewing detailed process information:

    Output:

    Explanation: The aux options together provide a lot of detailed information about running processes, including the percentage of CPU and memory used by each process, the virtual memory size (VSZ) and resident set size (RSS) of each process, and the process state (STAT). The START field shows the start time of the process, and the TIME field shows the CPU time consumed by the process.

Tips

  • To sort the output of the ps command by CPU usage, use the ps aux --sort=-%cpu command.

  • To display information about threads associated with each process, use the ps -eLf command.

  • To display processes in a tree-like format, use the ps axjf command.

Advanced Use Cases of ps Command in Linux

  • Displaying only specific processes:

    Output:

    Explanation: This command displays only the process specified by its process ID (PID). Replace <pid> with the actual process ID.

  • Displaying parent process information:

    Output:

    Explanation: This command displays the parent process of a specified process. Replace <pid> with the process ID of the child process, and <ppid> with the parent process ID.

  • Displaying the processes running on a specific terminal:

    Output:

    Explanation: This command displays the processes running on the specified terminal. Replace <tty> with the terminal name.

Conclusion

  • The ps command is a powerful tool for displaying information about running processes on your Linux system.

  • The ps command can display detailed information about the processes, including their resource usage, process IDs, and much more.

  • By using various options with the ps command, you can view specific information about running processes that is relevant to your needs.

  • The ps command can be used to monitor and troubleshoot system performance issues, and it is a valuable tool for system administrators and developers.