On Jun 18, 2006, at 9:51 AM, Christian Heller wrote:

> Questions:
>
> 1 Do I have to deallocate all duplicated resources in the child  
> process,
>   right after the "fork" and before running an "exec"?
>   (The new child process runs an external program that does not  
> need them.)

The short answer is that if you perform an exec (of some variety)  
immediately after the fork, you're okay. As a matter of history,  
early versions of Unix did implement fork by creating a copy of the  
process, but this was really overkill for situation where you were  
only going to do an immediate exec, so a different call, named vfork  
was introduced to get around the problem of unnecessary resource  
allocation and de-allocation. But with modern kernels, this is no  
longer necessary, and calling fork does not carry any extra overhead.  
I've always thought it sounded like a curious way to create new  
processes, but if you think of fork as being part of an abstract  
model it makes a bit more sense. It sounds very much like something  
that a mathematician or computer scientist (who is primarily  
concerned with constructing correct proofs, not with writing code in  
a natural or efficient way) might come up with. By the way, I say  
this as someone who leans very much in the direction of computer  
science and mathematics.

>
> 2 Or, can I leave the duplicated resources just not paying attention
>   while the new child process is running and assuming that the "exit"
>   call of the child process will properly deallocate duplicated  
> resources?

Yes, with the caveat given above (you should call exec/execv/execve  
immediately).
>
> 3 Isn't there a simpler way of starting an external program?
>   I cannot imagine that a desktop environment like KDE, for example,
>   starts applications with "fork" which copies all resources every  
> time,
>   only to destroy them right after, if the application does not  
> need them.

The simplest way to start an external program is system (try man  
system) but it goes through an external shell. You can also write  
your own function to implement the usual fork/exec/wait incantation.

Gregory Woodhouse
[EMAIL PROTECTED]

"Judge a man by his questions not
his answers."   --Voltaire





[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Yahoo! Groups gets a make over. See the new email design.
http://us.click.yahoo.com/XISQkA/lOaOAA/yQLSAA/W4wwlB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/openhealth/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to