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?

1
  • 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, 2016 at 20:51

1 Answer 1

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.

Not the answer you're looking for? Browse other questions tagged .