From owner-freebsd-questions@FreeBSD.ORG Fri Jul 23 23:07:53 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9DF9E16A4CE for ; Fri, 23 Jul 2004 23:07:53 +0000 (GMT) Received: from smtp.rdsnet.ro (smtp.rdsnet.ro [62.231.74.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id B342343D31 for ; Fri, 23 Jul 2004 23:07:52 +0000 (GMT) (envelope-from itetcu@apropo.ro) Received: (qmail 5804 invoked by uid 89); 23 Jul 2004 23:01:48 -0000 Received: from unknown (HELO it.buh.tecnik93.com) (81.196.204.98) by 0 with SMTP; 23 Jul 2004 23:01:48 -0000 Received: from localhost (localhost.buh.tecnik93.com [127.0.0.1]) by it.buh.tecnik93.com (Postfix) with ESMTP id 0614A198 for ; Sat, 24 Jul 2004 02:04:51 +0300 (EEST) Received: from it.buh.tecnik93.com ([127.0.0.1]) by localhost (it.buh.tecnik93.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 84127-06 for ; Sat, 24 Jul 2004 02:04:50 +0300 (EEST) Received: from it.buh.tecnik93.com (localhost.buh.tecnik93.com [127.0.0.1]) by it.buh.tecnik93.com (Postfix) with SMTP id 96E5F116 for ; Sat, 24 Jul 2004 02:04:50 +0300 (EEST) Date: Sat, 24 Jul 2004 02:04:50 +0300 From: Ion-Mihai Tetcu To: freebsd-questions@freebsd.org Message-Id: <20040724020450.39b9c18c@it.buh.tecnik93.com> X-Mailer: Sylpheed-Claws 0.9.12 (GTK+ 1.2.10; i386-portbld-freebsd5.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at it.buh.cameradicommercio.ro Subject: (Perl:) How to check linux's /proc/pid in BSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Jul 2004 23:07:53 -0000 Hi, Could someone please help me with the following code as I don't want it to use /proc (my perl skils are very low) ## Check to see if that process is running if (! -d "/proc/$pid") { ## Return success if the PID is not running printmsg("DEBUG => checkPidFile() returning 0 since the PID specified in the pid file is not running.", 2); return(0); } ## Open the PID cmdline file so we can get the process name for the running PID. if (! open(PIDFILE, "/proc/$pid/cmdline")) { ## Return an error if it exists but we couldn't open it. printmsg("DEBUG => checkPidFile() returning 2 because for some reason I wasn't able to open the file: /proc/$pid/cmdline", 2); return(2); } ## proc/xxx/cmdline can be split by \0 to get the different parts my $pidname = ; $pidname =~ s/\0/ /; if ($pidname =~ /dspampd/io) { printmsg("DEBUG => checkPidFile() returning 3 the process referenced in the pid file [$pidname] is another dspampd process.", 2); return(3); } Thanks, -- IOnut Unregistered ;) FreeBSD "user"