Created
October 18, 2014 02:50
-
-
Save StefanoFiumara/facd2eedc18c29369dce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(i = 0; i < n; i++) { | |
//create 2 pipes per process, then close appropriate ends | |
if(pipe(parent_to_child[i]) == -1) { | |
cout << "Error creating pipe!" << endl; | |
exit(1); | |
} | |
if(pipe(child_to_parent[i]) == -1) { | |
cout << "Error creating pipe!" << endl; | |
exit(1); | |
} | |
pid = fork(); | |
if(pid > 0) { | |
//This is the parent, close the unnecessary pipe ends | |
close(parent_to_child[i][READ_END]); | |
close(child_to_parent[i][WRITE_END]); | |
continue; | |
} else if(pid == 0) { | |
//This is the child, close the opposite pipe ends as above | |
close(parent_to_child[i][WRITE_END]); | |
close(child_to_parent[i][READ_END]); | |
create_child(i); | |
break; | |
} else { | |
cout << "Fork Error!" << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment