如何使用php中的pid杀死Linux进程? [英] How to kill a linux process using pid from php?

查看:428
本文介绍了如何使用php中的pid杀死Linux进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个有关从我的php代码中杀死Linux进程的问题. 我正在后台使用proc_open()函数从我的php代码运行Scrapy工具.

I am facing one issue regarding killing a Linux process from my php code. I am running a Scrapy tool from my php code using the proc_open() function in the background.

它工作正常,但现在我想使用其进程ID终止该进程. 为此,我使用exec("sudo kill -9 $pid");,其中$pid是从我的php代码获取的进程ID.

It works fine, but now I want to kill this process using its process id. To do that I'm using exec("sudo kill -9 $pid"); where $pid is the process id which I'm getting from my php code.

问题是此进程代表apache用户运行.我以为可能存在一些权限问题,所以我将apache用户添加到了apache ALL=(ALL) NOPASSWD:ALL这样的sudoers文件中,但是我仍然无法将其杀死.不知何故,相同的kill命令可以从我的腻子控制台上运行.

The problem is this process is running on behalf of the apache user. I thought there might be some permissions issue, so I added apache user to the sudoers file like this apache ALL=(ALL) NOPASSWD:ALL but I'm still not able to kill it. Somehow, the same kill command works from my putty console.

我的代码在Amazon EC2实例上.

My code is on an Amazon EC2 instance.

我的问题是,如何杀死php的pid标识的进程?

My question is, how can I kill that process identified by a pid from php?

推荐答案

永远不要授予apache sudo权限!

Never, ever, give apache sudo permissions!

使用exec("kill -9 $pid");-您的apache进程启动了它,它可以杀死它:)

Use exec("kill -9 $pid"); - your apache process started it, it can kill it :)

这篇关于如何使用php中的pid杀死Linux进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆