Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!rutgers!cmcl2!uupsi!sunic!liuida!isy!lysator.liu.se!pen From: pen@lysator.liu.se (Peter Eriksson) Newsgroups: comp.unix.internals Subject: fork() and close() Message-ID: <364@lysator.liu.se> Date: 17 Oct 90 20:11:59 GMT Sender: news@isy.liu.se (Lord of the News) Distribution: comp Organization: Lysator Computer Club, Linkoping University, Sweden Lines: 27 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@lysator.liu.se Lysator Computer Club ...!uunet!lysator.liu.se!pen University of Linkoping, Sweden "Seize the day!"