I am trying to modify the scheduling policy in xv6 in which Parent runs first after forking.
childPid = fork();
if (childPid < 0)
{
printf("fork() is failed\n");
}
else if (childPid == 0) // child
{
printf(" child! ");
exit();
}
printf(" parent! ");
As the scheduler of xv6 always run Parent first i need to context switch to child first so that child will run first and after that parent will run. I have tried using wait() in the code but the wait will fail and i do not want to use fail. I need to modify the context switch when fork is performed by my user level program.
In the xv6 fork() system call i have made the following changes
acquire(&ptable.lock);
np->state = RUNNABLE;
swtch(&cpu->scheduler, proc->context);
release(&ptable.lock);
but this does not seems to work. Does it have something to do with timer interrupts. How can i achieve to run child first in fork after doing context switching.
您可以在父代码中使用调用sched_yield() ,这将使父线程放弃CPU,而另一个线程将开始运行。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.