child.cpp
int main( int argc, char *argv[])
{
int cpipes[2];
pipe(cpipes); //create pipe
char buffer[4096];
int choice = atoi(argv[1]);
int num=0;
close(cpipes[1]);
read(cpipes[0], buffer, sizeof(buffer));
cout<<" Received at converter: "<<buffer<<endl;
}
-----------------------------main.cpp
int main()
{
int pipes[2];
char number[4096]; //storage for 32 bits
char options[3];
pipe (pipes); //create pipe
if (fork() == 0)
{
wait(NULL); // wait till child writes
}
else{
menu();
sprintf(number, "%d", choice); //convert integer to characters
sprintf(options, "%d", choice); //convert integer to characters
write(pipes[1], number, strlen(number));
cout << " Sent = " << number << endl;
execl("./child", "child", options, NULL); //pass write end buffer as argument to child
}
return 0;
}
Edited by WingedPanther, 07 June 2009 - 05:31 PM.
add code tags (the # button)


Sign In
Create Account

Back to top









