I m working on a basic shell in C. In my implementation of 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 in earlier code, but somehow I ve broken 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 if the child has already terminated.
Why, and in what cases will wait()
cause a segfault? How do I go about debugging this sort of thing?