lockdeath.c 895 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <u.h>
  2. #include <libc.h>
  3. int np = 32;
  4. int niter = 65536;
  5. int debug = 0;
  6. char data[8192];
  7. int i;
  8. int id;
  9. int intr = 0;
  10. void
  11. handler(void *v, char *s)
  12. {
  13. print("%d: %d iterations\n", id, i);
  14. if (intr++ < 16)
  15. noted(NCONT);
  16. exits("too many interrupts");
  17. }
  18. void
  19. main(int argc, char *argv[])
  20. {
  21. int pid;
  22. int fd;
  23. if (notify(handler)){
  24. sysfatal("notify: %r");
  25. }
  26. if (argc > 1)
  27. np = strtoull(argv[1], 0, 0);
  28. if (argc > 2)
  29. niter = strtoull(argv[2], 0, 0);
  30. debug = argc > 3;
  31. fd = open("#Z/qlock", ORDWR);
  32. if (fd < 0)
  33. sysfatal("qlock: %r");
  34. print("Running with %d kids %d times\n", np, niter);
  35. for(i = 0, id = 0; i < np-1; i++, id++) {
  36. pid = fork();
  37. if (pid == 0)
  38. break;
  39. if (pid < 0)
  40. sysfatal("fork");
  41. }
  42. if (debug) print("Forked. pid %d\n", getpid());
  43. for(i = 0; i < niter; i++) {
  44. if (read(fd, data, 1) < 1)
  45. print("%d: iter %d: %r", id, i);
  46. }
  47. }