getppid.c 339 B

1234567891011121314151617181920212223
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <fcntl.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include "sys9.h"
  8. pid_t
  9. getppid(void)
  10. {
  11. int n, f;
  12. char ppidbuf[15];
  13. f = open("#c/ppid", 0);
  14. n = read(f, ppidbuf, sizeof ppidbuf);
  15. if(n < 0)
  16. errno = EINVAL;
  17. else
  18. n = atoi(ppidbuf);
  19. close(f);
  20. return n;
  21. }