Close the Terminal Without Terminating the Process

Close the Terminal Without Terminating the Process

I started an installation process from a terminal and have two questions about this:

  1. How can I close the terminal without terminating the installation process? and how can I restore it again?
  2. How can I figure that this terminal has finished processing from another terminal so that I can do other processes based on the result of the first terminal?
2

1 Answer

For 1. you need to send your running process to the background and remove the associated job from current shell.

  • Press Ctrl+Z and type bg to send the installation process to the backgroud
  • then type disown.

You can now close the terminal, the process will still be alive. You can open another terminal and check its process id with ps -aef

In my case the process id is 14426. Unfortunately there's no easy way to reattach it to another terminal (See How to attach terminal to detached process?) unless you used something based on screen.

For 2. You can use the following command:

while kill -0 14426 >/dev/null 2>&1; do sleep 5 ; done ; echo "ok"

It will print ok when the process is over from an other terminal. You can of course change this echo command with something more complex.

Source: BASH: launch background process and check when it ends

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.