|
|
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? 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.
More Useful Unix and Linux Help Articles:
✔ Copy and Paste from the Mac OS X Command Line?
I am constantly running commands in Terminal.app on my MacBook and then copying and pasting the results into email messages or documents. Yes,...
✔ Shell script to convert lowercase to title case?As part of a project I'm working on, I find myself deep in a Linux shell script, needing to have a subroutine that...
✔ Can I script renaming files based on an XML data map?I have a folder full of files which are named with four digits and a file extension e.g. 0312.file and an XML-file describing...
✔ Test for valid numbers in a Bash shell script?In a different discussion on this site [see Redirecting input in a shell script] a visitor commented that "I was too busy trying...
✔ Review: iSSH for the iPad/iPhoneIf you're running an online business like I am, there are times when you need to connect and log in to the server...
Let's stay in touch!
Sign up for my weekly AskDaveTaylor Newsletter and you'll receive even more tech and gadget help
right to your inbox, along with exclusive news and industry updates. It's good stuff. I promise!
Categorized:
Unix and Linux Help
(Article 4234,
Written by Dave Taylor)
Tagged: Previous: Can someone track when I'm logged into Yahoo? Next: How do I know what printing of a book I have? Reader Comments To Date: 2thirumurugan said, on August 10, 2007 7:55 PM:
please tell me the command to view the running jobs with status. thiru
I do have a comment, now that you mention it!Check This Out Too... |
Recent Entries
Look for Answers
Recommended
All Our Categories
Apple iPad Help
Articles and Reviews Auctions and Online Shopping Blogs and Blogging Building Web Site Traffic Business and Management Computer and Internet Basics d) None of the Above Facebook Help Google Gmail Help Google Plus Help HTML, JavaScript and Web Site Programming Industry News and Trade Shows iPhone and Cell Phone Help iPod, Sony PSP and MP3 Player Help Kindle Fire Help Mac OS X Help Pay Per Click (PPC) Advertising Pinterest Help Search Engine Optimization (SEO) Shell Script Programming Tech Support Video Help The Writing Business Twitter, LinkedIn and Social Network Help Unix and Linux Help Video Game Tips and Help Windows PC Help Find Me on Google+ ADT on G+ |
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.