summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9/getpid.c
blob: 66eaaae8d662f2587fe3e58f3d330c0e168b43ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "lib.h"
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include "sys9.h"

pid_t
getpid(void)
{
	int n, f;
	char pidbuf[15];

	f = _OPEN("#c/pid", 0);
	n = _READ(f, pidbuf, sizeof pidbuf);
	if(n < 0)
		_syserrno();
	else
		n = atoi(pidbuf);
	_CLOSE(f);
	return n;
}