Path: utzoo!utgpu!water!watmath!clyde!bellcore!faline!ulysses!allegra!mit-eddie!ll-xn!ames!sdcsvax!ucsdhub!hp-sdd!hplabs!hpcea!hpfcdc!rml From: rml@hpfcdc.UUCP Newsgroups: comp.unix.wizards Subject: Re: wait3 emulation in SYSTEMV ?? Message-ID: <5980017@hpfcdc.HP.COM> Date: 14 Jan 88 00:06:55 GMT References: <360@rruxa.UUCP> Organization: HP Ft. Collins, Co. Lines: 57 Posted: Wed Jan 13 19:06:55 1988 > >UNIX Wizards: Anyone on the net have any suggestions, or ideas on > > how to emulate the 4.2BSD wait3() system call under System V??? > > Basically, you can't, at least not with the current release. True, you cannot emulate all the features. The one feature you can emulate, given some assumptions, is the WNOHANG flag. The emulation uses the (incompletely documented) semantics of the SIGCLD signal; when a handler is installed for SIGCLD, if there are any zombie children, a SIGCLD signal is immediately generated. Thus the following untested code more-or-less does the job. It will not work if there are other signal handlers that might be asynchronously doing forks and waits, but that is likely to apply to any use of wait or wait3. It may cause spurious SIGCLD signals if the user has another handler installed for that signal and there are multiple zombies when wait3 is called; a program expecting BSD SIGCHLD semantics probably won't be bothered by this, while one expecting SysV SIGCLD semantics wouldn't want the wait3 emulation. Credit for this idea goes to Dave Korn. If you want, you can emulate the ru_stime and ru_utime fields of the rusage with calls to times() before and after wait(). int caught_sig; catch_sigcld() { caught_sig = 1; } int wait3 (status, flags, rusage) int *status, flags; void *rusage; /* can't really emulate this */ { int (*oldhandler)(); int return_val; if (rusage != 0) /* probably an error */ if (flags & WNOHANG) { caught_sig = 0; oldhandler = signal (SIGCLD, catch_sigcld); } if (!(flags & WNOHANG) || caught_sig) return_val = wait (status); else return_val = 0; if (flags & WNOHANG) (void) signal (SIGCLD, oldhandler); return (return_val); } Bob Lenk {ihnp4, hplabs}!hpfcla!rml