LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-20-2015, 12:46 PM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
SSH broken pipe kills foreground process


Hi,

I have 2 hosts that I can connect them through SSH. In one host, after a while, I get the error `Write Failed: broken pipe.` In the other host, I don't get this error.

I don't understand why in one host, I get this problem, and in another host everything is ok.

So, I have set a SSH connection with tmux, and inside the remote host I run a foreground process (celeryd). But, even when the SSH session fails, and I reconnect to the dropped session, the foreground process has died.

I would like that the foreground process won't come down when the SSH connection is broken. So, I just have 2 solutions:

1. know how to avoid SSH broken pipes, or
2. know how to avoid that the process will die when the SSH connection goes down.


Can anyone can help me on this?

Last edited by xeon123; 04-20-2015 at 12:51 PM.
 
Old 04-20-2015, 01:30 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
You can't keep a process running in the foreground if the connection fails, because when the connection fails all of your stdin/stdout/stderr pipes break and the process can no longer function. Keeping the connection from failing is all well and good, but sometimes there's nothing you can do if this is a remote system.

The best option is to run it in the background with nohup if you don't need stdin, or in something like screen if you do.
 
Old 04-20-2015, 01:37 PM   #3
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,564
Blog Entries: 15

Rep: Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117Reputation: 2117
Have you tried using an entry in /etc/inittab to restart the service like:

ssh:2345:respawn:/usr/sbin/sshd -D -p 22

To restart the service if it stops?
 
Old 04-20-2015, 01:41 PM   #4
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by xeon123 View Post
Hi,

I have 2 hosts that I can connect them through SSH. In one host, after a while, I get the error `Write Failed: broken pipe.` In the other host, I don't get this error.

I don't understand why in one host, I get this problem, and in another host everything is ok.
SSH broken pipe usually result from connectivity issue. It could be because of network issue or because of misconfiguration in sshd_config. If your sshd was working fine on this server before and it suddenly started happening (assuming you have not made any changes to /etc/ssh/sshd_config) then it is most probably a network issue. It will be good if you run a ping test from another machine continuously to test that or check with your network team.

Quote:
So, I have set a SSH connection with tmux, and inside the remote host I run a foreground process (celeryd). But, even when the SSH session fails, and I reconnect to the dropped session, the foreground process has died.
Yes, if you are running any foreground process and if your ssh session gets killed or terminated the foreground process will get killed as well.

Quote:
I would like that the foreground process won't come down when the SSH connection is broken. So, I just have 2 solutions:

1. know how to avoid SSH broken pipes, or
2. know how to avoid that the process will die when the SSH connection goes down.


Can anyone can help me on this?
To avoid ssh broken pipes please see the above information I have provided. To avoid process getting killed it will be a good idea to run it in background. You can run it with nohup and & eg:

Code:
nohup dd if=/dev/zero of=/dev/null &
Here I am running dd with nohup and & to push it to background instead of foreground. So even if I exit from shell it will be running in background.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't login to ssh server--error: write failed broken pipe daforce Linux - Newbie 2 08-09-2014 10:05 AM
SSH-Write failed broken pipe Error vignesh4sh Linux - Server 1 11-22-2012 12:01 PM
[ssh] write failed: broken pipe mosthated Linux - Newbie 2 06-28-2012 07:21 AM
ssh Write failed: Broken pipe shogun1234 Linux - Networking 3 12-08-2010 10:33 PM
Recovering process to foreground after ssh session closed bujecas AIX 1 02-09-2010 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration