Page 1 of 1

fork in linux?

Posted: Fri Dec 26, 2008 12:33 pm
by yemista
Does anyone know why linux uses calls to fork to create new processes? Whats the advantage
of that over just creating a new process data structure and filling out the information? this is how I intend to do it in a multi-process OS im working on for fun and learning, but would it be better to try to go ahead and use the fork method?

Re: fork in linux?

Posted: Fri Dec 26, 2008 12:48 pm
by Love4Boobies
Most implementations of fork() create a new process with the same pages the parent process has; copies of these are only made on write. It's a nice technique to save memory because child processes use code and data from their parent process more often than you'd think and the overhead is so small (for creating a PCB and then replacing it) that there is more to gain.

Re: fork in linux?

Posted: Fri Dec 26, 2008 1:16 pm
by yemista
But if you plan to only have processes be single, small user programs, its ok not to bother to fork? Ideally, my OS will consist of a shell that runs user programs from disk through a prompt.

Re: fork in linux?

Posted: Fri Dec 26, 2008 2:10 pm
by Love4Boobies
It's okay either way. The fork() technique gives you better performance in some cases.