04-25-04 06:34 PM
the problem is i'm trying to record the order of the the child process
termination in a array and the time in other. How do i record this
information whithout block the parent process??
if i do something like
pid = waitpid(WAIT_ANY,&status,WNOHANG);
pidarray[i] = pid;
pidttime[i] = time(NULL);
i don't get the correct pids and times...
the libc manual say:
"
Here's an example of how to use `waitpid' to get the status from all
child processes that have terminated, without ever waiting. This
function is designed to be a handler for `SIGCHLD', the signal that
indicates that at least one child process has terminated.
void
sigchld_handler (int signum)
{
int pid, status, serrno;
serrno = errno;
while (1)
{
pid = waitpid (WAIT_ANY, &status, WNOHANG);
if (pid < 0)
{
perror ("waitpid");
break;
}
if (pid == 0)
break;
notice_termination (pid, status);
}
errno = serrno;
}
"
so i try
pidarray[i] = pid;
pidttime[i] = time(NULL);
instead of notice_termination (pid, status)
but i get the "waitpid: No child processes" error...
what should i do?
En el artículo <PtCdnVRRXffUfxbd4p2dnA@speakeasy.net>, Marc Rochkind escribió:
>
> "Aless" <natre_dev@NetexploraPtoCom.spamRq> wrote in message
> news:c6gmrm$ths$1@news1.nivel5.cl...
>
> You can't. The chief purpose of SIGCHLD is so it can be ignored, which
> prevents exited children from becoming zombies (unwaited for but inactive
> children). If you really want status from a child or to know which specifi
c
> one exited, you should use one of the wait system calls (and leave SIGCHLD
> alone). It's possible to use them in a non-blocking fashion, so your progr
am
> doesn't wait if there are no zombies around.
>
> (On some systems with optional Real-Time Signals, there is a way to get mo
re
> information in a signal handler, but even on those systems the standard
> doesn't require that information to be supplied for classic signals like
> SIGCHLD.)
>
--
.''`.
: :' : Alex Lorca
`. `'
[ Post a follow-up to this message ]
|