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.

<?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

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

<?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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.