getpid.c 198 B

1234567891011121314151617
  1. #include <u.h>
  2. #include <libc.h>
  3. int
  4. getpid(void)
  5. {
  6. char b[20];
  7. int f;
  8. memset(b, 0, sizeof(b));
  9. f = open("#c/pid", 0);
  10. if(f >= 0) {
  11. read(f, b, sizeof(b));
  12. close(f);
  13. }
  14. return atol(b);
  15. }