0

How can process become a member of a PGRP?

My attempt: Process needs to be a child of a PGRP's leader or we need to use a system call setpgid().

Also, another two questions.

1) How can process become a leader of a group? I can only think about creating a new process, which will automatically become a leader

2) Can group have many leaders? I think it is impossible, but can't find any information about this

Are my answers correct?

1

I can only think about creating a new process, which will automatically become a leader

False.

#include <stdio.h>
#include <unistd.h>
int main(void) {
    pid_t pid;
    pid = fork();
    printf("%d member of %d\n", getpid(), getpgrp());
    return 0;
}

The new process shares the group of the parent:

$ make leadership
cc -g    leadership.c   -o leadership
$ ./leadership
65617 member of 65617
65618 member of 65617
$ 

Only with setpgid(2) or setsid(2) or similar system calls will the group or leadership change.

2) Can group have many leaders?

False. Quoting from Stevens, "Advanced Programming in the UNIX Environment" (2nd ed.), chapter 9 section 4 (p. 243):

"Each process group can have a process group leader. The leader is identified by having its process group ID equal to its process ID."

Singular leader, and a very specific case for identifying said leader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.