CSC209H5 Chapter Notes - Chapter 8: Grep, C String Handling, Standard Streams
Document Summary
Csc209h5s - software programming and tools (winter 2018) Open a file using a file descriptor int filedes = open( file1 , o_rdonly); Create a pipe - set up a communication channel int fd[ 2 ]; // array of two file descriptors pipe(fd); Read 256 bytes from file read(filedes, buf, 256 ); Read 256 bytes from pipe read(fd[ 0 ], buf, 256 ); The file descriptor for standard output has the value 1 and is a field in a file struct. Specified by an array of two file descriptors, one for reading data from the pipe and one for writing data to the pipe. When a program calls the pipe system call, the os creates the pipe data structures and opens two file descriptors on pipe. Index 0 of array is used for reading. Index 1 of array is used for writing. When fork makes a copy of the existing progress, it also makes a copy of the open file descriptors.