This is the mail archive of the
mailing list for the Cygwin project.
Re: Broken since 1.3.10, or earlier
On Tue, Jul 16, 2002 at 05:00:38PM -0700, Randall R Schulz wrote:
>Someone who knows about the internal architecture of I/O processing in
>Cygwin might be able to shed some light on this. If, for example, there's
>some kind of queuing of I/O operations in Cygwin1.dll between the
>application code (grep or a shell, in this case) and the Windows I/O
>primitives, then there might be an opportunity for this kind of asynchrony.
Actually, AFAICT, it is a bash bug and one that I have reported earlier.
bash makes assumptions that pids grow monotonically but that is not the
case on windows. It's possible that you can run a program twice and get
the same pid twice in a row -- especially on Windows 9x. I try to work
around this in cygwin by keeping a certain number of process handles
open, so that the pids won't be reused, but that still causes problems
when you are fork/execing processes quickly.
What happens is that sometimes bash ends up not waiting for a process when
it should, starting the next process too early.
For instance, look at the following from an strace that shows the problem:
881 11112361 [main] bash 1304 fork: *1288* = fork()
979 11854415 [main] bash 1304 fork: 1120 = fork()
895 12550685 [main] bash 1304 fork: 1648 = fork()
947 13188885 [main] bash 1304 fork: 340 = fork()
1103 13843029 [main] bash 1304 fork: 1484 = fork()
950 14440217 [main] bash 1304 fork: 1560 = fork()
880 15097448 [main] bash 1304 fork: 1144 = fork()
931 15761062 [main] bash 1304 fork: 1620 = fork()
1191 16484221 [main] bash 1304 fork: 864 = fork()
902 17124502 [main] bash 1304 fork: 1548 = fork()
825 17815402 [main] bash 1304 fork: 1280 = fork()
968 18421987 [main] bash 1304 fork: *1288* = fork()
Guess where the output goes funny? Right after the second fork which
results in a pid of 1288.
I "fixed" this problem in my version of cygwin by upping the number of
process handles that fork keeps open from 8 to 128. This reduces, but
doesn't eliminate, the likelihood that bash will be confused by
repeating pids. When I did this, I get the expected output.
This isn't really a solution, however. It wastes resources by keeping
*a lot* of handles around so I'm not comfortable with upping the number
If you want to use this method, then run it under /bin/sh or /bin/zsh.
Neither of these programs seem to have this bug.
Oh, and as far as the "or earlier" part of cygwin goes, I tried this
back to 1.1.8. It behaves the same way. Of course, this wouldn't have
been a problem with B20.1 since that version of cygwin invented its own
pids rather than using windows pids. Back then people were asking for
cygwin to use actual windows pids, of course.
>It's too bad strace cannot solve this one,
Actually strace did solve this one.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html