Mail Archives: cygwin/2009/01/15/12:12:18
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 -