get the pid of a process with pexpect
Nick Craig-Wood
nick at craig-wood.com
Mon May 5 13:30:03 EDT 2008
Karim Bernardet <bernardet at cppm.in2p3.fr> wrote:
> Hi
>
> I am using pexpect to do ssh tunneling and to open a vnc server (jobs on
> a grid cluster). When the job is canceled, these 2 processes remain on
> the worker node (they are detached), so I have to kill them (using a
> trap command in the bash script of the job) but I need the pid of each
> process. I have tried to get it like this
>
> ssh_tunnel = pexpect.spawn (tunnel_command % globals())
> ...
> print ssh_tunnel.pid
>
> but ssh_tunnel is not the pid of the ssh tunnel
>
> Is there a way to get it using pexpect ?
If I understand you correctly what you need to do is run "echo $$" on
the remote shell then "exec tunnel_command". The $$ will print the
pid and the exec will run tunnel_command without changing the pid.
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list