fork in linux?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

fork in linux?

Post 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?
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: fork in linux?

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: fork in linux?

Post 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.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: fork in linux?

Post by Love4Boobies »

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 ]
Post Reply