开发者

Signal 11 segfault on wait() system call?

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 _开发者_如何学Pythonwaitpid () 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?


You are probably passing an invalid pointer for the status argument to wait(2).

As for how to debug this sort of thing, my first step would be to install the debugging symbols for your C library. Then look at which pointer its faulting on and trace it back up the stack (if possible).


Look at the arguments you're calling wait() with, and also look for memory overwrite issues. Run your program through Valgrind to get help detecting many overwrites very easily.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜