delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/01/15/12:12:18

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <5a05e0e60901150911i3caa5b66gef6c61d8a6e2ef7d@mail.gmail.com>
Date: Thu, 15 Jan 2009 12:11:30 -0500
From: "Dave Steenburgh" <dave DOT steenburgh AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Bash doesn't launch the applications directly.
In-Reply-To: <496F34BB.6080200@byu.net>
MIME-Version: 1.0
References: <gkm1pc$717$1 AT ger DOT gmane DOT org> <496F34BB DOT 6080200 AT byu DOT net>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
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

On Thu, Jan 15, 2009 at 8:06 AM, Eric Blake <ebb9 AT byu DOT net> wrote:
> 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.

Well, now I understand why I occasionally see more instances of bash
in the task manager than I was expecting.  However, now I have to ask
why the shim doesn't appear [plainly] with ps:

     4540       1    4540       4540    0 1003 11:48:08 /usr/bin/bash
     5656    4540    5656       4756    0 1003 11:48:35
/cygdrive/f/WINDOWS/system32/notepad

5656 is the PID of the shim, and 4756 is the PID of notepad.  I'm
extrapolating here, so correct me if I'm wrong: whenever the WINPID
column is different from the PID column, there's a shim process?  The
task manager displays both, because they are after all separate
processes.  Personally, I'd rather see one entry for each process than
have to notice when PID and WINPID are different.  Out of curiosity,
what would ps show if somehow the shim was left running long after
notepad had exited?  Would you still see notepad, or would there be no
entry at all, or would the shim then be in plain sight?

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

- Raw text -


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