How to filter the output of the 'ps' command?
Sometimes, you may want to filter the output of the 'ps' command to show only the processes that match certain criteria, such as a specific user, a specific name, or a specific status. You can use various options and arguments to filter the output of the 'ps' command, such as:
- -U or --user: These options show only the processes that belong to a specific user or a list of users. For example, 'ps -U root' shows only the processes that belong to the root user.
- -C or --comm: These options show only the processes that have a specific command name or a list of command names. For example, 'ps -C sshd' shows only the processes that have the command name sshd.
- --pid or --ppid: These options show only the processes that have a specific process ID or a list of process IDs, or a specific parent process ID or a list of parent process IDs. For example, 'ps --pid 1' shows only the process that has the process ID 1, which is usually the init process.
- --state or --stat: These options show only the processes that have a specific state or a list of states. The state of a process indicates its current activity, such as running, sleeping, stopped, or zombie. For example, 'ps --state Z' shows only the processes that have the state Z, which means zombie.