From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 1 18:08:35 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 077AD106564A for ; Tue, 1 Apr 2008 18:08:35 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id 5778F8FC2E for ; Tue, 1 Apr 2008 18:08:33 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from kobe.laptop (vader.bytemobile-rio.ondsl.gr [83.235.57.37]) (authenticated bits=128) by igloo.linux.gr (8.14.2/8.14.2/Debian-3) with ESMTP id m31HwE78028446 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 1 Apr 2008 20:58:41 +0300 Received: from kobe.laptop (kobe.laptop [127.0.0.1]) by kobe.laptop (8.14.2/8.14.2) with ESMTP id m31Hw6WV003533; Tue, 1 Apr 2008 20:58:06 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by kobe.laptop (8.14.2/8.14.2/Submit) id m31Hw3Hm003532; Tue, 1 Apr 2008 20:58:03 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) From: Giorgos Keramidas To: "Rao\, Nikhil" References: <20080329120018.0A8F5106567F@hub.freebsd.org> <12A5C15467D5B94F8E0FF265D9498ADD02CBF8FF@orsmsx419.amr.corp.intel.com> <20080401075623.GA19770@freebsd.org> <12A5C15467D5B94F8E0FF265D9498ADD02CBF949@orsmsx419.amr.corp.intel.com> Date: Tue, 01 Apr 2008 20:58:03 +0300 In-Reply-To: <12A5C15467D5B94F8E0FF265D9498ADD02CBF949@orsmsx419.amr.corp.intel.com> (Nikhil Rao's message of "Tue, 1 Apr 2008 07:23:58 -0700") Message-ID: <878wzxa250.fsf@kobe.laptop> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-MailScanner-ID: m31HwE78028446 X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-3.971, required 5, autolearn=not spam, ALL_TRUSTED -1.80, AWL 0.43, BAYES_00 -2.60) X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Spam-Status: No Cc: freebsd-hackers@freebsd.org, Roman Divacky Subject: Re: pfind() and the proc structure X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Apr 2008 18:08:35 -0000 On Tue, 1 Apr 2008 07:23:58 -0700, "Rao, Nikhil" wrote: > Ok, I should have caught that :-( 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 } Not until you unlock the specific proc entry. You are holding a lock for the specific proc entry, so anyone trying to `reap' the process would have to wait until you are done with what you are doing.