FreeBSD/sys/kern/kern_proc.c
/*
 * Locate process and do additional manipulations, depending on flags.
 */
Locate process and do additional manipulations, depending on flags.
Locate process and do additional manipulations depending on flags .
int
pget(pid_t pid, int flags, struct proc **pp)
{
	struct proc *p;
	int error;
	sx_slock(&allproc_lock);
	if (pid <= PID_MAX) {
		p = pfind_locked(pid);
		if (p == NULL && (flags & PGET_NOTWEXIT) == 0)
			p = zpfind_locked(pid);
	} else if ((flags & PGET_NOTID) == 0) {
		p = pfind_tid_locked(pid);
	} else {
		p = NULL;
	}
	sx_sunlock(&allproc_lock);
	if (p == NULL)
		return (ESRCH);
	if ((flags & PGET_CANSEE) != 0) {
		error = p_cansee(curthread, p);
		if (error != 0)
			goto errout;
	}
	if ((flags & PGET_CANDEBUG) != 0) {
		error = p_candebug(curthread, p);
		if (error != 0)
			goto errout;
	}
	if ((flags & PGET_ISCURRENT) != 0 && curproc != p) {
		error = EPERM;
		goto errout;
	}
	if ((flags & PGET_NOTWEXIT) != 0 && (p->p_flag & P_WEXIT) != 0) {
		error = ESRCH;
		goto errout;
	}
	if ((flags & PGET_NOTINEXEC) != 0 && (p->p_flag & P_INEXEC) != 0) {
		error = ESRCH;
		goto errout;
	}
	if ((flags & PGET_HOLD) != 0) {
		_PHOLD(p);
		PROC_UNLOCK(p);
	}
	*pp = p;
	return (0);
errout:
	PROC_UNLOCK(p);
	return (error);
}
int pget ( pid_t pid , int flags , struct proc * * pp ) { struct proc * p ; int error ; sx_slock ( & allproc_lock ) ; if ( pid <= PID_MAX ) { p = pfind_locked ( pid ) ; if ( p == NULL && ( flags & PGET_NOTWEXIT ) == 0 ) p = zpfind_locked ( pid ) ; } else if ( ( flags & PGET_NOTID ) == 0 ) { p = pfind_tid_locked ( pid ) ; } else { p = NULL ; } sx_sunlock ( & allproc_lock ) ; if ( p == NULL ) return ( ESRCH ) ; if ( ( flags & PGET_CANSEE ) != 0 ) { error = p_cansee ( curthread , p ) ; if ( error != 0 ) goto errout ; } if ( ( flags & PGET_CANDEBUG ) != 0 ) { error = p_candebug ( curthread , p ) ; if ( error != 0 ) goto errout ; } if ( ( flags & PGET_ISCURRENT ) != 0 && curproc != p ) { error = EPERM ; goto errout ; } if ( ( flags & PGET_NOTWEXIT ) != 0 && ( p -> p_flag & P_WEXIT ) != 0 ) { error = ESRCH ; goto errout ; } if ( ( flags & PGET_NOTINEXEC ) != 0 && ( p -> p_flag & P_INEXEC ) != 0 ) { error = ESRCH ; goto errout ; } if ( ( flags & PGET_HOLD ) != 0 ) { _PHOLD ( p ) ; PROC_UNLOCK ( p ) ; } * pp = p ; return ( 0 ) ; errout : PROC_UNLOCK ( p ) ; return ( error ) ; }
Locate process and do additional manipulations, depending on flags.
Locate process and do additional manipulations depending on flags .
/*
		 * XXXRW: Not clear ESRCH is the right error during proc
		 * execve().
		 */