Michał Dadej
Michał Dadej

Reputation: 93

How to get list of PID's of the processes in the group

How to get list of PID's of the processes in the group of the process which is current, using ps one line. I have tried:

ps -g $$

but $$ is not group id but only PID How do I get PGID of `$$'?

Upvotes: 0

Views: 2324

Answers (2)

jarno
jarno

Reputation: 856

Why not use pgrep?

pgrep -g0

gives you the list of PID's of the processes in the group of the process which is current. (See man pgrep)

Note that the command outputs nothing, if job control (set -m) is active in shell, because current process has a new process group then.

Upvotes: 0

William Pursell
William Pursell

Reputation: 212268

Use ps to get the pgid of a process:

ps -o pgid $$

Upvotes: 2

Related Questions