Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!rex!uflorida!mlb.semi.harris.com!trantor.harris-atd.com!trantor!chuck From: chuck@trantor.harris-atd.com (Chuck Musciano) Newsgroups: comp.unix.questions Subject: Reopening stdin Message-ID: <5200@trantor.harris-atd.com> Date: 7 Jan 91 17:46:13 GMT Sender: news@trantor.harris-atd.com Reply-To: chuck@trantor.harris-atd.com (Chuck Musciano) Organization: Advanced Technology Dept, Harris Corp, Melbourne, FL Lines: 27 Environment: Sun-3/60 running SunOS 4.1 I have a program which at one point forks itself. The child, in turn, calls system() to run a command. In the child, I would like to reopen stdin to point to a particular file. To do this, I call open() and dup2() before calling system(). Here is the strange behavior. If the parent has at some point closed its stdin, the command that the child invokes with system() terminates with "stdin: bad file number". If the parent does not close its stdin, all works fine. The close of stdin occurs before the child is forked. My question: what unusual behavior occurs when you close stdin such that your children cannot successfully dup2() into it and fork again (via system()). The trivial solution is to never close stdin in the parent, but my curiosity has been piqued by this odd behavior. Any insight on this? -- Chuck Musciano ARPA : chuck@trantor.harris-atd.com Harris Corporation Usenet: ...!uunet!x102a!trantor!chuck PO Box 37, MS 3A/1912 AT&T : (407) 727-6131 Melbourne, FL 32902 FAX : (407) 729-2537 A good newspaper is never good enough, but a lousy newspaper is a joy forever. -- Garrison Keillor