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

28 lines
530 B

12 years ago
  1. #include <stdio.h>
  2. #include <ulib.h>
  3. void
  4. sleepy(int pid) {
  5. int i, time = 100;
  6. for (i = 0; i < 10; i ++) {
  7. sleep(time);
  8. cprintf("sleep %d x %d slices.\n", i + 1, time);
  9. }
  10. exit(0);
  11. }
  12. int
  13. main(void) {
  14. unsigned int time = gettime_msec();
  15. int pid1, exit_code;
  16. if ((pid1 = fork()) == 0) {
  17. sleepy(pid1);
  18. }
  19. assert(waitpid(pid1, &exit_code) == 0 && exit_code == 0);
  20. cprintf("use %04d msecs.\n", gettime_msec() - time);
  21. cprintf("sleep pass.\n");
  22. return 0;
  23. }