Domanda

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.

È stato utile?

Soluzione

You may try:

echo $ssh->exec('java -Xmx256M -Xms32M -jar minecraft_server.jar nogui > /dev/null 2>&1 & echo $!;');

Altri suggerimenti

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");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top