xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/getppid.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
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 
9 pid_t
10 getppid(void)
11 {
12 	int n, f;
13 	char ppidbuf[15];
14 
15 	f = open("#c/ppid", 0);
16 	n = read(f, ppidbuf, sizeof ppidbuf);
17 	if(n < 0)
18 		errno = EINVAL;
19 	else
20 		n = atoi(ppidbuf);
21 	close(f);
22 	return n;
23 }
24