UNIX question

Al Brumm ahb at ccice5.UUCP
Thu Dec 12 09:49:00 AEST 1985


In article <156 at uw-june> pjs at uw-june (Philip J. Schneider) writes:
>My question: Is there any way to kill off these zombies so I can get
>	     more processes ?  Or, failing that, is there any other
>	     way to do what I want ?

A clean way to handle this problem on Sys3 was to use the following
system call in the parent process:
	signal(SIGCLD, SIG_IGN);

Then when a child process exited, a zombie would not be created.
Note that this would not allow you to examine the child's exit
status.  However, you could examine the exit status by doing the 
following:
	int
	sigcld()
	{
		int pid, status;
		pid = wait(&status);
		.
		. (do stuff)
		.
	}
	main()
	{
		int	(*sigcld)();

		signal(SIGCLD, sigcld);
	}

The example immediately above is also possible in 4.2BSD,
only SIGCLD is called SIGCHLD.

Then again, there is always the double fork() trick which goes
something like this:
	if (fork()) {			/* parent */
		wait((int *)0);		/* no zombies please */
	}
	else {
		if (fork()) {		/* child */
			exit(0);	/* satisfy parent's wait */
		}
		else {			/* grandchild */
			do_stuff();		/* since my parent exit'ed */
			.			/* I am inherited by init */
			.
			.
		}
	}
The above trick is used quite heavily by the UNET servers.



More information about the Comp.unix mailing list