Last night i started downloading all of Fedora core via rsync. It was getting late, so I put it in the background and logged out. i just logged in this morning, and wanted to see where it was at, so I typed “jobs”, but surprise, it isn’t there. I know it’s still running, because the lights on my hub are still blinking, it shows up in “top”, and i can see (du -bs fedora/) that the folder is still growing. How do i get the output back on my terminal?
First, the bad news. Once you’ve disassociated a running application from an input or output device, you can’t get it back. Hopefully it’s all working without a glitch so that’s not a big problem.
Now, let me explain what happened with your Linux process and show you how to avoid this problem in the future.
When you log in to your computer, your shell creates three I/O channels that are then used by all running applications spawned by (that is, launched from within) the shell unless specified otherwise. They are stdin (standard input), stdout (standard output, for all non-error message output), and stderr (standard error, only for error messages).
When you launched the rsync process, it was assigned the same three channels as an ls or who command would have been given. Since rsync doesn’t require any input, that was safely ignored, but as you know, stdout was going to your terminal window or screen.
Putting the job into the background, accomplished by the commands ^Z and bg, severed the ties with the three I/O channels, but most likely if the program had any input or output needs, it would have gone into what’s called an I/O Block state and output a message like “stopped (waiting for input)” on your screen. Of course, you might have set your login shell to ignore those I/O blocks, in which case output from background jobs just pours onto your screen, regardless of what you’re doing.
In either case, once you logged out, the three I/O channels were destroyed, even though they were ostensibly in use by your background job. Instead, the OS typically reassigns the channels to /dev/null, meaning that while rsync keeps chugging along, it can’t get any input (not a big deal) but can’t produce any visible output either.
Got it?
Now, to avoid this problem in the future, the classic Unix way to push a job into the background is to redirect its important I/O channels along the way (well, its output channels). Here’s how I would have done it:
Then, if you want to watch it working, simply use:
and it’ll be as if you were running it directly, but it’ll survive you logging out and logging in again.
I hope that’s helpful for you, and good luck with Fedora Core too. Oh, and one last thought: you might find my best-selling book Teach Yourself Unix in 24 Hours good supplemental reading too.
please tell me the command to view the running jobs with status.
thiru
I like using the screen command to run commands that will take a long time to process. Screen creates a new shell that can be exited without hurting the environment or jobs that are running. simply type “screen” at a prompt. Then start your rsync process like normal. Press Control-A, then the letter D to detach the screen. You can exit your shell but the screen shell keeps running. Later you can log into the shell, and type screen -list to see what shells there are, and screen -r to re-attach. The screen system works great when I have to start a long job from work, go home, and then finish the job.