Sometimes I start a program that takes a very long time to finish (emerge), then realize that I should go to bed instead of waiting for it. If I know this in the first place I would run

program; halt

However, now that I have started the program already, how can I "schedule" the computer to shutdown when that process finishes? Would Ctrl+z then fg; halt be OK?

3 Answers 3


Yes, that would work.

If unsure, you may test it with

  • sleep 15

  • Ctrl+z

  • fg; echo "it works"


Another way is to just type halt in your terminal while the first command is running; as long as the first command doesn't read input at some point it will sit in the terminal's buffer and the shell will read it when the first program ends


Using the wait command

$ sleep 10 &
[1] 29703
$ wait 29703 && echo hello
[1]+  Done                    sleep 10

Your Answer

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

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