1

I understand that when a process is started from a shell in linux or unix, a new process group is created with that process as the process leader, giving its PID equal to a new PGID which is used for any processes spawn from that process.

As I understand it, in the case where the process leader is terminated, a new process becomes leader. This new leader would then have a PID inequal to the PGID of the process group. So then, looking at all the processes in the group, how would I identify which is the leader?

2
  • Did you try ps fax? Commented Mar 2, 2023 at 7:18
  • I tried ps axjf which is I think roughly equivalent. The problem isn't getting the PID and PGID fields, its interpreting them :)
    – Andrew
    Commented Mar 4, 2023 at 4:04

1 Answer 1

1

You could run:

pgrep -g <PGID>

This will return you all the PIDs of the group. The first one is the leader.

You could run if you only want the leader:

pgrep -g <PGID> | head -1 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .