Sent on behalf of William Case: From: William Case <billlinux@xxxxxxxxxx> Date: Sat, May 24, 2008 at 11:26 PM Subject: fork and exec Hi; I have a fundamental question about why Linux/Unix uses the parent and child modal to start and run new processes. I am having trouble making my question understood. I tried to get an explanation from members of my local LUG who are usually quite responsive and helpful. My question was met with some defensiveness as if I was challenging the basic way that *nixes do things. I couldn't seem to get past answers that told me how fork() and exec() work to why things are done that way. So ... I will try my question here: Quoting from http://en.wikipedia.org/wiki/Fork_%28operating_system%29 "Under Unix and Unix-like operating systems, the parent and the child operations are selected by examining the return value of the fork() system call. ...", and, "The fork operation creates a separate address space for the child. The child process has an exact copy of all the memory segments of the parent process ... ", and, "More generally, forking is also performed by the shell each time a user issues a command. A child process is created by forking the shell, and the child process is overlaid, once again by exec, with the code associated with the program to be executed." I understand the mechanics of how this works. Several manuals, texts and Wikipedia give very clear examples. To further quote that section of Wikipedia: "Forking is an important part of Unix, critical to the support of its design philosophy, which encourages the development of filters. In Unix, a filter is a small program that reads its input from stdin, and writes its output to stdout." My question is: Why did the original designers of Multics/Unix choose to use the forking modal to start a new processes? Do not other OSs use other modals? What problem(s) did the fork overcome? Couldn't a system have been designed that just (in some way) starts each process raw? Intuitively, copying a process then overwriting it seems wasteful or at least inelegant, so why is it needed? How does a parent-to-child process enhance its (*nix's) design philosophy? Since forking is at the very core of the kernel, I would like to understand intellectually why the fork process is necessary? I am not being argumentative, or trolling, or proposing something different or better. Although relatively new to kernel programming and 'C' I am not a complete newbie. I would just like to see in my minds-eye what is going on and *why*. -- Regards Bill -- Regards, Peter Teoh -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ