Friday, March 12, 2010

I forgot to run a command in the background - Cool trick

I forgot to run a shell command in the background and I want to leave!

Found a cool bash trick (amongst others) at this site
http://stackoverflow.com/questions/211378/hidden-features-of-bash

So I run this command and I forgot to append the ampersand to background it.
What do I do? Kill the job and start over? Not a great option if the command
has already done a lot of work and you don't or can't have it start over.

The first thing to do is to stop/suspend the job with control-Z
Find out the pid of the stopped job then use the 'bg' command to send
it to the background. Now use the 'disown' command with the -h flag.
ie. disown -h pid

No comments:

Post a Comment