《操作系统》的实验代码。
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.

34 lines
708 B

10 years ago
  1. #include <stdio.h>
  2. #include <ulib.h>
  3. int magic = -0x10384;
  4. int
  5. main(void) {
  6. int pid, code;
  7. cprintf("I am the parent. Forking the child...\n");
  8. if ((pid = fork()) == 0) {
  9. cprintf("I am the child.\n");
  10. yield();
  11. yield();
  12. yield();
  13. yield();
  14. yield();
  15. yield();
  16. yield();
  17. exit(magic);
  18. }
  19. else {
  20. cprintf("I am parent, fork a child pid %d\n",pid);
  21. }
  22. assert(pid > 0);
  23. cprintf("I am the parent, waiting now..\n");
  24. assert(waitpid(pid, &code) == 0 && code == magic);
  25. assert(waitpid(pid, &code) != 0 && wait() != 0);
  26. cprintf("waitpid %d ok.\n", pid);
  27. cprintf("exit pass.\n");
  28. return 0;
  29. }