John Fusco9780132198578, 0132198576
The Linux Programmer
Table of contents :
The Linux programmer’s toolbox……Page 1
Contents……Page 8
Foreword……Page 18
Preface……Page 20
Acknowledgments……Page 24
About the Author……Page 26
1.1 Introduction……Page 28
1.3 What Does Open Source Mean to You?……Page 29
1.3.1 Finding Tools……Page 30
1.4 An Introduction to Archive Files……Page 31
1.4.1 Identifying Archive Files……Page 33
1.4.2 Querying an Archive File……Page 34
1.4.3 Extracting Files from an Archive File……Page 38
1.5 Know Your Package Manager……Page 39
1.5.1 Choosing Source or Binary……Page 41
1.5.2 Working with Packages……Page 43
1.6 Some Words about Security and Packages……Page 44
1.6.2 Basic Package Authentication……Page 46
1.6.3 Package Authentication with Digital Signatures……Page 48
1.6.4 GPG Signatures with RPM……Page 49
1.6.5 When You Cant Authenticate a Package……Page 52
1.7 Inspecting Package Contents……Page 54
1.7.1 How to Inspect Packages……Page 55
1.7.2 A Closer Look at RPM Packages……Page 57
1.7.3 A Closer Look at Debian Packages……Page 58
1.8 Keeping Packages up to Date……Page 60
1.8.1 Apt: Advanced Package Tool……Page 61
1.8.2 Yum: Yellowdog Updater Modified……Page 62
1.8.3 Synaptic: The GUI Front End for APT……Page 63
1.8.4 up2date: The Red Hat Package Updater……Page 64
1.9.1 Tools Used in This Chapter……Page 66
1.9.2 Online References……Page 67
2.2 Build Tools……Page 68
2.2.1 Background……Page 69
2.2.2 Understanding make……Page 71
2.2.3 How Programs Are Linked……Page 94
2.2.4 Understanding Libraries……Page 96
2.3.2 The configure Stage……Page 101
2.3.3 The Build Stage: make……Page 104
2.4 Understanding Errors and Warnings……Page 105
2.4.1 Common Makefile Mistakes……Page 106
2.4.2 Errors during the configure Stage……Page 109
2.4.3 Errors during the Build Stage……Page 110
2.4.4 Understanding Compiler Errors……Page 113
2.4.5 Understanding Compiler Warnings……Page 115
2.4.6 Understanding Linker Errors……Page 125
2.5 Summary……Page 127
2.5.2 Online References……Page 128
3.2 Online Help Tools……Page 130
3.2.1 The man Page……Page 131
3.2.2 man Organization……Page 132
3.2.3 Searching the man Pages: apropos……Page 134
3.2.4 Getting the Right man Page: whatis……Page 137
3.2.5 Things to Look for in the man Page……Page 138
3.2.6 Some Recommended man Pages……Page 139
3.2.8 Viewing info Pages……Page 142
3.2.9 Searching info Pages……Page 145
3.2.10 Recommended info Pages……Page 146
3.3 Other Places to Look……Page 147
3.3.2 Cross Referencing and Indexing……Page 148
3.3.3 Package Queries……Page 149
3.4.1 TeX/LaTeX/DVI……Page 151
3.4.2 Texinfo……Page 152
3.4.3 DocBook……Page 153
3.4.4 HTML……Page 154
3.4.5 PostScript……Page 156
3.4.6 Portable Document Format (PDF)……Page 157
3.5.1 www.gnu.org……Page 158
3.5.2 SourceForge.net……Page 159
3.5.3 The Linux Documentation Project……Page 160
3.6 Finding Information about the Linux Kernel……Page 161
3.6.1 The Kernel Build……Page 162
3.6.2 Kernel Modules……Page 164
3.7.1 Tools Used in This Chapter……Page 165
3.7.2 Online Resources……Page 166
4.1 Introduction……Page 168
4.2 The Text Editor……Page 169
4.2.1 The Default Editor……Page 170
4.2.2 What to Look for in a Text Editor……Page 171
4.2.4 Vim: vi Improved……Page 173
4.2.5 Emacs……Page 197
4.2.6 Attack of the Clones……Page 206
4.2.7 Some GUI Text Editors at a Glance……Page 209
4.2.8 Memory Usage……Page 214
4.2.9 Editor Summary……Page 215
4.3.1 Revision Control Basics……Page 216
4.3.2 Defining Revision Control Terms……Page 218
4.3.4 Introducing diff and patch……Page 220
4.3.5 Reviewing and Merging Changes……Page 224
4.4 Source Code Beautifiers and Browsers……Page 230
4.4.1 The Indent Code Beautifier……Page 231
4.4.2 Astyle Artistic Style……Page 233
4.4.3 Analyzing Code with cflow……Page 234
4.4.4 Analyzing Code with ctags……Page 237
4.4.5 Browsing Code with cscope……Page 238
4.4.6 Browsing and Documenting Code with Doxygen……Page 239
4.4.7 Using the Compiler to Analyze Code……Page 241
4.5.1 Tools Used in This Chapter……Page 243
4.5.2 References……Page 244
4.5.3 Online Resources……Page 245
5.1 Introduction……Page 248
5.2 User Mode versus Kernel Mode……Page 249
5.2.1 System Calls……Page 250
5.3 The Process Scheduler……Page 253
5.3.1 A Scheduling Primer……Page 254
5.3.2 Blocking, Preemption, and Yielding……Page 255
5.3.3 Scheduling Priority and Fairness……Page 256
5.3.4 Priorities and Nice Value……Page 261
5.3.5 Real-Time Priorities……Page 262
5.3.6 Creating Real-Time Processes……Page 265
5.3.7 Process States……Page 266
5.3.8 How Time Is Measured……Page 273
5.4.1 Device Driver Types……Page 284
5.4.2 A Word about Kernel Modules……Page 286
5.4.3 Device Nodes……Page 287
5.4.4 Devices and I/O……Page 299
5.5.1 The Linus Elevator (aka noop)……Page 309
5.5.3 Anticipatory I/O Scheduler……Page 311
5.5.5 Selecting an I/O Scheduler……Page 312
5.6.1 Virtual Memory Explained……Page 313
5.6.2 Running out of Memory……Page 330
5.7.1 Tools Used in This Chapter……Page 342
5.7.4 References……Page 343
6.2 Where Processes Come From……Page 344
6.2.1 fork and vfork……Page 345
6.2.2 Copy on Write……Page 346
6.3 The exec Functions……Page 347
6.3.1 Executable Scripts……Page 348
6.3.3 Miscellaneous Binaries……Page 351
6.4 Process Synchronization with wait……Page 354
6.5 The Process Footprint……Page 356
6.5.1 File Descriptors……Page 358
6.5.2 Stack……Page 365
6.5.3 Resident and Locked Memory……Page 366
6.6 Setting Process Limits……Page 367
6.7 Processes and procfs……Page 370
6.8.1 Displaying Process Information with ps……Page 373
6.8.2 Advanced Process Information Using Formats……Page 376
6.8.3 Finding Processes by Name with ps and pgrep……Page 379
6.8.4 Watching Process Memory Usage with pmap……Page 380
6.8.5 Sending Signals to Processes by Name……Page 381
6.9 Summary……Page 382
6.9.3 Online Resources……Page 383
7.1 Introduction……Page 384
7.2 IPC Using Plain Files……Page 385
7.2.1 File Locking……Page 389
7.3 Shared Memory……Page 390
7.3.1 Shared Memory with the POSIX API……Page 391
7.3.2 Shared Memory with the System V API……Page 394
7.4 Signals……Page 397
7.4.2 Handling a Signal……Page 398
7.4.3 The Signal Mask and Signal Handling……Page 400
7.4.4 Real-Time Signals……Page 403
7.4.5 Advanced Signals with sigqueue and sigaction……Page 405
7.5 Pipes……Page 408
7.6 Sockets……Page 409
7.6.1 Creating Sockets……Page 410
7.6.3 Client/Server Example Using Local Sockets……Page 414
7.6.4 Client Sever Using Network Sockets……Page 419
7.7.1 The System V Message Queue……Page 420
7.7.2 The POSIX Message Queue……Page 424
7.8 Semaphores……Page 429
7.8.1 Semaphores with the POSIX API……Page 434
7.8.2 Semaphores with the System V API……Page 437
7.9.1 System Calls and APIs Used in This Chapter……Page 439
7.9.3 Online Resources……Page 441
8.2 Tools for Working with Open Files……Page 442
8.2.1 lsof……Page 443
8.2.2 fuser……Page 444
8.2.4 file……Page 445
8.2.5 stat……Page 446
8.3 Dumping Data from a File……Page 447
8.3.1 The strings Command……Page 449
8.3.2 The xxd Command……Page 450
8.3.3 The hexdump Command……Page 451
8.3.4 The od Command……Page 452
8.4.1 System V Shared Memory……Page 453
8.4.2 System V Message Queues……Page 456
8.4.3 System V Semaphores……Page 457
8.5.1 POSIX Shared Memory……Page 458
8.5.2 POSIX Message Queues……Page 459
8.5.3 POSIX Semaphores……Page 460
8.6 Tools for Working with Signals……Page 461
8.7.1 Pipes and FIFOs……Page 464
8.7.2 Sockets……Page 465
8.8 Using Inodes to Identify Files and IPC Objects……Page 467
8.9.1 Tools Used in This Chapter……Page 469
8.9.2 Online Resources……Page 470
9.2 System Performance……Page 472
9.2.1 Memory Issues……Page 473
9.2.2 CPU Utilization and Bus Contention……Page 483
9.2.3 Devices and Interrupts……Page 486
9.2.4 Tools for Finding System Performance Issues……Page 494
9.3.1 The First Step with the time Command……Page 502
9.3.2 Understanding Your Processor Architecture with x86info……Page 503
9.3.3 Using Valgrind to Examine Instruction Efficiency……Page 507
9.3.4 Introducing ltrace……Page 511
9.3.5 Using strace to Monitor Program Performance……Page 512
9.3.6 Traditional Performance Tuning Tools: gcov and gprof……Page 514
9.3.7 Introducing OProfile……Page 521
9.4.1 Types of SMP Hardware……Page 528
9.4.2 Programming on an SMP Machine……Page 533
9.5 Summary……Page 536
9.5.3 Tools Used in This Chapter……Page 537
9.5.5 References……Page 538
10.1 Introduction……Page 540
10.2.1 Problems with Using printf……Page 541
10.2.2 Using printf Effectively……Page 546
10.2.3 Some Final Words on printf Debugging……Page 555
10.3 Getting Comfortable with the GNU Debugger: gdb……Page 556
10.3.1 Running Your Code with gdb……Page 557
10.3.2 Stopping and Restarting Execution……Page 558
10.3.3 Inspecting and Manipulating Data……Page 568
10.3.5 Debugging Core Files……Page 580
10.3.6 Debugging Multithreaded Programs with gdb……Page 584
10.3.7 Debugging Optimized Code……Page 585
10.4 Debugging Shared Objects……Page 588
10.4.1 When and Why to Use Shared Objects……Page 589
10.4.2 Creating Shared Objects……Page 590
10.4.4 Overriding the Default Shared Object Locations……Page 591
10.4.6 Tools for Working with Shared Objects……Page 592
10.5.1 Double Free……Page 596
10.5.3 Buffer Overflows……Page 597
10.5.4 glibc Tools……Page 599
10.5.5 Using Valgrind to Debug Memory Issues……Page 603
10.5.6 Looking for Overflows with Electric Fence……Page 608
10.6 Unconventional Techniques……Page 610
10.6.1 Creating Your Own Black Box……Page 611
10.6.2 Getting Backtraces at Runtime……Page 614
10.6.3 Forcing Core Dumps……Page 616
10.6.4 Using Signals……Page 617
10.6.5 Using procfs for Debugging……Page 618
10.7.1 Tools Used in This Chapter……Page 621
10.7.3 References……Page 622
A……Page 624
B……Page 625
C……Page 626
D……Page 627
E……Page 629
F……Page 630
G……Page 631
I……Page 632
L……Page 634
M……Page 635
N……Page 637
O……Page 638
P……Page 639
R……Page 641
S……Page 642
T……Page 646
U……Page 647
W……Page 648
Z……Page 649
Reviews
There are no reviews yet.