Title | L18 - Lecture notes 17 |
---|---|
Author | Drew Limpasuvan |
Course | Introduction To Programming Systems |
Institution | Princeton University |
Pages | 2 |
File Size | 33.9 KB |
File Type | |
Total Downloads | 12 |
Total Views | 179 |
Course by Szymon Rusinkiewicz. This lecture returns to the idea of processes and goes more into detail about how to fork a child process. It also talks about Orphan and Zombie children and the way to avoid these problems....
Creating new processes: -program might want to run an additional instance of itself (two programs, one interacting w client while the other watching for more) or a whole different program -shell calls other program, other program runs, returns to shell So does fork-execute model! Parent proccess forks a child process Why? Bc sometimes bc execute, you want to set up environment with unix. With windows, you have to do all that during create process time In unix, there is fork that makes two copies and one uses standard system calls and only then does it do execute -gets callled once and returns twice -two processes will have registers identical at time of return (other than return status) -contents of memory identical too In child process, fork returns 0. In parent, returns process id of child But distinct! In parent process, local variables are all what they used to be but when parent changes the values, it doesn’t affect child and vice versa -same memory but different sets of page tables. Modifications in parent or child or affects its personal copy -even if only one cpu available, it looks like they are running concurrently because of time splicing -with time splicing, have to worry about which process goes first Typically will use pid as an if conditional Wait -suspends execution of calling process until one of it’s children terminates If parent process don’t wait for child -shell could causes sequencing problems -child becoming zombie or orphan Orphans will be adopted by process 1 (the process responsible for making the other processes and waits until the very end The only problem arises when orphan child never exits Execvp -replaces the current process images with new process image Provides an array of pointers to null terminated strings Wait only returns after cat exits
What about stuff you do in the background? Shell returns immediately!...