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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。