我有一个脚本来下载一个torrent文件我使用的ctorrent似乎并没有关闭自己,所以我需要杀死pid。PHP获得进程的PID并将其杀死
$command = "ctorrent -x \"/var/www/html/torrents/$torrentName\"";
$output = shell_exec($command);
这完美的作品,我看到了另一个计算器问题,有人说要做到以下几点:
$command = 'yourcommand' . ' > /dev/null 2>&1 & echo $!; ';
$pid = exec($command, $output);
var_dump($pid);
但是当我使用这一点,删除下载文件部分的输出,我需要作为即时通讯从输出中获取一些数据。
我怎样才能得到运行我的脚本的PID?
这最终是我想要实现:
if (file_exists("/proc/$pid")){
shell_exec("kill -9 $pid");
}
您可以使用ps工具或使用锁定文件。对于ps'exec(“ps -ef | grep'$ process'”,$ output);'并解析$ output – ineersa
'$ process'中将包含什么? – Exoon
'ctorrent'我想? – ineersa