2

This question already has an answer here:

I have ssh'd into a ubuntu AWS box via terminal on mac. I have successfully setup the process I want to run in the box.

How do can exit out of terminal without killing the process running?

Can not run the below command because terminal is running the script and not allowing me to even copy and paste the below command into terminal:

nohup long-running-process &

Thank you in advance.

P.S

New to linux and terminal on mac

marked as duplicate by muru, G-Man, Jesse_b, Anthony Geoghegan, roaima Feb 7 '18 at 0:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you have already started the script, background and disown it: unix.stackexchange.com/a/23623/70524 – muru Feb 6 '18 at 5:35
  • Hi @muru I am trying this method: end processName to the background with bg %1 (using whatever the job # is following the %). This will resume processName in the background. but I am getting error 'Failed to open config file bg' – RustyShackleford Feb 6 '18 at 5:46
  • Is your process already in the background? If not, go to the step before that. – muru Feb 6 '18 at 5:47
  • Note that in the suggested duplicate, the answers other than the accepted one are definitely better solutions if you can prepare before starting the long-running process.. – roaima Feb 7 '18 at 0:08
3

ersonally I use screen to get in/out of the system while keeping the processes running.

$ sudo apt install screen

To create a new screen:

$ screen -S screen_name

Then do something in your screen, for example running a program, editing files, downloading file with wget, etc.

Later if you want to exit the terminal without killing the running process, simply press Ctrl+A+D. The process will kept running in the background inside the screen

To reconnect to the screen:

$ screen -R screen_name
1

Stop process with ctrl+z, put it in Background with bg, detach from shell with disown - exit shell.

Better use a multiplexer like screen https://help.ubuntu.com/community/Screen if you run into that more often.

  • confirming, I ran your three commands above got the message. "-bash: warning: deleting stopped job 3 with process group 10461" does that mean process is still running in background? – RustyShackleford Feb 6 '18 at 5:58
  • 1
    @RustyShackleford that most probably means that the process was killed and no longer running. You'd better use screen indeed. Just learn 2 commands and 2 shortcuts and it will become trivial. – ddnomad Feb 6 '18 at 7:20
  • @ddnomad the screen worked! Posting answer below! – RustyShackleford Feb 6 '18 at 12:41
  • ctrl+z worked! I'm just wondering why would they choose ctrl+z instead of ctrl+c or ctrl+d. Like every program is starting to have its own way of exiting the terminal while its running. – Kourosh May 20 at 2:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.