Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!randvax!segue!jim From: jim@segue.segue.com (Jim Balter) Newsgroups: comp.unix.wizards Subject: Re: UNIX v7 calling sched() Message-ID: <7101@segue.segue.com> Date: 14 Apr 91 09:44:42 GMT References: <1991Apr12.172939.6348@ncsu.edu> Reply-To: jim@segue.segue.com (Jim Balter) Organization: Segue Software, Inc. - Santa Monica, CA. +1-213-453-2161 Lines: 63 In article <1991Apr12.172939.6348@ncsu.edu> miler@osl.csc.ncsu.edu (George Miler) writes: > main () > { > ...... > if (newproc()) <==== true, create /etc/init process > { > copy (/etc/init) > return; <==== exit main, starts copied process > } > sched (); <==== never reached if did /etc/init > } Do you understand how main () { if (fork() == 0) { childstuff(); return; } parentstuff(); } works? newproc() is just the kernel level equivalent of fork. It returns twice, into two different processes, with a 0 return to the parent and a non-zero return to the child (fork is the other way around). Generally, newproc will create a new process that is pretty much a copy of the current process, and set the pc of the new process to point to some code that will do a return 1. Since the stack is copied, that return will return to the caller of newproc. So the flow of control looks something like main newproc creates new process, returns 0 sched look for schedulable processes find proc 1, start it running [main] [newproc] return 1 exec init at some point, init sleeps or forks to create a new process, which causes sched to be resumed [main] [sched] look for schedulable processes, start one running . . . Basically, you need to understand the concept of concurrent processes and how they function under UNIX. Since you are in a class, why not get your instructor or a fellow student to help you?