Foreword p. xxxi
Introduction p. xxxiii
Getting Started p. 1
An Introduction to UNIX, Linux, and GNU p. 1
What Is UNIX? p. 1
What Is Linux? p. 3
The GNU Project and the Free Software Foundation p. 3
Linux Distributions p. 4
Programming Linux p. 5
Linux Programs p. 5
The C Compiler p. 6
Development System Roadmap p. 8
Getting Help p. 13
Summary p. 15
Shell Programming p. 17
Why Program with a Shell? p. 18
A Bit of Philosophy p. 18
What Is a Shell? p. 19
Pipes and Redirection p. 21
Redirecting Output p. 21
Redirecting Input p. 22
Pipes p. 23
The Shell as a Programming Language p. 23
Interactive Programs p. 23
Creating a Script p. 25
Making a Script Executable p. 26
Shell Syntax p. 27 Variables p. 28 Conditions p. 32 Control Structures p. 35 Functions p. 47 Commands p. 50 Command Execution p. 69 Here Documents p. 73 Debugging Scripts p. 75
Going Graphical--The Dialog Utility p. 76
Putting It All Together p. 80
Requirements p. 81
Design p. 81
Summary p. 90
Linux File Structure p. 92
Directories p. 92
Files and Devices p. 93
System Calls and Device Drivers p. 94
Library Functions p. 95
Low-Level File Access p. 96
write p. 96
read p. 97
open p. 98
Initial Permissions p. 100
Other System Calls for Managing Files p. 104
The Standard I/O Library p. 107
fopen p. 108 fread p. 108 fwrite p. 109 fclose p. 109 fflush p. 109 fseek p. 110
fgetc, getc, and getchar p. 110
fputc, putc, and putchar p. 110
fgets and gets p. 111
Formatted Input and Output p. 111
Printf, fprintf, and sprintf p. 112
Scanf, fscanf, and sscanf p. 114
Other Stream Functions p. 116
Stream Errors p. 117
Streams and File Descriptors p. 118
File and Directory Maintenance p. 118
chmod p. 118
chown p. 119
unlink, link, and symlink p. 119
mkdir and rmdir p. 119
chdir and getcwd p. 120
perror p. 126
The /proc File System p. 126
Advanced Topics: fcntl and mmap p. 130
fcntl p. 130
mmap p. 131
Summary p. 134
The Linux Environment p. 135
Program Arguments p. 135
getopt p. 138
getopt_long p. 140
Environment Variables p. 142
Use of Environment Variables p. 144
The environ Variable p. 145
Time and Date p. 146
Temporary Files p. 153
User Information p. 155
Host Information p. 158
Logging p. 160
Resources and Limits p. 164
Summary p. 169
Terminals p. 171
Reading from and Writing to the Terminal p. 171
Talking to the Terminal p. 176
The Terminal Driver and the General Terminal Interface p. 178
Overview p. 178
Hardware Model p. 179
The termios Structure p. 180
Input Modes p. 181
Output Modes p. 182
Control Modes p. 183
Local Modes p. 183
Special Control Characters p. 184
Terminal Speed p. 187
Additional Functions p. 188
Terminal Output p. 191
Terminal Type p. 191
Identify Your Terminal Type p. 192
Using terminfo Capabilities p. 195
Detecting Keystrokes p. 200
Virtual Consoles p. 202
Summary p. 204
Managing Text-Based Screens with curses p. 205
Compiling with curses p. 206
Concepts p. 207
Initialization and Termination p. 210
Output to the Screen p. 210
Reading from the Screen p. 211
Clearing the Screen p. 211
Moving the Cursor p. 212
Character Attributes p. 212
The Keyboard p. 214
Keyboard Modes p. 215
Keyboard Input p. 215
Windows p. 217
The WINDOW Structure p. 217
Generalized Functions p. 218
Moving and Updating a Window p. 218
Optimizing Screen Refreshes p. 222
Subwindows p. 223
The Keypad p. 225
Color p. 227
Redefining Colors p. 230
Pads p. 230
The CD Collection Application p. 233
Summary p. 247
Data Management p. 249
Managing Memory p. 249
Simple Memory Allocation p. 250
Allocating Lots of Memory p. 251
Abusing Memory p. 254
The Null Pointer p. 255
Freeing Memory p. 256
Other Memory Allocation Functions p. 257
File Locking p. 258
Creating Lock Files p. 258
Locking Regions p. 262
Use of read and write with Locking p. 264
Competing Locks p. 270
Other Lock Commands p. 273
Deadlocks p. 273
The dbm Database p. 274
The dbm Routines p. 276
dbm Access Functions p. 277
Additional dbm Functions p. 280
The CD Application p. 282
Updating the Design p. 283
The CD Database Application Using dbm p. 283
Summary p. 302 MySQL p. 303 Installation p. 304 Precompiled Packages p. 304 Post-Install Configuration p. 306 Post-Installation Troubleshooting p. 310 MySQL Administration p. 310 Commands p. 310
Creating Users and Giving Them Permissions p. 314
Passwords p. 316
Creating a Database p. 317
Data Types p. 318
Creating a Table p. 319
Graphical Tools p. 322
Accessing MySQL Data from C p. 325
Connection Routines p. 326
Error Handling p. 330
Executing SQL Statements p. 331
Miscellaneous Functions p. 346
The CD Database Application p. 347
Creating the Tables p. 348
Adding Some Data p. 350
Accessing the Application Data from C p. 353
Summary p. 363
Development Tools p. 365
Problems of Multiple Source Files p. 365
The make Command and Makefiles p. 366
The Syntax of Makefiles p. 366
Options and Parameters to make p. 367
Comments in a Makefile p. 370
Macros in a Makefile p. 370
Multiple Targets p. 372
Built-in Rules p. 374
Managing Libraries with make p. 376
Advanced Topic: Makefiles and Subdirectories p. 378
GNU make and gcc p. 378
Source Code Control p. 379
RCS p. 380 SCCS p. 386 Comparing RCS and SCCS p. 386 CVS p. 386 gCVS p. 390 BitKeeper p. 391
Writing a Manual Page p. 391
Distributing Software p. 395
The patch Program p. 395
Other Distribution Utilities p. 397
RPM Packages p. 399
Working with RPM Package Files p. 400
Installing RPM Packages p. 400
Building RPM Packages p. 401
Other Package Formats p. 410
Development Environments p. 410 xwpe p. 410 C-Forge p. 411 KDevelop p. 412 Other Environments p. 414 Summary p. 415 Debugging p. 417 Types of Errors p. 417
General Debugging Techniques p. 418
A Program with Bugs p. 418
Code Inspection p. 421 Instrumentation p. 422 Controlled Execution p. 424 Debugging with gdb p. 425 Starting gdb p. 425 Running a Program p. 426 Stack Trace p. 427 Examining Variables p. 427
Listing the Program p. 428
Setting Breakpoints p. 429
Patching with the Debugger p. 432
More Debugging Tools p. 434
Lint: Removing the Fluff from Your Programs p. 434
Function Call Tools p. 436
Execution Profiling with prof/gprof p. 438
Assertions p. 439
Memory Debugging p. 440
ElectricFence p. 441
valgrind p. 442
Summary p. 444
Processes and Signals p. 445
What Is a Process? p. 445
Process Structure p. 446
The Process Table p. 447
Viewing Processes p. 447
System Processes p. 449
Process Scheduling p. 450
Starting New Processes p. 451
Waiting for a Process p. 458
Zombie Processes p. 460
Input and Output Redirection p. 462
Threads p. 463 Signals p. 463 Sending Signals p. 467 Signal Sets p. 471 Summary p. 476 POSIX Threads p. 477 What Is a Thread? p. 477
Advantages and Drawbacks of Threads p. 478
A First Threads Program p. 479
Simultaneous Execution p. 483
Synchronization p. 485
Synchronization with Semaphores p. 485
Synchronization with Mutexes p. 490
Thread Attributes p. 494
Canceling a Thread p. 498
Threads in Abundance p. 501
Summary p. 504
Inter-Process Communication: Pipes p. 505
What Is a Pipe? p. 505
Process Pipes p. 506
Passing More Data p. 509
How popen Is Implemented p. 510
The Pipe Call p. 511
Parent and Child Processes p. 514
Reading Closed Pipes p. 516
Pipes Used as Standard Input and Output p. 517
Named Pipes: FIFOs p. 520
Accessing a FIFO p. 522
Advanced Topic: Client/Server Using FIFOs p. 529
The CD Database Application p. 533
Aims p. 534
Implementation p. 534
Client Interface Functions p. 538
The Server Interface p. 544
The Pipe p. 548
Application Summary p. 554
Summary p. 555
Semaphores, Shared Memory, and Message Queues p. 557
Semaphores p. 557
Semaphore Definition p. 558
A Theoretical Example p. 559
Linux Semaphore Facilities p. 560
Using Semaphores p. 563 Shared Memory p. 566 shmget p. 568 shmat p. 568 shmdt p. 569 shmctl p. 569 Message Queues p. 573 msgget p. 574 msgsnd p. 574 msgrcv p. 575 msgctl p. 576
The CD Database Application p. 579
IPC Status Commands p. 583
Socket Connections p. 588
Socket Attributes p. 592
Creating a Socket p. 594
Socket Addresses p. 595
Naming a Socket p. 596
Creating a Socket Queue p. 596
Accepting Connections p. 597
Requesting Connections p. 597
Closing a Socket p. 598
Socket Communications p. 598
Host and Network Byte Ordering p. 601
Network Information p. 602
The Internet Daemon (inetd) p. 608
Socket Options p. 609 Multiple Clients p. 610 select p. 613 Multiple Clients p. 616 Datagrams p. 619 Summary p. 622
Programming GNOME Using GTK+ p. 623
Introducing X p. 623 X Server p. 624 X Client p. 624 X Protocol p. 624 Xlib p. 624 Toolkits p. 625 Window Managers p. 625
Other Ways to GUI--Platform-Independent Windowing APIs p. 625
Introducing GTK+ p. 626
GLib Type System p. 626
GTK+ Object System p. 627
Introducing GNOME p. 628
Installing the GNOME/GTK+ Development Libraries p. 629
Events, Signals, and Callbacks p. 632
Packing Box Widgets p. 635
GNOME Widgets p. 652
GNOME Menus p. 653
Dialogs p. 658
GtkDialog p. 658
Modal Dialog Box p. 660
Nonmodal Dialogs p. 661
GtkMessageDialog p. 662
CD Database Application p. 663
Summary p. 675
Programming KDE Using Qt p. 677
Introducing KDE and Qt p. 677
Installing Qt p. 678
Signals and Slots p. 681
Qt Widgets p. 688 QLineEdit p. 688 Qt Buttons p. 691 QComboBox p. 695 QListView p. 699 Dialogs p. 701 QDialog p. 702 QMessageBox p. 704 QInputDialog p. 705
Using qmake to Simplify Writing Makefiles p. 707
Menus and Toolbars p. 708
CD Database Application Using KDE/Qt p. 711
Summary p. 720
Device Drivers p. 721
Writing Device Drivers p. 721
Devices p. 722
Device Classes p. 723
User and Kernel Space p. 724
Character Devices p. 729
File Operations p. 730
A Sample Driver: schar p. 732
How schar Behaves p. 750
Time and Jiffies p. 750
Small Delays p. 752
Timers p. 752
Giving Up the Processor p. 755
Task Queues p. 756
Memory Management p. 758
Virtual Memory Areas p. 759
Address Space p. 759
Types of Memory Locations p. 760
Getting Memory in Device Drivers p. 761
Transferring Data between User and Kernel Space p. 763
Moving More Data p. 764
Simple Memory Mapping p. 765
I/O Memory p. 766
Assignment of Devices in Iomap p. 768
I/O Memory mmap p. 768
I/O Ports p. 771
Interrupt Handling p. 772
The IRQ Handler p. 775
Bottom Halves p. 776
Re-entrancy p. 777
Disabling Single Interrupts p. 778
Atomicity p. 779
Protecting Critical Sections p. 780
Block Devices p. 781
radimo--A Simple RAM Disk Module p. 782
Media Change p. 785
ioctl for Block Devices p. 785
The request Function p. 786
The Buffer Cache p. 788
Going Further p. 790
Debugging p. 790
Oops Tracing p. 790
Debugging Modules p. 792
The Magic Key p. 793
Kernel Debugger--kdb p. 793
Remote Debugging p. 794
General Notes on Debugging p. 794
Portability p. 795
Data Types p. 795
Endianess p. 795
Alignment p. 796
Anatomy of the Kernel Source p. 796
Summary p. 797
Standards for Linux p. 799
A Brief History Lesson p. 800
The GNU Compiler Collection p. 801
gcc Options p. 801
Interfaces and the LSB p. 803
LSB Standard Libraries p. 804
LSB Users and Groups p. 805
LSB System Initialization p. 805
The Filesystem Hierarchy Standard p. 807
/bin p. 808 /boot p. 808 /dev p. 808 /etc p. 809 /home p. 809 /lib p. 809 /mnt p. 809 /opt p. 809 /root p. 809 /sbin p. 809 /tmp p. 809 /usr p. 810 /var p. 810
Further Reading about Standards p. 810
Summary p. 810
Index p. 811