mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-04-28 04:40:37 +08:00
LAB 4 IS DONE.
This commit is contained in:
31
lab/user/spin.c
Normal file
31
lab/user/spin.c
Normal file
@@ -0,0 +1,31 @@
|
||||
// Test preemption by forking off a child process that just spins forever.
|
||||
// Let it run for a couple time slices, then kill it.
|
||||
|
||||
#include <inc/lib.h>
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
envid_t env;
|
||||
|
||||
cprintf("I am the parent. Forking the child...\n");
|
||||
if ((env = fork()) == 0) {
|
||||
cprintf("I am the child. Spinning...\n");
|
||||
while (1)
|
||||
/* do nothing */;
|
||||
}
|
||||
|
||||
cprintf("I am the parent. Running the child...\n");
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
sys_yield();
|
||||
|
||||
cprintf("I am the parent. Killing the child...\n");
|
||||
sys_env_destroy(env);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user