getmainpid.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. void
  21. main(void)
  22. {
  23. int32_t pid, mainpid;
  24. Waitmsg *w;
  25. switch(fork()){
  26. case 0:
  27. mainpid = getmainpid();
  28. pid = getppid();
  29. if(mainpid != pid){
  30. print("FAIL: getmainpid() = %d, getppid() = %d\n", mainpid, pid);
  31. exits("FAIL");
  32. }
  33. exits(nil);
  34. break;
  35. default:
  36. mainpid = getmainpid();
  37. pid = getpid();
  38. if(mainpid != pid){
  39. print("FAIL: getmainpid() = %d, getpid() = %d\n", mainpid, pid);
  40. exits("FAIL");
  41. }
  42. w = wait();
  43. if(w->msg[0])
  44. exits("FAIL");
  45. break;
  46. }
  47. print("PASS\n");
  48. exits("PASS");
  49. }