Re: Get pid of child that has exited?



How does one get the pid if a child process that has exited? On other
systems this is available in siginfo_t but si_pid seems to be 0. Is
that normal?

wait4, wait3 and waitpid will all return it:

If wait4(), wait3(), or waitpid() returns due to a stopped, continued, or
terminated child process, the process ID of the child is returned to the
calling process. If there are no children not previously awaited, -1 is
returned with errno set to ECHILD. Otherwise, if WNOHANG is specified
and there are no stopped, continued or exited children, 0 is returned.
If an error is detected or a caught signal aborts the call, a value of -1
is returned and errno is set to indicate the error.

I don't know if si_pid == 0 is normal. I rarely use SIGCHILD to get
the status of a child process.

Warner
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: waitpid not reaping child
    ... I am trying to use waitpid with WNOHANG in a loop, ... returning 0 and the child process goes into <defunct> state. ...
    (comp.unix.programmer)
  • waitpid
    ... What's the point of waitpid with WNOHANG and the value ... Also suppose that in each iteration I fork one process. ... have yet to terminate. ... a new child process is forked but the last three child ...
    (comp.unix.programmer)
  • waitpid not reaping child
    ... I am trying to use waitpid with WNOHANG in a loop, ... returning 0 and the child process goes into <defunct> state. ...
    (comp.unix.programmer)
  • Re: SIGCHLD recursion
    ... int n, status; ... printf("Didn't reap any childred\n"); ... Replace the wait4() call with a waitpidcall... ... The current problem is that child process is not "seen" by the wait4 ...
    (comp.unix.aix)
  • Re: waitpid not reaping child
    ... I am trying to use waitpid with WNOHANG in a loop, ... returning 0 and the child process goes into <defunct> state. ...
    (comp.unix.programmer)