Problem with fork/exec/setsid/fgets (was: cygwin_attach_handle_to_fd())

Craig Nelson craig@reversion.ca
Tue Jun 5 08:51:00 GMT 2001


Christopher Faylor wrote:

> As usual, "loads of grief" is not an adequate bug report.  You probably
> don't think you're providing a bug report, but you are.  Cygwin is supposed
> to be a UNIX emulation package.  If you can't use fork/exec for some reason
> then that's a serious problem.
>
> >I've switched to using CreateProcess() and the grief goes away (except
> >for this little problem I'm having here).  I'll try some new things
> >here and post my findings..

OKAY you're right.  rather than try to write a whole new 250 lines of code using CreateProcess() to get around
a single problem, I should really get to work on finding the fork/exec problem in the first place.

Here goes:

I reduced my code to the smallest program possible with the same functionality.  here is the test case:
A program which uses fork(), exec(), AND fgets() and setsid(), will hang after two children have been produced.

Run the attached program and press return twice.  you will see the output of "dir.exe" twice.  press return again.  now you get
nothing.  commenting out the "#define TEST_USE_FGETS" and / or "#define TEST_USE_SETSID" will allow the program
to run without error.  (note that when not defining TEST_USE_FGETS that the program just creates one child at a time forever)


I am running the latest cygwin (1.3.2) on an PIII 400Mhz WinNTsp6a box.  The workaround here is to quit using setsid(), but that does
have some implications...

Any help would be greatly appreciated.  I've looked at the cygwin source code but do not feel I would be capable of coming up with
and accurate diagnosis of the cygwin internals..

Thanks,
Craig Nelson, Cameo Systems Inc.



More information about the Cygwin mailing list