From: alexandrug on
On Nov 28, 12:59 am, pac...(a)kosh.dhis.org (Alan Curry) wrote:

> In article <e22036c1-e514-430d-b372-93681ff25...(a)m3g2000yqf.googlegroups.com>,
>
>
>
> alexandrug  <webaig...(a)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.
From: Alan Curry on
In article <31306251-f3bb-49e4-8a2d-624f72af585c(a)9g2000yqa.googlegroups.com>,
alexandrug <webaigoia(a)gmail.com> wrote:
>On Nov 28, 12:59�am, pac...(a)kosh.dhis.org (Alan Curry) wrote:
>
>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 ? (*)

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