previous | start | next

Changing Process Group and Foreground Process (2)

Suppose the shell is currently the foreground process.

Then the shell creates a child to execute some program and the child should.

The child should be placed in its own process group different from the shell's group. (Why?)

If the child is to be run in the foreground, the child's new process group should become the foreground process instead of the shell.

The process group of the child can be changed using

int setpgid(pid_t pid, pid_t pgid);

The foreground process can be set using

 int tcsetpgrp(int fd, pid_t pgrp);     
     

Which process should call which function and in what order?

If the child calls setpgid to change its process group, it is no longer part of the foreground process (the shell is). So if the child then calls tcsetpgrp to make it be the foregroud process, it will get the SIGTTOU signal.



previous | start | next