I have a parent and child process, and the parent can read the output from the child and send the child to the input. So far, everything has worked great with shell scripts, testing commands that input and output data. I just tested with a simple C program and couldn't get it to work. Here's the C program:
#include <stdio.h>
int main( void ) {
char stuff[80];
printf("Enter some stuff:\n");
scanf("%s", stuff);
return 0;
}
The problem with the C program is that my choice is not read from the child fd and therefore the program cannot end. Here is a bit that makes a choice.
fd_set set;
struct timeval timeout;
FD_ZERO( &set );
FD_SET( PARENT_READ, &set );
timeout.tv_sec = 3;
timeout.tv_usec = 0;
int r = select(FD_SETSIZE, &set, NULL, NULL, &timeout);
if( r < 1 ) {
exit(1);
}
Does anyone know why this will happen with a C program and not a shell?
Edit: I have to indicate that the child process calls exec in the argument, so I don't have access to it for this point.