Here’s a small UNIX tip (or how-to) for executing a command in the background. For UNIX gurus, this tip might seem like a basic one. But for guys like me who are coming from a Windows background, even smaller ones makes a big difference.
This is the scenario – I use Putty to login to UNIX. I execute few (internal) UNIX commands which are time thirtsy and take at least 2 hours to complete. While the command is running, I can’t do anything in the Putty terminal. All I can do is stare the Putty for 2 hours or do the below, to reuse the Putty session for other tasks while running the time-thirsty command in the background.
- In UNIX shell, type your command and hit Enter.
$ my-long-running-command ...... the long-running command running .....
- Your command will start running. Now press
Ctrl + z. This will interrupt the current process and pauses it. You’ll see something like this;[1]+ Stopped my-long-running-command
- Now , type
bgand hit Enter. Your current process (i.e. the command) will start running in the background. To check, typejobsin the command line and hit Enter. You’ll see the job status something like this.$ bg [1]+ my-long-running-command $jobs [1]- Running my-long-running-command
So, now you can use Putty for other tasks, while your command executes in the background.



{ 5 comments… read them below or add one }
have you tried & to send a job to background? I have never used Putty.
$sleep 15 &
[1] 1234
$sleep 10 &
[2] 5678
$fg 5678
sleep 10
cool. that’s a useful shortcut. it works in Putty too.
typically appending an & to the end of the command would do!
However it is a diff way you had suggested!
yes. I’m finding & method more quick and handy.
Thats great
Glad to hear that!!