xref: /plan9-contrib/sys/src/ape/lib/ap/plan9/getppid.c (revision 3e12c5d1bb89fc02707907988834ef147769ddaf)
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
getppid(void)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