Najpierw odniosę się do ustawienia grupy procesów, tj. setpgrp., które musimy wykonać na podprocesie zanim ten wywoła execve. Przytoczę ustęp z rozdziału 9.4 APUE:
In most job-control shells, this function is called after a fork to have the parent set the process group ID of the child, and to have the child set its own process group ID. One of these calls is redundant, but by doing both, we are guaranteed that the child is placed into its own process group before either process assumes that this has happened. If we didn’t do this, we would have a race condition, since the child’s process group membership would depend on which process executes first.
Jeśli to jest zrozumiałe, to pozostaje kwestia, czy wołać tcsetpgrp od razu za setpgrp, czy dopiero w monitorjobs.
Jeśli nie zdążymy wypromować grupy procesów do pierwszoplanowej zanim wszystkie procesy ją opuszczą, to tcsetpgrp powinno zawieść (?) i to nie jest błąd.
Na razie nie znajduję argumentów za tym by w tym samym miejscu robić setpgrp i tcsetpgrp. Gdyby jednak okazało się to niezbędne, to należy dorobić prostego wrappera w pliku jobs.c i wystawić jego deklarację do shell.h.