CSC209H1 Lecture Notes - Lecture 8: File Descriptor, Strace, Inter-Process Communication
Document Summary
Introduction to pipes: fork() system call gives us the ability to create multiple processes. In a long running program it is important to close the descriptors that are no longer needed, as the number of open file descriptors is limited it is possible to run out! Important details of how pipes really work: pipes are used to communicate between two independent processes. It is up to the os when these processes are even run. It is a good idea to close the file descriptor that are not in use. #include /* equivalent to sort < file1 | uniq */ int main() { int fd[2], r; /* create the pipe */ if ((pipe(fd)) == -1) { perror(pipe); exit(1); if ((r = fork()) > 0) { // parent will run sort. // set up the redirection from file1 to stdin int filedes = open(file1, o_rdonly);