comparison sbr/pidstatus.c @ 0:bce86c4163a3

Initial revision
author kono
date Mon, 18 Apr 2005 23:46:02 +0900
parents
children 441a2190cfae
comparison
equal deleted inserted replaced
-1:000000000000 0:bce86c4163a3
1 /* pidstatus.c - report child's status */
2 #ifndef lint
3 static char ident[] = "@(#)$Id$";
4 #endif /* lint */
5
6 #include "../h/mh.h"
7 #include <signal.h>
8 #include <stdio.h>
9
10
11 #ifndef BSD44
12 #ifndef BSD42
13 static char *sigs[] = {
14 NULL,
15 "Hangup",
16 "Interrupt",
17 "Quit",
18 "Illegal instruction",
19 "Trace/BPT trap",
20 "IOT trap",
21 "EMT trap",
22 "Floating exception",
23 "Killed",
24 "Bus error",
25 "Segmentation fault",
26 "Bad system call",
27 "Broken pipe",
28 "Alarm clock",
29 "Terminated",
30 #ifdef SIGURG
31 "Urgent I/O condition",
32 #else
33 NULL,
34 #endif
35 "Stopped (signal)",
36 "Stopped",
37 "Continued",
38 "Child exited",
39 "Stopped (tty input)",
40 "Stopped (tty output)",
41 "Tty input interrupt",
42 "Cputime limit exceeded",
43 "Filesize limit exceeded",
44 NULL
45 };
46 #else
47 extern char *sys_siglist[];
48 #endif /* BSD42 */
49 #endif /* BSD44 defines sys_siglist in signal.h */
50
51 /* */
52
53 int pidstatus (status, fp, cp)
54 register int status;
55 register FILE *fp;
56 register char *cp;
57 {
58 int signum;
59
60 if ((status & 0xff00) == 0xff00)
61 return status;
62
63 switch (signum = status & 0x007f) {
64 case OK:
65 if (signum = ((status & 0xff00) >> 8)) {
66 if (cp)
67 fprintf (fp, "%s: ", cp);
68 fprintf (fp, "Exit %d\n", signum);
69 }
70 break;
71
72 case SIGINT:
73 break;
74
75 default:
76 if (cp)
77 fprintf (fp, "%s: ", cp);
78 #ifndef BSD42
79 if (signum >= sizeof sigs || sigs[signum] == NULL)
80 fprintf (fp, "Signal %d", signum);
81 else
82 fprintf (fp, "%s", sigs[signum]);
83 #else /* BSD42 */
84 if (signum >= NSIG)
85 fprintf (fp, "Signal %d", signum);
86 else
87 fprintf (fp, "%s", sys_siglist[signum]);
88 #endif /* BSD42 */
89 fprintf (fp, "%s\n", status & 0x80 ? " (core dumped)" : "");
90 break;
91 }
92
93 return status;
94 }