From owner-freebsd-questions@FreeBSD.ORG Tue Dec 4 20:08:14 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6F84ECF for ; Tue, 4 Dec 2012 20:08:14 +0000 (UTC) (envelope-from bonomi@mail.r-bonomi.com) Received: from mail.r-bonomi.com (mx-out.r-bonomi.com [204.87.227.120]) by mx1.freebsd.org (Postfix) with ESMTP id 097368FC19 for ; Tue, 4 Dec 2012 20:08:13 +0000 (UTC) Received: (from bonomi@localhost) by mail.r-bonomi.com (8.14.4/rdb1) id qB4K9b60009439; Tue, 4 Dec 2012 14:09:37 -0600 (CST) Date: Tue, 4 Dec 2012 14:09:37 -0600 (CST) From: Robert Bonomi Message-Id: <201212042009.qB4K9b60009439@mail.r-bonomi.com> To: martin@dc.cis.okstate.edu Subject: Re: Safe Way to Tell if Process is Running In-Reply-To: <201212041939.qB4JdfGt085863@x.it.okstate.edu> Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Dec 2012 20:08:14 -0000 > Subject: Safe Way to Tell if Process is Running > Date: Tue, 04 Dec 2012 13:39:41 -0600 > From: Martin McCormick > > About 20 years ago, I saw some code in which you > verified whether or not a process was running by giving it a > kill -0 command. If the process was running, nothing happened to > it but your kill -0 command exited with a 0 status. If there was > no process with that PID, the kill command exited non-zero. > > I use this in a system(command); in a C program I wrote > some years ago and I think this is now causing a segmentation > fault when the process number being signalled doesn't exist. Is > there a better way to determine if process number 12345 is > running without bothering it? > > None of the documentation on kill (1) shows a signal 0 > nor does kill -l. > > Something tells me this is a bad idea these days, but I > still need an easy way to see if XYZ process is still alive. 'man 2 kill' tells all.