English 中文(简体)
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 _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?

最佳回答

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.





相关问题
Signal 11, segmentation fault on iphone App exit

I have an iphone app. It seems to run fine. When I connect to a provisioned iphone to Xcode and run the App, the console log in the Organizer window, always complains about a Segmentation fault when ...

Segmentation fault on large array sizes

The following code gives me a segmentation fault when run on a 2Gb machine, but works on a 4GB machine. int main() { int c[1000000]; cout << "done "; return 0; } The size of the ...

PHP doesn t handle stack overflow?

I was surprised when I just tried the following PHP code: function foo() { foo(); } foo(); I expected to get "500: Internal server error". Instead the connection was closed immediately (no bytes ...

PHP segmentation fault caused by php while loop

I discovered a way to make php segfault, and I m a bit curious about what s happening. Maybe someone can explain this for me? joern@xps:..com/trunk5/tools/nestedset> cat > while.php <?php ...

C: Accessing a pointer from outside a function

I have the following code: int takeEven(int *nums, int numelements, int *newlist) { newlist = malloc(numelements * sizeof *newlist); int i, found = 0; for(i = 0; i < numelements; ++i, ...

Segmentation fault on time(0);

I m rewriting an old program to do some new stuff, and suddenly I get a segmentation fault error on the following line of code: time_t seconds_since_time_begun = time(0); Why, oh why? Update: I ...

热门标签