Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Tue, 11 Jan 2005 14:29:08 -0500 From: Jason Tishler To: cygwin AT cygwin DOT com Subject: Re: popen() fails while system() works Message-ID: <20050111192908.GA388@tishler.net> Mail-Followup-To: cygwin AT cygwin DOT com References: <20050105100830 DOT GB5240 AT cygbert DOT vinschen DOT de> <30305 DOT 193 DOT 16 DOT 155 DOT 145 DOT 1104926914 DOT squirrel AT 193 DOT 16 DOT 155 DOT 145> <20050105124336 DOT GA6515 AT cygbert DOT vinschen DOT de> <20050105150204 DOT GA1068 AT tishler DOT net> <20050111121830 DOT GA1128 AT tishler DOT net> <36895 DOT 193 DOT 16 DOT 155 DOT 145 DOT 1105449682 DOT squirrel AT 193 DOT 16 DOT 155 DOT 145> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline In-Reply-To: <36895.193.16.155.145.1105449682.squirrel@193.16.155.145> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Jan 11, 2005 at 02:21:22PM +0100, Rainer Hochreiter wrote: > > On Mon, Jan 10, 2005 at 08:56:58AM +0100, Rainer Hochreiter wrote: > >> but what's the real reason why popen() results in the address > >> conflict and system() does not?! > > > > AFAICT, popen() calls fork() and system() does not. > > this is not true - both functions call vfork()! > > cygwin-1.5.12-1/newlib/libc/stdlib/system.c:165 if ((pid = vfork ()) == 0) AFAICT, Cygwin's system() is implemented in: winsup/cygwin/syscalls.cc > system() calls execve() while popen() calls execl() to start execution > of another file! Nevertheless, the above is not quite right. fork() is called, but the call occurs in sh *not* the original application. See the attached testcase, st.c, and the following strace snippets: $ strace st | egrep '(Program name| fork):' Program name: c:\home\jtishler\src\c++\st.exe (2788) Program name: C:\cygwin\bin\sh.exe (928) 227 17561 [main] sh 928 fork: entering Program name: C:\cygwin\bin\sh.exe (4948) 199 42119 [main] sh 928 fork: 4948 = fork() 151 43337 [main] sh 4948 fork: 0 = fork() Program name: C:\cygwin\bin\id.exe (4948) This is why system() does not trigger the base address conflict problem and popen() does. Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="st.c" #include int main() { system("id"); return 0; } --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --vtzGhvizbBRQ85DL--