privates2.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * This file is part of Jehanne.
  3. *
  4. * Copyright (C) 2016 Giacomo Tesio <giacomo@tesio.it>
  5. *
  6. * Jehanne is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, version 2 of the License.
  9. *
  10. * Jehanne is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Jehanne. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <u.h>
  19. #include <lib9.h>
  20. int spin;
  21. int ok[2];
  22. void
  23. main(void)
  24. {
  25. char **test;
  26. test = (char **)privalloc();
  27. *test = smprint("Hello from %d (at %p)\n", getpid(), test);
  28. rfork(RFNOTEG);
  29. switch(rfork(RFPROC|RFMEM)){
  30. case -1:
  31. exits("rfork");
  32. case 0:
  33. *test = smprint("Hello from %d (at %p)\n", getpid(), test);
  34. spin = 1;
  35. while(spin)
  36. ;
  37. print("on %d: %s", getpid(), *test);
  38. exits(nil);
  39. break;
  40. default:
  41. while(spin == 0)
  42. ;
  43. }
  44. switch(rfork(RFPROC|RFMEM)){
  45. case -1:
  46. exits("rfork");
  47. case 0:
  48. *test = smprint("Hello from %d (at %p)\n", getpid(), test);
  49. spin = 2;
  50. while(spin)
  51. ;
  52. print("on %d: %s", getpid(), *test);
  53. exits(nil);
  54. break;
  55. default:
  56. while(spin == 1)
  57. ;
  58. }
  59. spin = 0;
  60. sleep(500);
  61. print("on %d: %s", getpid(), *test);
  62. exits("PASS");
  63. }