9 #include <sys/resource.h>
11 #ifndef WCOREDUMP /* not on Mac OS X Tiger */
12 #define WCOREDUMP(status) 0
22 SIGILL, "sys: illegal instruction",
23 SIGTRAP, "sys: breakpoint",
24 SIGABRT, "sys: abort",
26 SIGEMT, "sys: emulate instruction executed",
28 SIGFPE, "sys: fp: trap",
30 SIGBUS, "sys: bus error",
31 SIGSEGV, "sys: segmentation violation",
34 SIGURG, "sys: urgent condition on socket",
38 SIGCHLD, "sys: child",
41 #ifdef SIGIO /* not on Mac OS X Tiger */
42 SIGIO, "sys: i/o possible on fd",
44 SIGXCPU, "sys: cpu time limit exceeded",
45 SIGXFSZ, "sys: file size limit exceeded",
46 SIGVTALRM, "sys: virtual time alarm",
47 SIGPROF, "sys: profiling timer alarm",
48 #ifdef SIGWINCH /* not on Mac OS X Tiger */
49 SIGWINCH, "sys: window size change",
52 SIGINFO, "sys: status request",
56 SIGPIPE, "sys: write on closed pipe",
60 _p9sigstr(int sig, char *tmp)
64 for(i=0; i<nelem(tab); i++)
69 sprint(tmp, "sys: signal %d", sig);
78 for(i=0; i<nelem(tab); i++)
79 if(strcmp(s, tab[i].str) == 0)
85 _await(int pid4, char *str, int n, int opt)
89 char buf[128], tmp[64];
93 /* On Linux, pid==-1 means anyone; on SunOS, it's pid==0. */
95 pid = wait3(&status, opt, &ru);
97 pid = wait4(pid4, &status, opt, &ru);
100 u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000);
101 s = ru.ru_stime.tv_sec*1000+((ru.ru_stime.tv_usec+500)/1000);
102 if(WIFEXITED(status)){
103 status = WEXITSTATUS(status);
105 snprint(buf, sizeof buf, "%d %lud %lud %lud %d", pid, u, s, u+s, status);
107 snprint(buf, sizeof buf, "%d %lud %lud %lud ''", pid, u, s, u+s, status);
108 strecpy(str, str+n, buf);
111 if(WIFSIGNALED(status)){
112 cd = WCOREDUMP(status);
113 snprint(buf, sizeof buf, "%d %lud %lud %lud 'signal: %s%s'", pid, u, s, u+s, _p9sigstr(WTERMSIG(status), tmp), cd ? " (core dumped)" : "");
114 strecpy(str, str+n, buf);
121 await(char *str, int n)
123 return _await(-1, str, n, 0);
127 awaitnohang(char *str, int n)
129 return _await(-1, str, n, WNOHANG);
133 awaitfor(int pid, char *str, int n)
135 return _await(pid, str, n, 0);