Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use CentOS and I have a little bit of difficulty with background tasks

When something like updatedb command is running, I press CTRL+Z, instead of running in the background it immediately says

[1]+  Stopped                 updatedb

Which I assume means the task has stopped, well this upsets me a little bit I thought CTRL+Z sends the task to background not stop it.

Then I use the bg command and it returns

[1]+ updatedb  &

And then it seems like the task is continuing in the background, but the problem is if the task has some standard output it will be shown on the display! Making the command shell almost useless.

I know I can redirect the standard output to a file or dev null or something but why all this pain to do a simple task? What's a better way of doing the same?

I mean not adding & at the end of the command but just sending the current process to the background and having it not be annoying in CentOS?

share|improve this question
not really sure what you're asking. redirecting to a file removes the output, and it's hardly much hassle ? – Sirex Jun 27 '13 at 22:46
Yeah, it isn't that hard to do updatedb &> /dev/null. Or just have a shell tab with that if you'd rather just hit Shift+Ctrl+T. Or add & disown after the /dev/null so your background process doesn't get killed with the shell. Or make an alias for the command to save you the typing. (I.e. alias updb="updatedb &> /dev/null & disown") – nerdwaller Jun 27 '13 at 22:53
Sirex, here is why it's a hassle, you already are running a script for two hours, you press CTRL+Z, you don't want it to run from the beginning, and it makes shell impossible to use. So you have to terminate the process, and rerun it with output redirects, wait another 2 hours to get where you were before, make sense? – user893730 Jun 27 '13 at 22:55
@user893730 - That doesn't make sense, because now you are aware of the issue and can type the command before you get 2hrs in and have that headache... – nerdwaller Jun 27 '13 at 22:56
Another reason it's annoying is that sometimes you can't simply redirect the output, because some commands wait for your input after you run them, so now you have to create an input file, redirect both input and output, and basically create two files to do a simple thing. – user893730 Jun 27 '13 at 22:56

You can use screen or tmux. They will allow you to work with virtual terminals.

So you can start updatedb in a terminal an continue to work in another virtual terminal.

share|improve this answer
Will screen stop working if your ssh session is disconnected? – user893730 Jun 28 '13 at 0:33
In screen you can "detach" a terminal. If you terminal is detach you'll be able to close you ssh session, come back later and get every screen terminals you had detach in your previous ssh session. Here is a screen tutorial – Just1602 Jun 28 '13 at 0:40
and screen detaches by default when ssh loses connection, for clarity. – Sirex Jun 30 '13 at 3:21
I'm not sure, but I think you have to detach your screen before closing your ssh connection. – Just1602 Jul 1 '13 at 22:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .