Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jul 2004 02:04:47 +0300
From:      Ion-Mihai Tetcu <itetcu@apropo.ro>
To:        freebsd-questions@freebsd.org
Subject:   (Perl:) How to check linux's /proc/pid in BSD
Message-ID:  <20040724020447.0b4f609c@it.buh.tecnik93.com>

next in thread | raw e-mail | index | archive | help
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 = <PIDFILE>;
    $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"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040724020447.0b4f609c>