May 2017
Beginner
552 pages
28h 47m
English
Suppose several instances of a command are being executed. In such a scenario, we need the PID of each process. Both the ps and pgrep command return this information:
$ ps -C COMMAND_NAME
Alternatively, the following is returned:
$ ps -C COMMAND_NAME -o pid=
When = is appended to pid, it removes the header PID from the output of ps. To remove headers from a column, append = to the parameter.
This command lists the process IDs of Bash processes:
$ ps -C bash -o pid=
1255
1680
The pgrep command also returns a list of process IDs for a command:
$ pgrep bash
1255
1680