(Perl:) How to check linux's /proc/pid in BSD

Ion-Mihai Tetcu itetcu at apropo.ro
Fri Jul 23 16:07:53 PDT 2004


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);
    ## 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);
    ## 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);


Unregistered ;) FreeBSD "user"

More information about the freebsd-questions mailing list