shithub: riscv

ref: 173a01ef8b43690f2f3f02d75d03d83436d8022d
dir: /sys/src/ape/lib/ap/plan9/getppid.c/

View raw version
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "sys9.h"

pid_t
getppid(void)
{
	int n, f;
	char ppidbuf[15];

	f = open("#c/ppid", 0);
	n = read(f, ppidbuf, sizeof ppidbuf);
	if(n < 0)
		errno = EINVAL;
	else
		n = atoi(ppidbuf);
	close(f);
	return n;
}