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

10 years ago
  1. #include <ulib.h>
  2. #include <stdio.h>
  3. const int max_child = 32;
  4. int
  5. main(void) {
  6. int n, pid;
  7. for (n = 0; n < max_child; n ++) {
  8. if ((pid = fork()) == 0) {
  9. cprintf("I am child %d\n", n);
  10. exit(0);
  11. }
  12. assert(pid > 0);
  13. }
  14. if (n > max_child) {
  15. panic("fork claimed to work %d times!\n", n);
  16. }
  17. for (; n > 0; n --) {
  18. if (wait() != 0) {
  19. panic("wait stopped early\n");
  20. }
  21. }
  22. if (wait() == 0) {
  23. panic("wait got too many\n");
  24. }
  25. cprintf("forktest pass.\n");
  26. return 0;
  27. }