$script_name = "distribution.php"; $my_pid=shell_exec("pgrep -f $script_name"); $my_pid=trim($my_pid); $ps = shell_exec("pgrep -f -l $script_name |grep -v $my_pid | grep -v grep"); if($ps) { exit(); } Works, with output : sh: line 2: 25571: command not found