13.07.2015 Views

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

Linux System Administration Recipes A Problem-Solution Approach

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 11 ■ TRACKING DOWN BUGSThis will show only the lines that differ, so there’s less clutter on the screen, and it’s easier to read.Here’s some example output showing a single line (plus one blank line) added in hosts-client1:> 10.0.0.10 extrahost>However, this way you don’t get any context for the changed lines (the -C switch is not compatiblewith -y output), which may or may not be problematic, depending on what file you’re looking at andwhat you’re looking for.■ Note Another alternative is to use vimdiff or gvimdiff; both use syntax highlighting to show you thedifferences in the files. This is rather easier to read, as a rule, than the standard diff output, and because it opensup a vim editor window showing both files side by side, it also allows you to navigate through the files and editthem as required while highlighting the differences. In particular, if you’re using a graphical interface, gvimdiffallows you to change the sizes of the windows on the fly, which can be handy for looking more closely at what’sgoing on in the file. ediff mode in GNU emacs works similarly.11-4. Running strace to Look at <strong>System</strong> Callsstrace is a useful little program and is installed by default on most <strong>Linux</strong> systems. It allows you to take alook at the system calls being made by a program.■ Note It doesn’t provide a stack trace, name notwithstanding. It just traces system calls.It’s very useful as a basic debugging tool, helping you work out where a program is crashing or whatproblems it’s having. In fact, it’s also interesting to use even if you’re not tracing a problem, because itcan help you find out more about what your system is doing.It’s important to remember that user programs on a modern system run in a little circumscribedarea within the system. They’re not permitted to interact directly with the computer (so you can’t justshove numbers into registers and have Things Happen, unless you’re root). Instead, everything goesthrough the kernel, and it’s these messages to the kernel that strace is tracking. So, if there’s no straceoutput for a while, don’t assume that your program is stuck and that that’s where the bug is. It might justbe working within its own sandbox and not need to talk to the kernel for a while. Having said that, if thestrace output does pause and you can’t obviously see why from eyeballing the program, it’s probablyworth taking a look at the last few system calls to see whether anything looks problematic.The basic strace command is strace program, but strace -o output.txt program is a better bet.This will send the (copious quantities of) output to output.txt rather than straight to the screen, makingit easier to deal with.218Download at WoweBook.Com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!