0

I am wanting to background a long running script, which I know I can do using the following:

nohup ./install.sh &>/dev/null &

However, I also realize that if I leave that session, I can no longer see it running using job, since it would be running on another session if I login and then log back in.

My question is, before I run a script in the background, is there a way I can set it up so that I can return/foreground that script later? Even after I have logged out and then back in?

Zed Said
  • 707
  • 6
  • 14
  • 25
  • There is no way to do this with shell builtins, but there are tools to accomplish this. `reptyr` is mentioned in the linked Q&A. – Andrew B Aug 12 '16 at 20:51

1 Answers1

3

If you have properly backgrounded a task using nohup the stdXX channels will no longer be attached to a terminal, nor can they be reattached to a terminal.

If you want to detach a process and later reattach to it use screen instead of nohup. This gives you two non-exclusive options:

  • Switch to a different screen using the multiplexing option to do continue working in the same session.
  • Detach the screen session and reattach to it latter. You can reattach from a different terminal session. (This is my prime use of screen.)

Some people choose to use screen as their terminal environment. This allows them to switch session while working. They can then detach from screen, and leave their sessions ready for when they are next ready to work.

kasperd
  • 29,894
  • 16
  • 72
  • 122
BillThor
  • 27,354
  • 3
  • 35
  • 69