You are not logged in.

#1 2009-05-23 17:16:45

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

[solved: answer=yes] Can child processes fork()?

As an exercise, I've been wanting to design a shell with better string-handling capabilities than bash — get around the quote-escaping problem, etc. But before I continue, I need to know: are fork()-ed child processes allowed to themselves fork()?

I ask because shells execute commands by fork()-exec(). But you start a subshell to a script? It then has to fork()-exec() the commands therein on its own...

It seems like this wouldn't work because in the child process, fork() returns 0. Or is this only for the fork() call that created it?

Last edited by Peasantoid (2009-05-23 18:11:35)

Offline

#2 2009-05-23 17:35:09

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [solved: answer=yes] Can child processes fork()?

They can. Daemons for example do this, and they simply use a structure like if fork() == 0 { if fork() == 0 { daemon_main() ; } EXIT* }

*EDIT

Last edited by Procyon (2009-05-23 17:36:47)

Offline

#3 2009-05-23 18:11:10

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: [solved: answer=yes] Can child processes fork()?

Ah, thank you.

Offline

Board footer

Powered by FluxBB