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: Cygwin parenting issue


Hi Norton,

I've only just grabbed the cygwin source code very recently out of desperation to try to solve a different problem that I'm experiencing, so I'm definitely no expert.

However, in the source is a file called "how-spawn-works.txt", which does have a disclaimer at the top:

(THIS DESCRIPTION IS OUT-OF-DATE)

However, what it does say is:

* if the mode is _P_OVERLAY (we are doing an exec)
wait for the child to
a) if it's a cygwin process, signal us via an event.
b) if it's a win32 process, exit.
c) exit.

And, from what I can tell, that's what the new code still does. i.e. it is a new process being created, because the Windows API doesn't have an equivalent to the POSIX exec() type functionality. So... your executed programme (i.e. parent) is not simply replacing the bash executable within the same Windows process - it is actually inside a child process.

Having said that, given that cygwin manages its own pids, I think it should be able to simulate the waitpid() functionality within the concept of an exec.

For example, I did notice this bit of code:

      cygpid = (mode != _P_OVERLAY) ? create_cygwin_pid () : myself->pid;

So clearly it is trying to preserve the same pid. I'd have to dig much deeper into the code to try to work out why waitpid() is not doing what you want, but perhaps there is someone else who already has that knowledge ?

Dave

On 2/01/2020 08:01, Norton Allen wrote:
I have a project that involves starting a number of programs in the background and then monitoring and reporting when they terminate. My approach has been to write a small application called 'parent' that loops on waitpid() until there are no more children. I invoke it in a script like:

#! /bin/bash
program1 &
program2 &
program3 &
exec parent

This of course works under Linux, but under Cygwin, although 'ps' documents the parent/child relationship, waitpid() immediately returns ECHILD, indicating there are no child processes. If I use the shell's waitpid, that works alright, so I am wondering whether the problem is a casualty of the exec.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


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