|
|
1.1 root 1: # include <errno.h>
2: # include <sccs.h>
3:
4: SCCSID(@(#)fullwait.c 7.1 2/5/81)
5:
6: /*
7: ** FULLWAIT -- performs a wait(II) primitive for a given child.
8: **
9: ** The wait primitive is executed as many times as needed to get
10: ** termination status for a given child. The case of an interrupt
11: ** during the wait is handled. No other children may die during
12: ** the wait. Also, the child must die "normally", that is, as the
13: ** result of an exit() system call, or from an interrupt.
14: **
15: ** Parameters:
16: ** "child" -- the pid of the child process to wait for,
17: ** returned from the fork() system call.
18: ** "name" -- a character string representing the name of
19: ** the calling routine; printed on syserr's.
20: ** Returns:
21: ** The exit parameter of the child process.
22: */
23:
24: fullwait(child, name)
25: int child;
26: char *name;
27: {
28: auto int st;
29: register int i;
30: extern int errno;
31: register char *n;
32: register char *coredump;
33:
34: n = name;
35:
36: /* wait for a child to die */
37: while ((i = wait(&st)) != child)
38: {
39: /* it is not the child we want; chew on it a little more */
40: if (i != -1)
41: syserr("%s: bad child: pid %d st 0%o", n, i, st);
42:
43: /* check for interrupted system call */
44: if (errno != EINTR)
45: {
46: /* wait with no child */
47: syserr("%s: no child", n);
48: }
49: errno = 0;
50:
51: /* dropped out from signal: reexecute the wait */
52: }
53:
54: /* check termination status */
55: i = st & 0377;
56: if (i > 2)
57: {
58: /* child collapsed */
59: if (i & 0200)
60: {
61: coredump = " -- core dumped";
62: i &= 0177;
63: }
64: else
65: {
66: coredump = "";
67: }
68: syserr("%s: stat %d%s", n, i, coredump);
69: }
70:
71: /* return exit status */
72: return (st >> 8);
73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.