1

And if so, can it be kept alive somehow?

(This is not a duplicate question since I did not know that logging out will kill a process. Maybe others also don't and so ask the wrong question.

I would suggest that the answers include a link to the other question.)

bomben
  • 2,059
  • I think the other question is very important but please keep in mind that you have to already KNOW, that a process will be terminated if you log out of ssh. I did not know this and this one answer is made it very clear and gave a clear, short solution. – bomben Oct 21 '18 at 16:36
  • Ok, I wasn't aware of that. Good point. -- Btw, if you are satisfied with the answer below you may follow the advice given in What should I do when someone answers my question?. ;-) But please don't feel pushed. Just take your time. – PerlDuck Oct 21 '18 at 16:43
  • 1
    I will test the answer and mark it as such if it works. – bomben Oct 21 '18 at 16:43
  • 1
    What do you mean “SSH into a samba share”? It’s either an SSH server offering services via the SSH protocol or a Samba server offering services/resources via the CIFS protocol. You can’t use SSH to access a CIFS resource. – David Foerster Oct 24 '18 at 07:18
  • I am SSHing into a server that is also providing a samba share. You are right, the fact that this server also provides a service via CIFS is not important. I will change the question. – bomben Oct 24 '18 at 07:26

2 Answers2

3

Yes, the process will get a "Hangup" signal (SIGHUP), which is not usually caught, and results in process termination. Read man -a signal and the man pages it points to.

The nohup command was designed to overcome this difficulty, without the overhead of screen or tmux (nohup was invented first, back when "Hangup" referred to modems). You can specify a logfile, or let nohup save STDOUT and STDERR to ./nohup.out, if possible, or $HOME/nohup.out if not.

nohup command >$HOME/command.log &
waltinator
  • 36,399
  • Why is th & necessary at the end? If I would use for example "nohup cp -v &" is there a way to log out of SSH and back in and then get the output from -v by re-connecting to the process? – bomben Oct 22 '18 at 06:24
1

Yes, commands you have started will be stopped if you log out. But you can start them using the screen command:

$ screen command

From this virtual screen you can exit afterwards (Ctrl+A, D), while letting the command proceed running.

You can start a command and instantly send it into a virtual detached screen as well:

$ screen -fa -d -m command

To get an overview of your screen sessions, use the following command:

$ screen -list
There are screens on:
    2457.pts-2.myserver (22.10.2018 20:04:35)   (Detached)
    12596.pts-3.myserver    (28.08.2018 22:10:00)   (Detached)
    4632..myserver  (15.07.2018 20:56:55)   (Detached)
3 Sockets in /run/screen/S-me.
$ 

Bring a session back in foreground, using the -r switch, while giving the session id:

$ screen -r 2457.pts-2.myserver
Nicolas
  • 857
  • In your first answer you said something about re-connecting to the process. That would be interesting, e.g. if I use "screen cp -v" and then log out of SSH and back in later. – bomben Oct 22 '18 at 06:25
  • I did a little research myself and I would suggest you add "screen -r" and "screen -ls" to your answer. – bomben Oct 22 '18 at 06:40
  • I added a description of the other two arguments – Nicolas Oct 22 '18 at 18:13