Path: utzoo!attcan!uunet!dptechno!dave From: dave@dptechno.UUCP (Dave Lee) Newsgroups: comp.sys.hp Subject: Re: fork()/exit() dumps core Message-ID: <555@dptechno.UUCP> Date: 13 Aug 90 15:36:38 GMT References: <5768@hplabsz.HPL.HP.COM> Reply-To: dave@dptechno.UUCP (Dave Lee) Organization: D.P. Technology Corp. Camarillo California Lines: 51 In article <5768@hplabsz.HPL.HP.COM> mayer@hplabs.hp.com (Niels Mayer) writes: >In article roger@zuken.co.jp (Roger Meunier) writes: >>When a C++ program exits, it calls a list of destructors to clean up >>static data. But what happens when exit() is called after fork()? > > pid_t pid; > if((pid = vfork()) == 0) > { > for(i=3;i<_NFILE;i++) /* close all fd except stdin, stdout, and stderr */ > close(i); > ... > } > >As to why the X implementation doesn't set the close-on-exec flag via >fcntl() to prevent this problem, only the experts know. > >Does anybody have a public domain (or non-restrictive-copyright) version of >popen() and system() that you'd be interested in sharing??? > >Actually, system() is easy... But I'm too lazy to go figure out how to do >popen() without sullying the pristine "clean-room" environment of my mind. A cleaner way to handle the above problems (if indeed they are due to the open fd from a display connection) is ... #include fcntl( DISPLAY_PTR , F_SETFD , 1 ); Where "DISPLAY_PTR" is a pointer to the open Display from XOpenDisplay(); Insert this just after opening the display, or before doing any system() popen(), or fork()/exec. This should then remove the need to recode system() or popen() from scratch. # # # # # # -- Dave Lee uunet!dptechno!dave