Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com X-Authentication-Warning: vivaldi.cpe.ku.ac.th: ans owned process doing -bs Date: Mon, 22 Jan 2001 00:10:58 +0700 (ICT) From: Anon Sricharoenchai X-Sender: ans AT vivaldi DOT cpe DOT ku DOT ac DOT th To: cygwin AT cygwin DOT com Subject: Bug when reading from a non-blocking pipe file descriptor, while the opposite end (the writing pipe file descriptor) is closed. Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII The following is the C program to regenerate this bug. #include #include #include #include #include void test_func(int n1, int n2) { int input_from_child[2]; pipe(input_from_child); if (fork()) { char buf[20]; close(input_from_child[1]); fcntl(input_from_child[0], F_SETFL, O_NONBLOCK); sleep(n1); printf("%d\n", read(input_from_child[0], buf, sizeof(buf))); } else { close(input_from_child[0]); dup2(input_from_child[1], 1); close(input_from_child[1]); sleep(n2); exit(0); }; }; int main() { test_func(1, 0); test_func(1, 2); return 0; }; When compile and run on linux, the output of running this program should be as follow. 0 -1 But when compile and run using cygwin, the output will be as follow. -1 -1 The latter case is a bug on cygwin. Because when calling read(input_from_child[0], buf, sizeof(buf)) from test_func(1, 0), the file descriptor input_from_child[0] should be in the end of file status that should cause the read(...) to return 0. -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple