CSC209H5 Lecture 8: Pipes and Dup2

67 views3 pages

Document Summary

Csc209h5s - software programming and tools (winter 2018) Pipes are used to send data between processes and uses an array of two fds (file descriptors). The index 0 of array is used for reading and 1 is for writing. Once you fork(), you must close one of the file descriptors before continuing in order to start sending/receiving data. Example: make each child communicate the a message to the parent through a pipe. # include int main ( int argc, char **argv) { // code to loop over the command line arguments. For ( int i = 1 ; i < argc; i++) { // fork and create a new process retval = fork(); } else if (retval == 0 ) { // child process. // child only writes to the pipe, so close the reading end. // before we forked, parent had open the reading ends to. // all previously forked children; so close those.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents