So, I have a file stream from the parent process for the child - and most of the time it works fine. However, when reading from it several times quickly, using the fgets () function returns NULL, and a "temporarily unavailable resource" is set for the error. The problem is intermittent - and running a script that will sometimes have fgets in readings returns NULL, and sometimes it won't.
Can someone help me stop this error? Thank!
Edit: here is the code. I'm not sure which other code would be useful? there is quite a bit
if( fgets( line, MAX_LINE_LENGTH, fpin ) == NULL ) {
if( ferror(fpin) ) {
perror("error on stream fpin");
}
free( line );
return FAIL;
}
According to the request, the code that opens the channel and processes the child process.
int readPipe[2];
int writePipe[2];
int errorPipe[2];
pipe( readPipe );
pipe( writePipe );
pipe( errorPipe );
pid_t pid;
pid = fork();
if( pid == 0 ) {
close( PARENT_READ );
close( PARENT_WRITE );
close( errorPipe[0] );
dup2( CHILD_READ, 0 );
dup2( CHILD_WRITE, 1 );
execvp(args[0], args);
char *error_message = "exec failed";
write( errorPipe[1], error_message, strlen(error_message)+1 );
exit(-1);
}
source
share