How to make child of failed fork exit cleanly?
Corinna Vinschen
corinna-cygwin@cygwin.com
Tue May 3 18:42:00 GMT 2011
On May 3 11:46, Ryan Johnson wrote:
> Hi all,
>
> I'm working on some changes to fork() which would detect early the
> case where a parent-child pair have unresolvable differences in
> address space layout (e.g. thread stacks, heaps, or
> statically-linked dlls which moved).
>
> Detecting the problem turned out to be pretty easy, but making the
> child exit cleanly is not. This leads to two questions, followed by
> what I have figured out so far while attempting to answer them
> myself.
>
> 1. What's the best way to make a child process notify the parent
> that the fork() cannot succeed, and exit cleanly?
Usually by using some helpful status code which then can be recognized
by child_info::proc_retry.
> Context for the first question: Existing fork failure code calls
> api_fatal(), but that sends messages to the terminal and generates a
> stack trace, in addition to the desired result of making the
> parent's fork() call return an error message. Further, Windows 7
> treats such an exit as grounds for an automatic process restart, and
> respawns the failed child up to five more times before giving up.
That's not Windows 7, it's Cygwin itself. See child_info::retry_count
and child_info::proc_retry.
> Given that the cause of the fork failure is known (rather than some
> surprise or bug), I propose that the messages go to some strace
> channel (a new one for fork, perhaps?) and that the child exit
> without attempting to generate a dump file (especially since dump
Sounds ok to me, if you're really sure that the situation is not
recoverable.
> generation itself has a tendency to cause crashes). It would also be
> good, in cases where the parent is the reason for fork failures, to
> prevent Windows from respawning the process so many times (though it
> is admittedly handy when the child was the problem and the fork
> succeeds on the nth try).
See above. That's handled in child_info::proc_retry.
> All of this still leaves the question of
> how to exit the child process, "properly" though. Is it necessary to
> wait for dll initialization to finish first, for example?
I'm not sure I understand the question. How do you know which
DLL is already initialized and which isn't?
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
More information about the Cygwin-developers
mailing list