Why does the connection break when I kill a process on remote host?
-
I login to the remote host (debian) by ssh and execute a command like this ssh user@remote_host "ps -ef | grep process_name | grep -v grep | awk {'print $2'} | xargs kill -9' then the connection breaks. I ping the remote host and can't receive any response, like the network isn't connected. But when I restart the remote host (power off and power on), everything is ok. I promise that the process killed is only the program written by me and it's father process is "init" process (if the process run in fg and is killed that everything is ok). Is there any one who knows why it happened?
-
Answer:
ps -ef | grep process_name | grep -v grep gives not only the pid of what you want to kill, but also other information such as the uid, command of the process which may kill something unexpectly. More unfortunately, its ppid (parent pid, for you is 1) is also showed, then you know what will happen. You may try ssh user@remote_host "pkill process_name" or ssh user@remote_host "ps -eo pid,cmd | grep process_name | grep -v grep | cut -d' ' -f2 | xargs kill -9" Or you can first get its output: ssh user@remote_host "ps -ef | grep process_name | grep -v grep" and then filter the pid yourself.
yanshuyuan at Server Fault Visit the source
Other answers
I wonder that the command you are showing us even ran without errors. As mentioned in the other answer, you are passing too many things to xargs/kill which they treat as garbage. Use something like this to extract only the PID an kill it ps -ef | grep process_name | grep -v grep | awk '{print $3}' | xargs kill -9
Pavan Manjunath
Related Q & A:
- Why don't I get the little envelope in my taskbar in Outlook Express when I get a message?Best solution by Yahoo! Answers
- When I Turn a song in my car stereo i got a sony xplod stereo and when flip threw songs it thump in my subs?Best solution by Yahoo! Answers
- Why doesn't it work when I want to click a link in my Yahoo mess list?Best solution by Yahoo! Answers
- Why is it that my widescreen movies have the top and bottom bars when I have a widescreen TV?Best solution by answers.yahoo.com
- Why does my laptop freeze when i scroll and why cant i use my taskbar?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.