I was following
http://www.advancedlinuxprogramming.com/ chapter 7 to play around with the file descriptors.
Here is the source code of a process that I'm looking into.
Code:
/* File: a.c */
#include <stdio.h>
#include <unistd.h>
int main( int argc, char *argv[] )
{
char what[80];
what[0] = what[79] = '\0';
fprintf( stdout, "%d\n", (int)getpid() );
do {
fgets( what, 79, stdin );
} while ( what[0] != 'Q' );
return 0;
}
Compile this to a.out and run it:
Start another terminal, and attempt to send some text to 26678:
Code:
$ echo "hello" >/proc/26678/fd/0
$ echo "Q" >/proc/26678/fd/0
a.out in the first terminal doesn't quit. Instead the texts 'hello' and 'Q' are displayed in that terminal. Why doesn't a.out exit at 'Q'?
Thanks.