《操作系统》的实验代码。
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

32 行
678 B

#include <stdio.h>
#include <ulib.h>
int
main(void) {
int pid, ret, i ,j;
cprintf("I am the parent. Forking the child...\n");
pid = fork();
if (pid== 0) {
cprintf("I am the child. spinning ...\n");
while (1);
}else if (pid<0) {
panic("fork child error\n");
}
cprintf("I am the parent. Running the child...\n");
yield();
yield();
yield();
cprintf("I am the parent. Killing the child...\n");
assert((ret = kill(pid)) == 0);
cprintf("kill returns %d\n", ret);
assert((ret = waitpid(pid, NULL)) == 0);
cprintf("wait returns %d\n", ret);
cprintf("spin may pass.\n");
return 0;
}