3

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

  • If you have already started the script, background and disown it: https://unix.stackexchange.com/a/23623/70524 – muru Feb 06 '18 at 05: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 06 '18 at 05:46
  • Is your process already in the background? If not, go to the step before that. – muru Feb 06 '18 at 05: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.. – Chris Davies Feb 07 '18 at 00:08

2 Answers2

8

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
2

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.

kai-dj
  • 186
  • 1
  • 5
  • 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 06 '18 at 05: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 06 '18 at 07:20
  • @ddnomad the screen worked! Posting answer below! – RustyShackleford Feb 06 '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. – Agent 0 May 20 '19 at 02:46