fork on uClinux

Carlos Manuel Duclos Vergara carlos at
Sat May 27 07:23:58 UTC 2006

> No, it's not ok! The two copies will be written sequentially one after
> the other, not over top of each other! This is obvious for non-
> seekable file descriptors.
> If you don't believe me on this, look it up! But it's well-known that
> it's dangerous to flush streams in both the parent and child process
> after a fork!

I think we're talking about the same thing but in two different instances. I 
refer to different processes writing to a same file. You're talking about 
forked processes BEFORE calling execve & friends. 
The typical situation is:

pid = fork()
if(pid < 0 )
else if(pid == 0) // child
	dup2(fd, 0);
} else { // father

so you can have a simple way to redirect the standard input of the child 
process (inetd uses this mechanism).
If you flush after a fork() and before calling execve & friends there are the 
same risks than any situation in which shared data is used, but I don't think 
that taking that into account the situation will become unmanageable.


More information about the uClibc mailing list