1 Apr 2008 08:03
pfind() and the proc structure
Rao, Nikhil <nikhil.rao <at> intel.com>
2008-04-01 06:03:31 GMT
2008-04-01 06:03:31 GMT
Hi List,
The pfind(..) (in kern_proc.c) function below returns the proc structure
for the PID passed in
Say the thread that calls pfind() gets blocked at PROC_LOCK(p) (line 255
below), in the meantime what prevents the process from exiting and
deallocating the proc structure ? Maybe I am missing something simple or
the answer requires knowledge of the mutex implementation.
Thanks,
Nikhil
242 struct proc *
243 pfind(pid)
244 register pid_t pid;
245 {
246 register struct proc *p;
247
248 sx_slock(&allproc_lock);
249 LIST_FOREACH(p, PIDHASH(pid), p_hash)
250 if (p->p_pid == pid) {
251 if (p->p_state == PRS_NEW) {
252 p = NULL;
253 break;
254 }
255 PROC_LOCK(p);
256 break;
257 }
258 sx_sunlock(&allproc_lock);
(Continue reading)
Another question -
Now that the PROC_LOCK on p is obtained the all_proc lock is released
and the function returns, at this point can't the proc get deallocated ?
Nikhil
242 struct proc *
243 pfind(pid)
244 register pid_t pid;
245 {
246 register struct proc *p;
247
248 sx_slock(&allproc_lock);
249 LIST_FOREACH(p, PIDHASH(pid), p_hash)
250 if (p->p_pid == pid) {
251 if (p->p_state == PRS_NEW) {
252 p = NULL;
253 break;
254 }
255 PROC_LOCK(p);
256 break;
257 }
258 sx_sunlock(&allproc_lock);
259 return (p);
260 }
-----Original Message-----
From: Roman Divacky [mailto:rdivacky <at> freebsd.org]
Sent: Tuesday, April 01, 2008 12:56 AM
RSS Feed