while (1) {
register int pid;
int w;
struct process *p;
/* Keep asking for a status until we get a definitive result. */
do
{
errno = 0;
pid = waitpid (WAIT_ANY,&w,WNOHANG | WUNTRACED);
}
while (pid <= 0 && errno == EINTR);
if (pid <= 0) {
/* A real failure means there are no more
stopped or terminated child processes,so return. */
errno = old_errno;
return;
}
/* Find the process that signaled us,and record its status. */
for (p = process_list; p; p = p->next)
if (p->pid == pid) {
p->status = w;
/* Indicate that the <code>status</code> field
has data to look at. We do this only after storing it. */
p->have_status = 1;
/* If process has terminated,stop waiting for its output. */
if (WIFSIGNALED (w) || WIFEXITED (w))
if (p->input_descriptor)
FD_CLR (p->input_descriptor,&input_wait_mask);
/* The program should check this flag from time to time
to see if there is any news in <code>process_list</code>. */
++process_status_change;
}
/* Loop around to handle all the processes
that have something to tell us. */
}
}
process_status_change:
if (process_status_change) {
struct process *p;
process_status_change = 0;
for (p = process_list; p; p = p->next)
if (p->have_status) {
... Examine p->status ...
}
}
p->statusuntil it sees that status has been validly stored. This is to make sure that the status cannot change in the middle of accessing it. Oncep->have_status is set,it means that the child process is stopped or terminated,and in either case,it cannot stop or terminate again until the program has taken notice. See section,for more information about coping with interruptions during accessings of a variable.
sig_atomic_t process_status_change;
sig_atomic_t last_process_status_change; (编辑:威海站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|