Kill process in Php - sudo

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
afifov
Forum Newbie
Posts: 1
Joined: Sat Nov 14, 2009 7:25 am

Kill process in Php - sudo

Post by afifov »

Hi ,

I am trying to kill a process thru php.

<?php
$pid=system("pidof myprocess");

echo "\n$pid";

exec("echo my pid is $pid", $out);
echo "restart process $pid";

exec("kill -6 $pid",$out);
var_dump($out);

?>

I am grabbing the process id successfully in $pid, and passing it to exec, but that doesn't work. I think its a permission thing, as all the above works, except the kill statement, which I believe its SELinux that gives me permission denial to execute the command via php.

I am on the sudoer list- how can I do this. I don't want a complicated function - Its just to allow my secretary to restart some batch jobs via a simple web page. She wouldn't know what a linux terminal is if her life depended on it.

Cheers,

C.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Kill process in Php - sudo

Post by josh »

Kill a process which is not responding:

killall -9 processname

The numeric argument specifies a signal to send to the process. In this case, the command sends signal 9 to the process, which is SIGKILL, as opposed to the default SIGTERM.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Kill process in Php - sudo

Post by VladSun »

You can only kill processes that are owned by the user executing the kill command. If not you need to use sudo. Try this first, before any attempt to mess with SELinux policies.

Code: Select all

`sudo kill -s 6 $pid`
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply