jos/user/spin.c

32 lines
614 B
C
Raw Normal View History

2018-10-06 06:52:47 -07:00
// 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);
}