I'm new to processes in *nix, and am working on a basic shell in C... in implementing pipes, I count the commands on the line and iteratively fork() a new process.
At the end of each iteration I wait() on the child before proceeding to the next command. This was working fine, but I've apparently changed something to break it:
Program terminated with signal 11, Segmentation fault.
#0 0xfef28730 in _waitpid () from /usr/lib/libc.so.1
(gdb) backtrace
#0 0xfef28730 in _waitpid () from /usr/lib/libc.so.1
#1 0xfef28770 in _wait () from /usr/lib/libc.so.1
#2 0xfef696d1 in wait () from /usr/lib/libc.so.1
#3 0x08051428 in main ()
I understand that wait() will simply reap the zombie process should the child have already terminated. So why, and in what sort of cases, would wait() cause a segfault?
Alternatively, how would I go about debugging this sort of thing?