[英]Kill process with php command
In ubuntu terminal, I can kill "firefox" with this comand: pgrep python | xargs kill
在ubuntu终端中,我可以使用以下命令杀死“ firefox”:
pgrep python | xargs kill
pgrep python | xargs kill
and it works. pgrep python | xargs kill
,它起作用。
But if I try to execute this comand in php in localhost, with this code: exec("sudo pgrep firefox | xargs kill",$output);
但是,如果我尝试在本地主机的php中执行此命令,则使用以下代码:
exec("sudo pgrep firefox | xargs kill",$output);
It doesn't work and the output is an empty array. 它不起作用,输出是一个空数组。 I've just added "www-data" in sudoers.
我刚刚在sudoers中添加了“ www-data”。 Other exec comand work.
其他执行命令工作。
For sudo to work You CAN'T have a pipe "|" 为了使sudo正常工作,您无法使用管道“ |” within the call tha way.
在通话范围内。
Also the clean way is to write the whole path to a binary, like "/usr/bin/pgrep" 同样,干净的方法是将整个路径写入二进制文件,例如“ / usr / bin / pgrep”
Best way to handle redirections in sudo is to put the whole command in a script and sudo that. 在sudo中处理重定向的最好方法是将整个命令放在脚本中并sudo。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.