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?
fork in linux?
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: fork in linux?
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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: fork in linux?
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.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: fork in linux?
It's okay either way. The fork() technique gives you better performance in some cases.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]