2

I know there are two or more ways to run a job and place it in the background.

Right now I used ctrl-z to put a scp transfer in the background because I noticed it was going to take a while. How do I run the process in the background so I can write other commands while I wait until it's done?

Note: I can create a new terminal however in this case I SSH'd into 2 different servers so it's inconvenient to do this for each concurrent job I want in the background.

4 Answers4

9

It's important to note that while some processes take CTRL+Z to mean background, the default behavior is STOP, which does not continue execution. The safest way is to run the command with an & at the end, then run "disown" to force it to the background completely. You will not be able to foreground it again, however.

If you want an easy way to keep an eye on background tasks, consider learning about screen. As a basic lesson, type screen scp myfile server:/mydest, then type CTRL+A D to "detach" the screen session. You can recall this session by typing "screen -r", even after logging off the machine! :)

screen has many more advanced features, such as multiple windows, an active taskbar, etc. Here's a guide: link

Kyle Smith
  • 9,808
6

After you've used ^Z to STOP something, type "bg" to let it run in the background. "fg" will bring it back to front, as long as you haven't logged out.

Bill Weiss
  • 11,266
1

To background commands just add & after the command.

CosmicQ
  • 123
1

I would recommend running programs like scp in screen. The reason is that by putting the command in the background, it will dump output into your current terminal and you can't easily disconnect from an ssh session and reconnect to it in the middle of your job.

Run screen. You'll get new terminal in front of you. Run your process. Now press "ctrl-a d" and you should get a line saying

[Screen detached]

You can reconnect to your screen by running:

# screen -r

You should get your original terminal back.

David Pashley
  • 23,963