ProcessHandle pin_process(pid_t pid) {
	EUID_ASSERT();

	ProcessHandle rv = malloc(sizeof(struct processhandle_instance_t));
	if (!rv)
		errExit("malloc");
	rv->pid = pid;

	char proc[64];
	snprintf(proc, sizeof(proc), "/proc/%d", pid);

	EUID_ROOT();
	int fd = open(proc, O_RDONLY|O_CLOEXEC);
	EUID_USER();
	if (fd < 0) {
		if (errno == ENOENT)
			fprintf(stderr, "Error: cannot find process with pid %d\n", pid);
		else
			fprintf(stderr, "Error: cannot open %s: %s\n", proc, strerror(errno));
		exit(1);
	}
	rv->fd = fd;

	return rv;
}
ProcessHandle pin_process(pid_t pid) {
	EUID_ASSERT();

	ProcessHandle rv = malloc(sizeof(struct processhandle_instance_t));
	if (!rv)
		errExit("malloc");
	rv->pid = pid;

	char proc[64];
	snprintf(proc, sizeof(proc), "/proc/%d", pid);

	EUID_ROOT();
	int fd = open(proc, O_RDONLY|O_CLOEXEC);
	EUID_USER();
	if (fd < 0) {
		if (errno == ENOENT)
			fprintf(stderr, "Error: cannot find process with pid %d\n", pid);
		else
			fprintf(stderr, "Error: cannot open %s: %s\n", proc, strerror(errno));
		exit(1);
	}
	rv->fd = fd;

	return rv;
}