fork on uClinux
Carlos Manuel Duclos Vergara
carlos at embedded.cl
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 )
error....
else if(pid == 0) // child
{
close(0);
dup2(fd, 0);
exec(...);
} else { // father
close(fd);
}
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.
--
http://toolchains.com/personal/blog
More information about the uClibc
mailing list