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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-20-2015, 12:46 PM
|
#1
|
Member
Registered: Sep 2006
Posts: 374
Rep:
|
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.
|
|
|
04-20-2015, 01:30 PM
|
#2
|
LQ Guru
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573
|
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.
|
|
|
04-20-2015, 01:37 PM
|
#3
|
LQ Guru
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,564
|
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?
|
|
|
04-20-2015, 01:41 PM
|
#4
|
Senior Member
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385
|
Quote:
Originally Posted by xeon123
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.
|
|
|
All times are GMT -5. The time now is 06:54 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|