Linux ps command options


The ps (process status) command in Linux provides detailed information about running processes on the system. Below, I'll explain several common ps command options and provide examples of their usage and the resulting output.

1. ps (Default Usage)

By default, ps shows processes running in the current terminal session.

ps

Sample Output:

PID TTY TIME CMD 1001 pts/0 00:00:01 bash 2002 pts/0 00:00:00 ps
  • PID: Process ID.
  • TTY: Terminal associated with the process.
  • TIME: Cumulative CPU time the process has used.
  • CMD: The command or program that started the process.

2. ps -e or ps -A (Show All Processes)

This option lists all processes running on the system, not just those associated with the current terminal.

ps -e

Sample Output:

PID TTY TIME CMD 1 ? 00:00:01 systemd 101 ? 00:00:00 sshd 102 ? 00:00:00 apache2 103 ? 00:00:00 ps
  • This displays all system processes, including system daemons.

3. ps -f (Full Format)

This option shows a more detailed listing of the processes, including the parent process ID (PPID), user ID (UID), and command with its arguments.

ps -f

Sample Output:

UID PID PPID C STIME TTY TIME CMD root 1 0 0 Jan01 ? 00:00:01 systemd root 101 1 0 Jan01 ? 00:00:00 sshd www-data 102 1 0 Jan01 ? 00:00:01 apache2 user 103 101 0 00:00 pts/0 00:00:00 ps
  • UID: User ID of the process owner.
  • PID: Process ID.
  • PPID: Parent Process ID.
  • C: CPU utilization.
  • STIME: Start time of the process.
  • CMD: Command and its arguments.

4. ps -u <username> (Show Processes for Specific User)

This option filters processes by a specific user, showing only those owned by that user.

ps -u root

Sample Output:

PID TTY TIME CMD 1 ? 00:00:01 systemd 101 ? 00:00:00 sshd 102 ? 00:00:00 apache2
  • This will show only the processes run by the root user.

5. ps -a (Show Processes for All Users)

Displays all processes associated with terminals, including those of other users (excluding session leaders).

ps -a

Sample Output:

PID TTY TIME CMD 1001 pts/0 00:00:01 bash 2002 pts/0 00:00:00 ps
  • This shows processes in the terminal, including those from other users, excluding daemon processes.

6. ps -x (Show Processes Without a Terminal)

This option shows processes that are not associated with a terminal (i.e., background processes, daemons).

ps -x

Sample Output:

PID TTY TIME CMD 1 ? 00:00:01 systemd 102 ? 00:00:00 apache2
  • This will display processes that are not attached to a terminal (such as daemons).

7. ps aux (Show All Processes with Detailed Info)

The aux option combination provides a detailed view of all running processes on the system, including processes from all users, with information such as CPU and memory usage.

ps aux

Sample Output:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 169276 6332 ? Ss Jan01 0:01 /sbin/init root 101 0.0 0.0 60100 1564 ? Ss Jan01 0:00 /usr/sbin/sshd www-data 102 0.1 1.2 150000 12345 ? S Jan01 0:10 /usr/sbin/apache2 user 103 0.0 0.1 56000 1824 pts/0 R+ 14:00 0:00 ps aux
  • USER: The user who owns the process.
  • PID: Process ID.
  • %CPU: Percentage of CPU usage by the process.
  • %MEM: Percentage of memory usage by the process.
  • VSZ: Virtual memory size of the process.
  • RSS: Resident Set Size (physical memory the process is using).
  • STAT: Process status (e.g., S for sleeping, R for running).
  • START: Process start time.
  • TIME: Cumulative CPU time used by the process.
  • COMMAND: Command that started the process.

8. ps -l (Long Format)

This option provides a longer, more detailed format with additional columns, including flags, priority, and memory information.

ps -l

Sample Output:

F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 4 S 0 1 0 0 80 0 - 108072 912 wait ? 00:00:01 systemd 4 S 0 101 1 0 80 0 - 60968 876 tty1 ? 00:00:00 sshd 4 S 33 102 101 0 80 0 - 134432 3008 wait ? 00:00:00 apache2
  • F: Flags associated with the process.
  • S: Process state (e.g., S for sleeping).
  • UID: User ID of the process owner.
  • PID: Process ID.
  • PPID: Parent Process ID.
  • C: CPU usage.
  • PRI: Process priority.
  • NI: Nice value.
  • ADDR: Memory address where the process is loaded.
  • SZ: Size of the process in memory.
  • WCHAN: If sleeping, shows the event the process is waiting for.
  • TTY: Terminal associated with the process.
  • TIME: CPU time used.
  • CMD: Command and its arguments.

9. ps -o <format> (Custom Output Format)

You can specify a custom output format to display only selected information, such as process ID, memory usage, or CPU usage.

ps -o pid,uid,etime,comm

Sample Output:

PID UID ELAPSED COMMAND 1 0 10-04:30 systemd 101 0 10-04:30 sshd 102 33 10-04:30 apache2
  • This command shows the process ID, user ID, elapsed time, and command.

10. ps -p <pid> (Show Specific Process)

Use the -p option followed by a process ID (PID) to display information about a specific process.

ps -p 101

Sample Output:

PID TTY TIME CMD 101 ? 00:00:00 sshd
  • This shows the process details for the process with PID 101.

Conclusion:

The ps command in Linux offers various options to monitor and display detailed information about processes. By using options such as -e, -f, -u, aux, and -o, you can tailor the output to meet your needs, making it a powerful tool for process management and troubleshooting.