《操作系统》的实验代码。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
602 B

  1. #include <stdio.h>
  2. #include <ulib.h>
  3. int
  4. main(void) {
  5. int pid, ret;
  6. cprintf("I am the parent. Forking the child...\n");
  7. if ((pid = fork()) == 0) {
  8. cprintf("I am the child. spinning ...\n");
  9. while (1);
  10. }
  11. cprintf("I am the parent. Running the child...\n");
  12. yield();
  13. yield();
  14. yield();
  15. cprintf("I am the parent. Killing the child...\n");
  16. assert((ret = kill(pid)) == 0);
  17. cprintf("kill returns %d\n", ret);
  18. assert((ret = waitpid(pid, NULL)) == 0);
  19. cprintf("wait returns %d\n", ret);
  20. cprintf("spin may pass.\n");
  21. return 0;
  22. }