fork() and close()
Peter Eriksson
pen at lysator.liu.se
Thu Oct 18 06:11:59 AEST 1990
I'm experiencing some strange things with the code segment below. I have to
add the call to usleep() (or use semaphore signalling from the child to the
parent) in order to have the 'fd' available in the child. Apparently something
goes wrong if I close it too fast in the parent. I just don't understand why
this is so. Any suggestions?
fd = accept(...);
if (fork())
{
/* usleep(100000); */
close(fd);
return;
}
dup2(fd, 0);
execl(...);
And, is there any portable way to code a wait in the parent to be sure
that the child has begun executing? (I'm using SysV semaphores right now,
which works real nice, but how common are those? How many versions of
Unix has those in the kernel "by default"?)
--
Peter Eriksson pen at lysator.liu.se
Lysator Computer Club ...!uunet!lysator.liu.se!pen
University of Linkoping, Sweden "Seize the day!"
More information about the Comp.unix.internals
mailing list