Closing the terminal will kill all processes launched from its shell instance that are still running. Here is how to detach a running process and run+detach a new process:
Scenario 1:
Let’s say we have ./long.sh
running, and we want to detach it:
./long.sh
Press Ctrl+Z
to pause the process:
[1] bash: suspended ./long.sh
Get its job ID with the jobs
command:
jobs
[1] + suspended ./long.sh
Then type bg
, to run it in background:
bg %1
[1] bash: continued ./long.sh
Use disown
to detach it:
$ disown %1
# Using its job ID
Scenario 2:
You can also run+detach a process with:
nohup ./long.sh &
# stdout and stderr will be put in a file.
In Scenario 2, how do you get the pid ?