Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

My background jobs in Linux have become invisible?

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?


Dave's Answer:

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:

$ nohup rsync args > /tmp/rsync.log &

Then, if you want to watch it working, simply use:

$ tail -f /tmp/rsync.log

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.



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

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.

Posted by: Michael Clark at October 17, 2005 1:20 PM

please tell me the command to view the running jobs with status.

thiru

Posted by: thirumurugan at August 10, 2007 7:55 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]