From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13041 invoked by alias); 15 Jan 2009 13:06:41 -0000 Received: (qmail 13032 invoked by uid 22791); 15 Jan 2009 13:06:40 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_SOFTFAIL X-Spam-Check-By: sourceware.org Received: from qmta07.emeryville.ca.mail.comcast.net (HELO QMTA07.emeryville.ca.mail.comcast.net) (76.96.30.64) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 15 Jan 2009 13:06:03 +0000 Received: from OMTA10.emeryville.ca.mail.comcast.net ([76.96.30.28]) by QMTA07.emeryville.ca.mail.comcast.net with comcast id 3oR21b0050cQ2SLA7p62av; Thu, 15 Jan 2009 13:06:02 +0000 Received: from [192.168.0.101] ([67.166.125.73]) by OMTA10.emeryville.ca.mail.comcast.net with comcast id 3p601b0021b8C2B8Wp60wT; Thu, 15 Jan 2009 13:06:02 +0000 Message-ID: <496F34BB.6080200@byu.net> Date: Thu, 15 Jan 2009 15:41:00 -0000 From: Eric Blake User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: cygwin@cygwin.com, len1@bodz.net Subject: Re: Bash doesn't launch the applications directly. References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-01/txt/msg00464.txt.bz2 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Lenik on 1/14/2009 5:59 PM: > Hi, all > > I noticed that when bash launches a program, for example win32 > notepad.exe or cygwin sleep, it in fact launches another bash which > launches the final program, > > Any idea? Yes. It's called forking (a concept that Windows does not have natively, but which cygwin does a LOT of work to emulate). The way Unix apps (including bash) start another program is to first fork themselves, then in that fork, exec the target program. The fork accounts for the second bash process. Depending on the nature of the called process, you might also see those additional processes stick around. If the child is a cygwin process (like sleep), exec() is decently emulated, where the forked bash goes away and you are left with only one running sleep process. But if it is a windows process (like notepad), cygwin has to insert a shim process in between to handle signal handling in order to abort notepad if you type ctrl-c in bash, as well as collect the correct exit status. Ultimately, bash could be made faster by using posix_spawn() instead of fork(), for much of what it does. However, that would require 1) an upstream patch to bash to use posix_spawn(), including a fallback implementation of posix_spawn on platforms that don't yet implement it (such an implementation is possible, since gnulib already provides one, but the upstream maintainer is hard to convince, and even if the patch existed, it has already missed the bash 4.0 cutoff), and 2) an implementation of posix_spawn() in cygwin that directly spawns processes using native Windows concepts (the bash fallback implementation of posix_spawn() would still end up using fork() under the hood, giving no speedups until we have a native version). http://cygwin.com/acronyms/#PTC - -- Don't work too hard, make some time for fun as well! Eric Blake ebb9@byu.net volunteer cygwin bash maintainer -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAklvNLsACgkQ84KuGfSFAYBp7wCfdPswFfp5U+1fsNAU2cIRDwGF UGsAoLhOPK3JdM/E61ruig0Ji5a1yJkY =C9qK -----END PGP SIGNATURE----- -- 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/