Path: utzoo!mnetor!uunet!husc6!uwvax!dave@spool.wisc.edu From: dave@spool.wisc.edu (Dave Cohrs) Newsgroups: comp.unix.wizards Subject: Re: Is processalive? Message-ID: <4846@spool.wisc.edu> Date: 10 Dec 87 15:52:57 GMT References: <1454@rtech.UUCP> <1921@munnari.oz> <429@minya.UUCP> Sender: news@spool.wisc.edu Reply-To: dave@spool.wisc.edu (Dave Cohrs) Organization: U of Wisconsin CS Dept Lines: 27 In article <429@minya.UUCP> jc@minya.UUCP (John Chambers) writes: >Is there a universal way that will work on any Unix to write a function > isprocess(n) >which returns TRUE if process n is alive, and FALSE if it isn't alive? Any Unix? Well, if the Unix acts like either 4.3BSD or SysV, the following should work: int isprocess(n) int n; { extern int errno; return (kill(n,0) == 0 || errno != ESRCH); } If you read the 4.3BSD kill(2) man page, you see that kill still does permission checks, so you have to check errno upon return to make sure that the error isn't EPERM, meaning the process is alive, but you can't send it signals. This works on SysV as well. I tested it. Dave Cohrs +1 608 262-6617 UW-Madison Computer Sciences Department dave@cs.wisc.edu ...!{harvard,ihnp4,rutgers,ucbvax}!uwvax!dave