8 #include <sys/resource.h>
18 SIGILL, "sys: illegal instruction",
19 SIGTRAP, "sys: breakpoint",
20 SIGABRT, "sys: abort",
22 SIGEMT, "sys: emulate instruction executed",
24 SIGFPE, "sys: fp: trap",
26 SIGBUS, "sys: bus error",
27 SIGSEGV, "sys: segmentation violation",
30 SIGURG, "sys: urgent condition on socket",
34 SIGCHLD, "sys: child",
37 SIGIO, "sys: i/o possible on fd",
38 SIGXCPU, "sys: cpu time limit exceeded",
39 SIGXFSZ, "sys: file size limit exceeded",
40 SIGVTALRM, "sys: virtual time alarm",
41 SIGPROF, "sys: profiling timer alarm",
42 SIGWINCH, "sys: window size change",
44 SIGINFO, "sys: status request",
48 SIGPIPE, "sys: write on closed pipe",
52 _p9sigstr(int sig, char *tmp)
56 for(i=0; i<nelem(tab); i++)
61 sprint(tmp, "sys: signal %d", sig);
70 for(i=0; i<nelem(tab); i++)
71 if(strcmp(s, tab[i].str) == 0)
77 _await(int pid4, char *str, int n, int opt)
81 char buf[128], tmp[64];
85 /* On Linux, pid==-1 means anyone; on SunOS, it's pid==0. */
87 pid = wait3(&status, opt, &ru);
89 pid = wait4(pid4, &status, opt, &ru);
92 u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000);
93 s = ru.ru_stime.tv_sec*1000+((ru.ru_stime.tv_usec+500)/1000);
94 if(WIFEXITED(status)){
95 status = WEXITSTATUS(status);
97 snprint(buf, sizeof buf, "%d %lud %lud %lud %d", pid, u, s, u+s, status);
99 snprint(buf, sizeof buf, "%d %lud %lud %lud ''", pid, u, s, u+s, status);
100 strecpy(str, str+n, buf);
103 if(WIFSIGNALED(status)){
104 cd = WCOREDUMP(status);
105 snprint(buf, sizeof buf, "%d %lud %lud %lud 'signal: %s%s'", pid, u, s, u+s, _p9sigstr(WTERMSIG(status), tmp), cd ? " (core dumped)" : "");
106 strecpy(str, str+n, buf);
113 await(char *str, int n)
115 return _await(-1, str, n, 0);
119 awaitnohang(char *str, int n)
121 return _await(-1, str, n, WNOHANG);
125 awaitfor(int pid, char *str, int n)
127 return _await(pid, str, n, 0);