New? idea
John Quarterman
jsq at ut-sally.UUCP
Tue Jan 17 04:43:35 AEST 1984
x
From: chris at umcp-cs.UUCP
Subject: New? idea
Message-ID: <4771 at umcp-cs.UUCP>
Date: Sun, 15-Jan-84 17:43:17 CST
Something that network servers often do is
while ((netfd = netopen ()) >= 0) {
if ((pid = fork ()) == 0) {
if (fork ())
exit (0);
workhorse ();
exit (0);
}
close (netfd);
}
The purpose of the double-fork is to "disown" the actual worker and
let the server continue to accept network connections. Without the
"disownment", when the "workhorse" finishes and exit()s, it hangs around
forever taking up a process slot, just so that it can return its status
to its parent. But the server doesn't care, ergo the double-fork-be-
inherited-by-init trick.
So, my suggestion is a "disown" system call, to allow parents to give
up their children so that on exit they will vanish without a trace.
Does anyone know why this should not be implemented (other than because
you can do it without this)? Alternatively, does anyone have better
ideas?
That's called a spawn. For it to work correctly, you need to have a wait:
while ((netfd = netopen ()) >= 0) {
if ((pid = fork ()) == 0) {
if (fork ())
exit (0);
workhorse ();
exit (0);
}
wait (0); /* clean up child, leave granchild */
close (netfd);
}
and some error checking and fork retrying is quite useful in practice.
I prefer SIGCHLD, myself. It's too bad select wasn't made general enough
to allow selecting on dead or stopped processes as well as file and socket
conditions.
--
John Quarterman, CS Dept., University of Texas, Austin, Texas
{ihnp4,seismo,ctvax}!ut-sally!jsq, jsq at ut-sally.{ARPA,UUCP}
More information about the Comp.unix.wizards
mailing list