UNIX v7 calling sched()
Jim Balter
jim at segue.segue.com
Sun Apr 14 19:44:42 AEST 1991
In article <1991Apr12.172939.6348 at ncsu.edu> miler at 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
<proc 0>
main
newproc
creates new process, returns 0
sched
look for schedulable processes
find proc 1, start it running
<proc 1>
[main]
[newproc]
return 1
exec init
at some point, init sleeps or forks to create a new process,
which causes sched to be resumed
<proc 0>
[main]
[sched]
look for schedulable processes, start one running
<proc n>
.
.
.
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?
More information about the Comp.unix.wizards
mailing list