Suppose I have this code :
{
pid = fork();
int exitcode = 0;
if (pid == 0) { do_some_actions(); }
if ( waitpid(pid, &exitcode,0) == -1)
{
switch(errno) {
case ECHILD: do_something();
break;
case EINTR: break;
default : break;
}
}
In what conditions we can have waitpid == -1 and errno == ECHILD,
supposing that the signal handler for SIGCHLD is NOT SIG_IGN ?
Thank you,
Alexandru.
In what you've shown, the waitpid() call executes in both
the parent and the child processes. In the child, it tries to
wait for pid zero -- that is, for any of the child's own children.
If the child has no children of its own, ECHILD is correct.
If that's not the problem with your actual code -- well,
I'm not a mind reader, and I can't debug what I can't see.
--
Eric Sosman
eso...@ieee-dot-org.invalid
More precisely, the code is like this :
{
pid = fork();
int exitcode = 0;
if (pid == 0) while(1) { do_some_actions(); }
// only in parent process
It could happen if pid==(pid_t)-1 i.e. fork failed, which you didn't check
for.
--
Alan Curry
> Greetings,
Hello,
waitpid() exeuted in the parent can fail with ECHILD eg. if there is a
handler for SIGCHLD and it calls wait*() function, or if another thread
calls wait() simultaneously. IMHO the best way to inspect this is run the
program under strace.
Regards
Jiri Palecek
> In article <e22036c1-e514-430d-b372-93681ff25...@m3g2000yqf.googlegroups.com>,
>
>
>
> alexandrug <webaig...@gmail.com> wrote:
> >> > In what conditions we can have waitpid == -1 and errno == ECHILD,
> >> > supposing that the signal handler for SIGCHLD is NOT SIG_IGN ?
>
> >More precisely, the code is like this :
>
> >{
> >pid = fork();
> >int exitcode = 0;
>
> >if (pid == 0) while(1) { do_some_actions(); }
>
> >// only in parent process
>
> >if ( waitpid(pid, &exitcode,0) == -1)
> >{
> >switch(errno) {
> >case ECHILD: do_something();
> > break;
> >case EINTR: break;
> >default : break;
>
> >}
> >}
>
> It could happen if pid==(pid_t)-1 i.e. fork failed, which you didn't check
> for.
>
> --
> Alan Curry
Suppose that
1) pid = fork() > 0, in parent process (ie, fork() was successful)
2) there is NOT any handler for SIGCHLD, that colls wait*()
3) there is NOT any thread which calls wait*()
4) the signal handler for SIGCHLD is set, but NOT to SIG_IGN
5) at runtime, we have waitpid(pid, &exitcode, 0) == -1
In what conditions we could have errno == ECHILD ? (*)
I noticed that if I kill -9 (manually) the child process, then
the child process (defunct) will still exist in the process table,
and a waitpid() on it would return a code of success.
Please help me with my question : (*).
Thanks,
Alexandru.
Let's just say it's a kernel bug. If it's reproducable, write a minimal test
program that demonstrates it, put a system("ps axj") after the errno==ECHILD
test, and follow your vendor's bug reporting procedure.
--
Alan Curry