Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!killer!texbell!sugar!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.unix.questions Subject: Re: Avoiding processes on Ultrix Message-ID: <3772@ficc.uu.net> Date: 9 Apr 89 15:08:09 GMT References: <520@pan.UUCP> Organization: Xenix Support Lines: 40 The following should help. The returned PID is bogus, but you didn't care for it anyway, right? I can't return the real pid easily, since exit eats 8 bits of the return value. dfork() /* Fork and detach, so you can run stuff from a daemon */ { int pid, status; switch(pid==fork()) { /* Create a sacrificial child */ case -1: /* Failure */ return -1; /* return error code */ default: /* In parent */ while(wait(&status) != pid) /* find child */ continue; if(status) return -1;/* error, assume fork failed */ else return pid;/* fork succeeded -- PID BOGUS */ case 0: /* In sacrificial child */ switch(fork()) { case -1: /* fork failed, tell boss */ exit 1; case 0: /* return in child */ return 0; default: /* fork succeeds, tell boss */ exit 0; /* And sacrifice child to daemon */ } } } -- Peter da Silva, Xenix Support, Ferranti International Controls Corporation. Business: uunet.uu.net!ficc!peter, peter@ficc.uu.net, +1 713 274 5180. Personal: ...!texbell!sugar!peter, peter@sugar.hackercorp.com.