Writing my own toy shell, and have run into a bump trying to implement job control.
I am setting the process group of the child, both in the child and the parent with setpgid. My wait call is:
pid = waitpid(-pid, &status, 0)
However, waitpid returns -1 and perror says "No child process". However, it does seem to wait every time. Also, ps output looks right to mean when run from the shell. Since ps parent's process is kbsh like I would expect.
% ps -o pid,ppid,pgrp,session,tpgid,comm
Forking
In Parent: Setting process group to 20809 of process 20809 with setpgid
In Child Processes, pid of child process is 20809
in Child: Setting process group to 20809 of process 20809 with setpgid
Requesting that Process Group 20809 becomes the foreground process with tcsetpgrp
Waiting for job with process group 20809
PID PPID PGRP SESS TPGID COMMAND
12002 32573 12002 12002 20809 zsh
20808 12002 20808 12002 20809 kbsh
20809 20808 20809 12002 20809 ps
Wait Error: No child processes
Restoring Shell process group 20808 to forground
Anyone see what I am doing wrong? can post more code if need be...