CSC209H1 Lecture Notes - Lecture 8: File Descriptor, Strace, Inter-Process Communication

59 views11 pages
School
Course
Professor

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);

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents