How to kill a running bash file with php -


i have 2 buttons "start acquisition" , "stop acquisition",

the start button executes bash file , works fine:

<form action="control.php" method="post"> <input value="continous acquisition " name="continuous" type="submit"> </form>  <?php if (isset($_post['continous'])) { shell_exec('sh /desktop/run_test.sh'); } ?> 

i have no idea how stop execution when stop button pressed

<form action="control.php" method="post">  <input value="stop acquisition " name="stop" type="submit">   </form> 

any appreciated. thank you.

to run program in background, command should take form:

nohup sh /desktop/run_test.sh & 

to stop program, first find process id (pid), assuming here there 1 instance, otherwise you'll need differentiate instances:

$exec_output = array(); $actual_pid = 0; exec("pgrep -fl /desktop/run_test.sh", $exec_output); if ($exec_output , preg_match('/^(\d+) .*$/', $exec_output[0], $match)) {     $actual_pid = $match[1]; } 

then issue kill command

if ($actual_pid != 0) exec("kill -9 $actual_pid"); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -