notes9

notes9 - CS 354 Yashjeet Kaur Start by creating a new...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 354 Yashjeet Kaur Start by creating a new process for each command in the pipeline and having the shell wait for the last command to finish. No redirection for now, A|B|C ç create a process and exec for A,B,C and wait for C execute() for( each command in the pipeline) ret = fork(); if(ret == 0) { //Child execvp (command.args[0], command.args); perror (“execvp”); exit(1); } else if(ret < 0) { perror (“fork”); return } if(!background) { waitpid (ret, NULL); } When debugging shell, do not redirect stderr and use stderr for debugging messages. fprintf(stderr,"DebugStatement\n"); //function works with FILE* Close file descriptors when you don't use them. Especially for pipes. If a parent does not close a file descriptor of a pipe, it may cause a child to block forever, in another word, the child will never exit. ls | a pipe-in gets EOF when there are no writers. pipe-out produces EOF only when there are no writers.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
If the parent does not close its own pipe-file descriptor, there's always going to be a writer on the pipe and no EOF will be produced. Note: default max of 32
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

notes9 - CS 354 Yashjeet Kaur Start by creating a new...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online