Move a Running Command to a Background Process

time-saving-strategies

You just kicked off a command on the command line and one of three things happens:

  1. You have to leave your computer and run off to a meeting or go talk to your boss,
  2. You realize you’ve made a terrible mistake and didn’t realize how much data or work that command has to deal with and it’s probably going to take a few hours,
  3. You were testing a command, liked that it was working, and want to let it run now

Now what?

If you just let it keep running in the foreground, your session could end and any work it’s not yet completed is left in some limbo-area. It might be hard to recover or restart work that’s already begun.

With the command’s output flying past you on the screen, I present to you, your savior:

<CTRL-Z>
bg
disown %1

*Note this works on Centos, not necessarily every other OS*

This is one of those things I regret just now discovering. Especially because I find myself needing it so often. Doing things with big data on the command line can just take a while. Being able to run a command, see that it’s running well, and then throw it to a background process is remarkably freeing.

I remember one evening starting a command around 4:30pm not realizing the time. It was going to take ~3 hours to run, so I left my laptop open in my passenger seat of my car on my way home. My life could have been much easier had I known this.

Anyways, <CTRL-Z> suspends the command, ‘bg’ sends the most recent job to the background of your current shell, and ‘disown %1’ moves that job outside of your current shell.

You’re now free to move about the office.


Do you know a great time-saving command in Linux or with Hadoop? Share it below!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s