Как проверить наличие экземпляра wget

У меня есть этот php-скрипт, который будет запускать процессы вилки wget каждый раз, когда это вызывается с помощью & :

wget http://myurl?id='.$insert_id .' -O ./images/'. $insert_id.' > /dev/null 2>&1 & 

Но как я могу проверить, есть ли уже обработчики wget, и если есть, не запускайте еще один?

Этот код используется для управления запущенным процессом (который в моем случае является скриптом php).

Не стесняйтесь вынимать части, которые вам нужны, и использовать их по своему усмотрению.

 class Process { private $processName; private $pid; public $lastMsg; public function __construct($proc) { $this->processName = $proc; $this->pid = 0; $this->lastMsg = ""; } private function update() { $output = array(); $cmd = "ps aux | grep '$this->processName' | grep -v 'grep' | awk '{ print $2; }' | head -n 1"; exec($cmd, $output, $rv); if ($rv == 0 && isset($output[0]) && $output[0] != "") $this->pid = $output[0]; else $this->pid = false; return; } public function start() { // if process isn't already running, if ( !$this->is_running() ) { // call exec to start php script $op = shell_exec("php $this->processName &> /dev/null & echo $!"); // update pid $this->pid = $op; return $this->pid; } else { $this->lastMsg = "$this->processName already running"; return false; } } public function is_running() { $this->update(); // if there is no process running if ($this->pid === false) { $this->lastMsg = "$this->processName is not running"; return false; } else { $this->lastMsg = "$this->processName is running."; return true; } } public function stop() { $this->update(); if ($this->pid === false) { return "not running"; } else { exec('kill ' . $this->pid, $output, $exitCode); if ($exitCode > 0) return "cannot kill"; else return true; } } }