Path: utzoo!utgpu!cunews!dgbt!netfs.dnd.ca!rutgers!usc!samsung!uunet!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: fork question Message-ID: <1991Feb6.204637.5927@athena.mit.edu> Date: 6 Feb 91 20:46:37 GMT References: Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 29 When you run fork(), the child process that results from the fork() has the same open file descriptors (except for the ones that are set to close-on-exec) as the parent process. When you use back-quote command evaluation in the shell, the shell keeps reading on the stdout file descriptor of the process it calls, until it gets EOF on that file descriptor. The shell won't get EOF on the file descriptor until *all* processes that have the other end of the file descriptor open have closed it (or exited and implicitly closed it). Therefore, although your parent process exits, the shell continues to wait for output, because the child process still has stdout open, so the shell does not get an EOF. The easiest way to fix this is to close stdout and reopen /dev/null or something on top of it in the child process. If you need to output stuff to stdout in the child, you'll have to come up with something more creative, like opening /dev/tty for write after closing stdout, or dup'ing stderr's file descriptor onto stdout, or something like that. Deciding exactly how to get back a stdout to write to depends on exactly what your program does. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710