This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash doesn't launch the applications directly.

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

- --
Don't work too hard, make some time for fun as well!

Eric Blake   
volunteer cygwin bash maintainer
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at
Comment: Using GnuPG with Mozilla -


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]