§ Запрет повторного запуска
1$pname = "processwatch.php";
2$pnum = (int) `ps aux | grep '$pname' | grep -v 'grep' | grep -v 'sh -c' | grep -v '/bin/sh' | wc -l`;
3if ($pnum === 0 || $pnum > 1) die();
§ Функция запрета повторного запуска
1
2
3function block_duplicate($procname)
4{
5 $cnt = 0;
6 $psaux = explode("\n", `ps aux`);
7 $reg_procname = preg_quote($procname, '~');
8
9 if (count($psaux) < 16)
10 die();
11
12 foreach ($psaux as $ps) {
13
14 if (preg_match('~' . $reg_procname . '\b~', $ps)) {
15
16 if (preg_match('~/bin/sh ~', $ps))
17 continue;
18
19 if (++$cnt >= 2)
20 die();
21 }
22 }
23}