]>
diplodocus.org Git - nmh/blob - sbr/pidwait.c
3 * pidwait.c -- wait for child to exit
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/signals.h>
17 #ifdef HAVE_SYS_WAIT_H
18 # include <sys/wait.h>
22 pidwait (pid_t id
, int sigsok
)
25 SIGNAL_HANDLER istat
, qstat
;
34 /* ignore a couple of signals */
35 istat
= SIGNAL (SIGINT
, SIG_IGN
);
36 qstat
= SIGNAL (SIGQUIT
, SIG_IGN
);
40 while ((pid
= waitpid(id
, &status
, 0)) == -1 && errno
== EINTR
)
43 while ((pid
= wait(&status
)) != -1 && pid
!= id
)
48 /* reset the signal handlers */
49 SIGNAL (SIGINT
, istat
);
50 SIGNAL (SIGQUIT
, qstat
);
54 return (pid
== -1 ? -1 : status
);
56 return (pid
== -1 ? -1 : status
.w_status
);