wait_pid.c (709B)
1 #include <sys/types.h> 2 #include <sys/wait.h> 3 #include "error.h" 4 #include "haswaitp.h" 5 6 #ifdef HASWAITPID 7 8 int wait_pid(wstat,pid) int *wstat; int pid; 9 { 10 int r; 11 12 do 13 r = waitpid(pid,wstat,0); 14 while ((r == -1) && (errno == error_intr)); 15 return r; 16 } 17 18 #else 19 20 /* XXX untested */ 21 /* XXX breaks down with more than two children */ 22 static int oldpid = 0; 23 static int oldwstat; /* defined if(oldpid) */ 24 25 int wait_pid(wstat,pid) int *wstat; int pid; 26 { 27 int r; 28 29 if (pid == oldpid) { *wstat = oldwstat; oldpid = 0; return pid; } 30 31 do { 32 r = wait(wstat); 33 if ((r != pid) && (r != -1)) { oldwstat = *wstat; oldpid = r; continue; } 34 } 35 while ((r == -1) && (errno == error_intr)); 36 return r; 37 } 38 39 #endif