du8589840 2014-01-13 16:15
浏览 107
已采纳

从网站上杀死一个进程

I have the code and everything which is:

     pkill python

However I wanted to run it from a php script like this:

  echo shell_exec("pkill python");

I get an output which says:

bash: pkill: (1503) - Operation not permitted

I know what the problem is, which is that pkill is su command. Anyway to change this so that the php script can run it?

  • 写回答

1条回答 默认 最新

  • duanben4771 2014-01-13 16:43
    关注

    The problem is, that the process you want to kill does not belong to the apache user (apache usually runs as www-data with group www-data). If you give apache more rights (say run it as user root), your PHP script would run with more rights and could do things like this. But this would be dangerous, because if there is a security flaw in apache or your php script, a malicious attacker could take over your system.

    Instead I suggest using the setuid bit.

    1. Create a file kill.sh with the content pkill python
    2. Make it executable (chmod a+x kill.sh)
    3. Make it belong to root (chown root:root kill.sh)
    4. Make it setuid (chmod u+s kill.sh)
    5. Invoke this script from your php script
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度