Job Control

^Z $bg $disown
You're running a script, command, whatever.. You don't expect it to take long, now 5pm has rolled around and you're ready to go home... Wait, it's still running... You forgot to nohup it before running it... Suspend it, send it to the background, then disown it... The ouput wont go anywhere, but at least the command will still run...
Sample Output
$ sleep 100

[1]+  Stopped                 sleep 100
$ bg
[1]+ sleep 100 &
$ disown
$ logoff

Another TTY:
$ ps -ef | grep sleep100
16334 12453  0 16:48 pts/0    00:00:00 sleep 100

By: fall0ut
2009-03-17 21:52:52

2 Alternatives + Submit Alt

What Others Think

and the values for "$bg" and "$disown" would be?
linuxrawkstar · 657 weeks and 6 days ago
Thank you very much for the pointer to 'disown'. Now I can get rid of the '[1]+ Done' messages I receive from background tasks in my local.start script.
Alanceil · 657 weeks and 6 days ago
PS: @linuxrawkstar: bg and disown without values will affect your last job, for options see the bash man page: disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.
Alanceil · 657 weeks and 6 days ago
the $ signs in front of the bg and disown commandos are just wrong.
cran · 657 weeks and 5 days ago
@cran - I figured as much. Misleading and detrimental.
linuxrawkstar · 657 weeks and 5 days ago
ok for this to work: 1) start long running process 2) hit CTRL+Z 3) type bg 4) type disown -h 5) close terminal -- test it by reopening terminal and grepping for the process in the process table (ps -afx)
linuxrawkstar · 657 weeks and 5 days ago
Ok, disown was unknown to me. thanks!
unixmonkey2431 · 657 weeks and 4 days ago
Looking up the manpage for bash, disown is mentioned, to my surprise. Reminds me what my unix sensei taught me: never forget to try the manpages. After some googling, the best way to do this in one swoop is to use the 'nohup' command, which is a program (part of GNU coreutils), and is not built-in to bash: nohup command & That will have the effect of disown-ing the process, avoiding it dying when the launching shell dies and backgrounding it at the same time.
bwoodacre · 657 weeks and 4 days ago
How can I get the process to be 'own'ed by another shell ?
naseer · 657 weeks and 1 day ago
@naseer: That's impossible without running the process in something like GNU Screen ahead of time. However, it is possible in BSD to do sudo watch -W <tty path> and "reattach" to another tty. A program called "ttysnoop" should allow similar behavior, but I'm not very familiar with it. In the end, it's impossible to "re-own" a regular job after it's been disowned.
woxidu · 656 weeks and 3 days ago
Just to clarify for linux users: BSD's "watch" is completely different from Linux's "watch"
woxidu · 656 weeks and 3 days ago
What about correcting the command so that it actually works? The version of linuxrawkstar worked.
Svish · 656 weeks and 2 days ago
In this case the command isn't a one-liner, it's a several-liner. What is our procedure for handling something like this? Still a good thing to know, though.
nitehawk · 652 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: