LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-24-2017, 06:39 PM   #1
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Rep: Reputation: 3
If an SSH sessions ends in the middle of a command does the command end as well?


Computer shutdown during a mv command over SSH. Of course mv doesn't delete the old directory until all the files are moved (have always known/thought this applied to both Linux and Windows) so everything is good.

Am right in assuming that if an SSH sessions disconnects that any given command being performed ends as well?
 
Old 04-24-2017, 08:30 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,346
Blog Entries: 28

Rep: Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145
It is my understanding that it does, as the terminal closes.

As an alternative, you can use something like tmux or screen, which allows you to start a remote terminal session and disconnect from and reconnect to it without the terminal's closing.

I would expect both of them to be in your repos.

Last edited by frankbell; 04-24-2017 at 08:37 PM.
 
Old 04-24-2017, 11:27 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,330
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Normally, when SSH closes the processes get sent a SIGHUP signal (actually two in short order) and then do with that what they will. The normal reaction is to stop.

Code:
man 7 signal
If you don't write your program to trap and process SIGHUP you can use nohup to protect a single process or, as mentioned already, tmux or screen. I prefer tmux of the two and now use it almost exclusively over screen even though I'd been using the latter for many years.

systemd is said to break all of that, starting last year. Though some distros are also said to have deployed a work-around to keep the session behavior as expected. Check with your specific distro to see the exact situation on your hands.
 
Old 04-25-2017, 09:41 AM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
"SIGHUP" means "hang-up," as in, "the teletype user hung up the phone."

Ordinarily, the parent process receives this signal and terminates, thus (slight hand-waving here ...) terminating all of the children.

The nohup command can be used to influence this behavior.
 
Old 04-27-2017, 04:48 PM   #5
schnappi
Member
 
Registered: Apr 2017
Posts: 52

Original Poster
Rep: Reputation: 3
Thank you so much for sharing the nohup command. Really neat. Exactly what was looking for. Also happy to see nohup work in terminal on a local machine and not just over SSH. Previously had to leave a teminal window open for FreeFDP but nohup enables the terminal windows to be closed.
 
  


Reply



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
[SOLVED] mv command ends up deleting file andrew.comly Programming 8 10-07-2015 08:47 PM
Start command on ssh and access the progress of the command later. sublimemusic Linux - General 2 07-12-2015 01:23 PM
[SOLVED] Remote command execution via SSH and newgrp command SuperMegaMau Linux - General 4 05-13-2011 07:31 AM
dialog in the middle of a command geeyathink Programming 2 01-18-2008 10:25 PM
Make command always ends up in trouble ..!! cyberiapost Linux - Newbie 6 01-09-2007 07:22 AM

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

All times are GMT -5. The time now is 06:15 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