Hi all,
I have been having problem with the unix ipc in a while. Cant really figure it out why i'm not able to read anything of the pipe at the parents process end, until the child gets killed. As you could see from the following snap of code which gets executed in the child. Here I create the child process and exec atec.exe. Thats a standalone process which accepts commands and prints the results to stdout. In which case i'm expecting it to be written on to the pipe, so that i can capture in the parent process. NOTE: atec will be in an infinite loop accepting commands, its never quit's until quit command is applied.
Code:
if( !fork() )
{
__LOG("Fork child(atec) - Sucess");
__LOG("Redirecting child stdout & stdin");
Close_Tunnel( 1);
Close_Tunnel( 0 );
if( ( dup2( __CHILD_WRITE,1 ) < 0 ) || ( dup2( __CHILD_READ,0 ) < 0 ) )
{
__ERROR( strerror( errno ) );
__ERROR("Process exiting..." );
return EXIT_FAILURE;
}
Close_Tunnel( __PARENT_READ );
Close_Tunnel( __PARENT_WRITE );
__LOG("Starting process");
if( execlp( __CHILD_PROCESS_PATH,__CHILD_PROCESS_PATH, NULL) == -1 )
{
dup2( 1, __CHILD_WRITE );
dup2(0, __CHILD_READ );
close( __CHILD_WRITE );
close( __CHILD_READ );
__ERROR( strerror( errno ) );
__ERROR("Process exiting..." );
return EXIT_FAILURE;
}
}
Thats my Child code
Code:
if( ( StreamContainer = ReadTunnel( __PARENT_READ ) ) > 0 )
{
printf( StreamContainer );
free( StreamContainer );
}
WriteTunnel( __PARENT_WRITE, "QueryStatus" );
if( ( StreamContainer = ReadTunnel( __PARENT_READ ) ) > 0 )
{
printf( StreamContainer );
free( StreamContainer );
}
Parent Code.
So when the command 'QueryStatus' is sent, i could see that child has received it and prints the results back onto stdout, which i should be able to read it in the parent. NOTE: I'm able to read message "starting process" which was written by child before exec the 'atec' process. But when I send the command 'quit' to 'atec' from parent. I'm able to read all the prints printed by atec after atec is quited. Why such a behaviour? How do re-direct exec stdout and in to child stdout and stdin? My thoughts were that it should anyway be using the child stdout and stdin?
TIA
ssharish