0

If you start a command in a remote server with the net/ssh gem, and the command is on a deadlock, how do find the pid of the process running in the remote server and kill it?

Does net/ssh gem support this?

cjapes
  • 99
  • 9
  • Do you need a way to kill the processing using the Net::SSH gem? – Kashyap Aug 06 '12 at 18:29
  • Yes, that would be convinient. I found that ruby PTY gives you the pid of the process you started and you can use that to kill the process if it's not responding. But PTY is more complicated to use so I wanted to find a way to do the same with Net:SSH gem – cjapes Aug 07 '12 at 09:00

1 Answers1

-1

Well, if you can ssh into the remote server, you can use this to get the pid of the process:

# Assuming the command you want to kill is a ruby program.
# If the program is something else, say sparrow mail app, you should replace
# ruby with sparrow below.
  ps -ax | grep ruby 

And then, perhaps:

kill -9 <pid>
Kashyap
  • 4,696
  • 24
  • 26
  • That would return nothing if you doing ssh to a remote machine and then run a command that's not ruby... :( – cjapes Aug 07 '12 at 09:01
  • I think the answer was a little confusing. The `grep ` part in the answer basically filters the output of the command `ps -ax` with whatever `` is. So if its not a Ruby program, you'll replace it with whatever the name of the program you ran. – Kashyap Aug 07 '12 at 09:23
  • If you want to use the Net::SSH gem, however, I wrote a small snippet here: https://gist.github.com/3277327. Hope that works and helps – Kashyap Aug 07 '12 at 09:26