0

I am using phpseclib, Net_SSH2.

I need to get the process ID of the server/process that is started by this command.

echo $ssh->exec('java -Xmx256M -Xms32M -jar minecraft_server.jar nogui');

This is so i can store it and be able to kill it via a PHP script at anytime.

Harry Beasant
  • 1,014
  • 8
  • 18

2 Answers2

1

You may try:

echo $ssh->exec('java -Xmx256M -Xms32M -jar minecraft_server.jar nogui > /dev/null 2>&1 & echo $!;');
Aurimas Ličkus
  • 9,886
  • 4
  • 24
  • 26
0

Even this would work if you want to track PID of particular command after its execution.

$cmd = 'java -Xmx256M -Xms32M -jar minecraft_server.jar nogui';
$pid = $ssh->exec('echo `ps aux | grep -F "' . $cmd . '" | grep -v -F "grep" | awk \'{ print $2 }\'`');
echo $pid;  

To Kill same:

$ssh->exec("kill -9 $pid");
Asciiom
  • 9,867
  • 7
  • 38
  • 57
Mayura
  • 1,879
  • 1
  • 19
  • 21