0

Hi all..
I have written one php code to kill a process on my shell. for this
i have used shell_exec function.
the code is: start.php

<?php
echo "into php";
shell_exec ('killall -9 sshd-sim'); //sshd-sim is the process to be killed
echo "out of php";
?>

the problem i am facing is:
when i run it from CLI using php start.php, den i get all the desired results: into php
out of php
also the process is killed
but when i open it thru browser http://x.y.z.q/start.php
den it only displays :
into php
out of php
it never kills the process .
Please give me any suggestions.
Any help will be greatly appreciated.

Edited by nav33n: Please use [code] tags to wrap your code for easy readability.

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by dolu
0
<?php
      echo "into php";
      $result = shell_exec ('killall -9 sshd-sim'); //sshd-sim is the process to be killed
     echo $result;
      echo "out of php";
      ?>

that will give you the output and should help you debug. my guess is www-data doesnt have access to kill that process and needs to be added to admin group which is very dangerous

Edited by kireol: n/a

0

What system are you using?
If you are using Apache with Windows you need to open your services pannel (Start>Run>services.msc), right click Apache *.*, account then check "Allow service to interact with desktop"
That should help if you are on Windows, if you are on Linux or UNIX that script should work so if it doesn't then it may be an issue with Apache/Linux rather than PHP itself

0
<?php
      echo "into php";
      $result = shell_exec ('killall -9 sshd-sim'); //sshd-sim is the process to be killed
     echo $result;
      echo "out of php";
      ?>

that will give you the output and should help you debug. my guess is www-data doesnt have access to kill that process and needs to be added to admin group which is very dangerous

thanks 4 ur time...
I am using linux+ apache.
If its dangerous, can u please suggest me some other way to invoke or kill a process running on linux. Any sort of help will be quite useful to me.

0

What system are you using?
If you are using Apache with Windows you need to open your services pannel (Start>Run>services.msc), right click Apache *.*, account then check "Allow service to interact with desktop"
That should help if you are on Windows, if you are on Linux or UNIX that script should work so if it doesn't then it may be an issue with Apache/Linux rather than PHP itself

thanks for ur time
the thing is when I pass 'ls - ltr ' or 'whoami' to exec or system then it works. i.e it displays whatever is required.
but when i try to run/kill a process or make some directory using exec it fails. please help me out of this trouble.
or suggest me some other way by which invoking/killing a process can be done.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.