Messages in this thread | | | From | (H. Peter Anvin) | Subject | Re: Out of ptys | Date | 27 Aug 1998 05:34:52 GMT |
| |
Followup to: <Pine.LNX.3.95.980826132017.375A-100000@chaos.analogic.com> By author: "Richard B. Johnson" <root@chaos.analogic.com> In newsgroup: linux.dev.kernel > > Alan, > This shows the problem I reported to the glibc folks about a year > go. Note that both functions, good() and bad(), are identical except > for the fds that I close. > > void bad() > { > int i; > close(STDOUT_FILENO); > i = fprintf(stdout, "Hello world!\n"); > if(i > 0) > fprintf(stderr, "Bad! %d bytes copied to (closed) stdout...\n", i); > else > fprintf(stderr, "Good! (%d)\n", i); > } > > void good() > { > int i; > close(STDERR_FILENO); > i = fprintf(stderr, "Hello world!\n"); > if(i > 0) > fprintf(stdout, "Bad! %d bytes copied to (closed) stderr...\n", i); > else > fprintf(stdout, "Good! (%d)\n", i); > } >
This is perfectly understandable: stdout is a buffered stream, stderr isn't. Your bug is mixing low-level functions (e.g. close()) with stdio without an intervening fflush().
-hpa -- PGP: 2047/2A960705 BA 03 D3 2C 14 A8 A8 BD 1E DF FE 69 EE 35 BD 74 See http://www.zytor.com/~hpa/ for web page and full PGP public key I am Bahá'í -- ask me about it or see http://www.bahai.org/ "To love another person is to see the face of God." -- Les Misérables
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html
| |