Xref: utzoo comp.unix.questions:11703 comp.unix.wizards:14698 comp.unix.xenix:4972 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!pasteur!ucbvax!decwrl!decvax!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.unix.questions,comp.unix.wizards,comp.unix.xenix Subject: Re: Getting rid of a process Message-ID: <425@lakart.UUCP> Date: 13 Feb 89 23:14:02 GMT References: <102@avatar.UUCP> Distribution: usa Organization: Lakart Corporation, Newton, MA Lines: 41 From article <102@avatar.UUCP>, by kory@avatar.UUCP (Kory Hamzeh): > I have written an application which forks and execs off many subtasks. > The main process (the parent which does all of the forks) can not > do a wait() because I can't get blocked for anything. Well, this results > in a lot of "" processes in the process table when the child > exits. This may provide a workable solution, but there is a disadvantage: It will slow down the fork process, because two fork calls are required instead of 1. However, that may or may not be an issue. You may need to muck with the calling parameters passed to forknew, I've assumed useage of execv() - modify as appropriate for whatever you're using. forknew(prog, argv) char *prog, **argv; { int pid1, pid2; if (fork() != 0) /* parent */ { wait(&pid1); /* wait for child */ return; /* and carry on */ } if (fork() != 0) /* child forks AGAIN, */ exit(0); /* child exits, so parent's wait() * doesn't block */ execv(prog, argv); /* grandchild actually does the execv, but * since it has no parent it gets inherited * by init (PID 1) which will detect it's * passing, and do a wait */ } This works on BSD, but may well work on other systems Comments anyone? -- dg@lakart.UUCP - David Goodenough +---+ IHS | +-+-+ ....... !harvard!xait!lakart!dg +-+-+ | AKA: dg%lakart.uucp@xait.xerox.com +---+