diff --git a/sys/man/2/getpid b/sys/man/2/getpid index 6d795746d..9245df9be 100644 --- a/sys/man/2/getpid +++ b/sys/man/2/getpid @@ -13,27 +13,18 @@ int getpid(void) int getppid(void) .SH DESCRIPTION .I Getpid -reads -.B /dev/pid -(see -.IR cons (3)) -and converts it to get the process id of the current process, +returns the process id of the current process, a number guaranteed to be unique among all running processes on the machine executing .IR getpid . .PP .I Getppid -reads -.B /dev/ppid -(see -.IR cons (3)) -and converts it to get the id of the parent of the current process. +returns the process id of the parent of the current process. .SH SOURCE .B /sys/src/libc/9sys .SH SEE ALSO .IR intro (2), .IR exec (2), -.IR cons (3), .IR proc (3) .SH DIAGNOSTICS Returns 0 and diff --git a/sys/src/ape/lib/ap/plan9/getppid.c b/sys/src/ape/lib/ap/plan9/getppid.c index ad38e2c7b..d4cd710c2 100644 --- a/sys/src/ape/lib/ap/plan9/getppid.c +++ b/sys/src/ape/lib/ap/plan9/getppid.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -9,14 +10,15 @@ pid_t getppid(void) { - char b[20]; + char buf[32]; int f; - memset(b, 0, sizeof(b)); - f = _OPEN("/dev/ppid", OREAD); - if(f >= 0) { - _PREAD(f, b, sizeof(b), 0); - _CLOSE(f); - } - return atol(b); + snprintf(buf, sizeof(buf), "/proc/%d/ppid", getpid()); + f = open(buf, 0); + if(f < 0) + return 0; + memset(buf, 0, sizeof(buf)); + read(f, buf, sizeof(buf)-1); + close(f); + return atol(buf); } diff --git a/sys/src/libc/9sys/getppid.c b/sys/src/libc/9sys/getppid.c index 87b878927..1d1fc433f 100644 --- a/sys/src/libc/9sys/getppid.c +++ b/sys/src/libc/9sys/getppid.c @@ -4,14 +4,15 @@ int getppid(void) { - char b[20]; + char buf[32]; int f; - memset(b, 0, sizeof(b)); - f = open("/dev/ppid", OREAD|OCEXEC); - if(f >= 0) { - read(f, b, sizeof(b)); - close(f); - } - return atol(b); + snprint(buf, sizeof(buf), "/proc/%lud/ppid", (ulong)getpid()); + f = open(buf, OREAD|OCEXEC); + if(f < 0) + return 0; + memset(buf, 0, sizeof(buf)); + read(f, buf, sizeof(buf)-1); + close(f); + return atol(buf); }