douhoushou8385 2012-06-23 07:06
浏览 48
已采纳

从浏览器运行时posix_kill无法正常工作

I have a simple script, which tries to kill an already running process. I am using posix_kill for the same. The script runs fine, if I run it from command shell, but doesn't work when I run it from the browser.

<?php

    $taskid  = 33;
    killProcess($taskid);

    function killProcess($taskid) {
    $ppid = getPID($taskid);
    echo "process id -- $ppid
";
    $pids = preg_split('/\s+/', `ps -o pid --no-heading --ppid $ppid`);
    var_dump($pids);
    foreach($pids as $pid) {
            if(is_numeric($pid)) {
            echo "Killing $pid
";
                posix_kill($pid, 15);
            }
    }

    }
?>

I always get the following output, which means that the script is executing fine, but the process does not get killed: process id -- 4632 array (size=3) 0 => string '' (length=0) 1 => string '4633' (length=4) 2 => string '' (length=0) Killing 4633

I checked out the apache "error.log" file, and found that for each run that I do from browser, and additional entry gets added as follows: [Sat Jun 23 12:24:55 2012] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico

Unfortunately this error does not give me much information about what's going wrong. I checked out the php.ini settings, and there doesn't seem to be anything wrong (as per whatever limited understanding I have). I do not see posix_kill in the "disabled_functions" list etc or any other setting that should prevent me from executing process.

Would sincerely appreciate some help !!

Thanks, Kapil

  • 写回答

1条回答 默认 最新

  • dst3605528 2012-06-23 07:31
    关注

    The error message has nothing to do with your problem. It's just the browser asking for your site's icon, which you haven't configured.

    Now, about the actual issue: the apache user likely doesn't have permissions to kill your process. If the process was started under a different user account, you can't kill it from within the web server. Imagine a multiuser system where any local user could log in and kill everyone else's processes - that isn't the Unix permissions model...

    You might want to use a limited sudo with exec, or otherwise assume permissions before sending the signal. Or you could have the process listen for the web server to do something, and then kill itself. Or, better yet, don't use a web-serving language like PHP for systems-administration type tasks: use cron or a more appropriate tool.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多