getpgrp.c 442 B

123456789101112131415161718192021222324252627
  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 <stdio.h>
  8. #include "sys9.h"
  9. #include "lib.h"
  10. pid_t
  11. getpgrp(void)
  12. {
  13. int n, f, pid;
  14. char pgrpbuf[15], fname[30];
  15. pid = getpid();
  16. sprintf(fname, "/proc/%d/noteid", pid);
  17. f = open(fname, 0);
  18. n = read(f, pgrpbuf, sizeof pgrpbuf);
  19. if(n < 0)
  20. _syserrno();
  21. else
  22. n = atoi(pgrpbuf);
  23. close(f);
  24. return n;
  25. }