delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/01/11/14:29:19

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <jason AT tishler DOT net>
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: <pan DOT 2005 DOT 01 DOT 05 DOT 09 DOT 19 DOT 22 DOT 647025 AT hochreiter DOT at> <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> <pan DOT 2005 DOT 01 DOT 10 DOT 07 DOT 56 DOT 56 DOT 382605 AT hochreiter DOT at> <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
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 <stdlib.h>

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--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019