What I want
I would like to ssh to a remote machine, start a process in the background, and retrieve the pid.
mrocklin@notebook:~$ echo hello &
[1] 29974
hello
What I tried
I would like to do this same thing with Paramiko
In [1]: import paramiko
In [2]: client = paramiko.SSHClient()
In [3]: client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
In [4]: client.connect('127.0.0.1')
In [5]: stdin, stdout, stderr = client.exec_command('echo hello &')
In [6]: stderr.read()
Out[6]: b''
In [7]: stdout.read()
Out[7]: b'hello\n'
When I do this with a process like sleep
, stdout.read()
blocks, cementing the fact that this isn't happening in the background.
What I really want
I want to run processes in the background because I want the ability to kill the process based on the PID later if I choose. Is there a better way to go about launching and killing several processes on a remote machine?