System() returning ECHILD error on FreeBSD 7.2

Naveen Gujje gujjenaveen at gmail.com
Wed Feb 10 18:52:44 UTC 2010


On Wed, Feb 10, 2010 at 11:28 PM, Andriy Gapon <avg at icyb.net.ua> wrote:

> on 10/02/2010 19:52 Garrett Cooper said the following:
> >     Isn't this section of the system(3) libcall essentially doing what
> > you want, s.t. you'll never be able to get the process status when you
> > call waitpid(2)?
> >
> >        do {
> >            pid = _wait4(savedpid, &pstat, 0, (struct rusage *)0);
> >        } while (pid == -1 && errno == EINTR);
> >        break;
> >
> >     You typically get status via wait*(2) when using exec*(2) or via
> > the return codes from system(3), not system(3) with wait*(2)...
>
> Exactly.  I think that SIGCHLD handler would effectively 'reap' the child
> and thus
> wait*() in system would rightfully return ECHILD (perhaps after doing EINTR
> iteration of the loop).
>
> Since we block SIGCHLD signal in system(3) till we return from wait4(), i
think there
is no way in which SIGCHLD handler gets invoked? Am I correct or Am I
missing something?

If I do the following then I don't see any problem

oldsa = signal(SIGCHLD, SIG_DFL);
if (0 != system(command))
   exit(1);
signal(SIGCHLD, oldsa);

Thanks,
Naveen Gujje

--
> Andriy Gapon
>


More information about the freebsd-hackers mailing list