Getting rid of a <defunct> process

JD Allen jamesa at arabian.Sun.COM
Mon Feb 13 10:51:14 AEST 1989


In article <102 at avatar.UUCP>, kory at avatar.UUCP (Kory Hamzeh) writes:
> 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 "<defunct>" processes in the process table when the child
> exits.

	Simply replace:

		if (fork() == 0)
			run_child_code();

	With a lintable version of:

		if (fork() == 0)
			fork() ? _exit() : run_child_code();
		else
			wait(0);	/* reap the "dummy" process */

	When your orphaned grandchild exits it will now be reaped by the Grim
	Reaper.  "Bastards" don't become "zombies".  (Holy metaphor, Batman!)

	(On the other hand, "morally", if a process is worth running, its exit
	status is worth inspecting.  You can get it "asynchronously" with
	SIGCHLD and/or wait3().)

	-- James Allen



More information about the Comp.unix.wizards mailing list