Hi,

Let me introduce a bit. I'm working on porting busybox's ash shell to
Windows as part of an attempt to bring Git to Windows without MSYS or
Cygwin dependency. I knew from Git mailing list you guys were Windows
FLOSS experts. So please help this poor FLOSS developer :-)

I concern about Windows pipe behavior. I make a pipe to connect two
programs together. The first program feeds the second  one. Things
worked fine until I found that if the second one dies soon, the first
one won't notice and keep feeding the pipe until it blocks itself.

I attach three programs to demonstrate that. a.c is the feeder. b.c is
the consumer (it actually does not consume anything, just dies out).
c.c is the one that connects a and b together.  You run c.exe, then
look at file "o" or process list. In a perfect world, a.exe should
exit and we should get 999 in "o".

Did I make anything wrong?
-- 
Duy
#include <stdio.h>

int main(int argc,char **argv)
{
	int i;
	FILE *fp = fopen("o", "w");
	fprintf(fp, "%08x %08x\n", (int)_get_osfhandle(0),(int)_get_osfhandle(1));
	for (i = 0;i < 1000;i ++) {
		printf("%010d\n",i);
		fprintf(fp,"%d\n",i);
		fflush(fp);
	}
}
#include <stdio.h>

int main(int argc,char**argv)
{
	FILE *fp = fopen("o2","w");
	fprintf(fp, "%08x %08x\n", (int)_get_osfhandle(0),(int)_get_osfhandle(1));
	close(0);
}
#include <windows.h>
#include <stdio.h>
#include <process.h>

int main(int argc,char **argv)
{
	int fd;
	int pip[2];
	_pipe(pip, 0, 0);

	fd = dup(1);
	dup2(pip[1], 1);
	spawnl(_P_NOWAIT, "a.exe", "a.exe", NULL);
	close(1);
	dup2(fd, 1);
	close(fd);

	fd = dup(0);
	dup2(pip[0], 0);
	spawnl(_P_NOWAIT, "b.exe", "b.exe", NULL);
	close(0);
	dup2(fd, 0);
	close(fd);
}
_______________________________________________
Make-w32 mailing list
Make-w32@gnu.org
http://lists.gnu.org/mailman/listinfo/make-w32

Reply via email to