Işlemi hala çalışıyor olmadığını denetleme?

0 Cevap

Bir fakir adamın Watchdog'u kurmak ve emin bir uygulama (Ben neden anlamaya kadar) o çöker durumda yeniden kazanmak için bir yol olarak, her 5mn kontrol etmek cron tarafından idare edilecek bir PHP CLI komut dosyası yazmak gerek olmadığını süreci hala çalışıyor.

Dayanarak this page, ben aşağıdaki kodu denedim, ama her zaman ben sahte verilerle aramak bile True verir:

function processExists($file = false) {
    $exists= false;
    $file= $file ? $file : __FILE__;

    // Check if file is in process list
    exec("ps -C $file -o pid=", $pids);
    if (count($pids) > 1) {
    $exists = true;
    }
    return $exists;
}

#if(processExists("lighttpd"))
if(processExists("dummy"))
    print("Exists\n")
else
    print("Doesn't exist\n");

Sonra, ben denedim this code ...

(exec("ps -A | grep -i 'lighttpd -D' | grep -v grep", $output);)
print $output;

... Ama ben nelerle alamadım:

/tmp> ./mycron.phpcli 
Arrayroot:/tmp> 

FWIW, bu komut dosyası PHP 5.2.5 CLI sürümü ile çalışacak ve işletim uClinux 2.6.19.3 olur.

Herhangi bir ipucu için teşekkür ederiz.


Düzenleme: Bu iyi iş gibi görünüyor

exec("ps aux | grep -i 'lighttpd -D' | grep -v grep", $pids);
if(empty($pids)) {
        print "Lighttpd not running!\n";
} else {
        print "Lighttpd OK\n";
}

0 Cevap