| Preface |
|
vii | (6) |
| Contents |
|
xiii | (10) |
|
|
|
xxiii | |
| Part 1 Getting Started |
|
1 | (28) |
|
Chapter 1 History of Linux Development |
|
|
3 | (8) |
|
1.1 A Short History of Free Unix Software |
|
|
4 | (2) |
|
|
|
6 | (2) |
|
1.3 Basic Lineage of Unix Systems |
|
|
8 | (1) |
|
|
|
9 | (2) |
|
Chapter 2 Licenses and Copyright |
|
|
11 | (8) |
|
|
|
11 | (2) |
|
|
|
13 | (1) |
|
2.3 Free Software Licenses |
|
|
14 | (5) |
|
2.3.1 Combinations of Free and Commercial Software |
|
|
14 | (1) |
|
2.3.2 The GNU General Public License |
|
|
15 | (1) |
|
2.3.3 The GNU Library General Public License |
|
|
15 | (1) |
|
2.3.4 MIT/X-Style Licenses |
|
|
16 | (1) |
|
|
|
16 | (1) |
|
|
|
16 | (1) |
|
2.3.7 License Incompatibilities |
|
|
17 | (2) |
|
Chapter 3 More Information on Linux |
|
|
19 | (10) |
|
3.1 Overview of Linux Documentation |
|
|
19 | (4) |
|
3.1.1 The HOWTOs and mini-HOWTOs |
|
|
21 | (1) |
|
|
|
21 | (1) |
|
3.1.3 The Linux Software Map |
|
|
21 | (1) |
|
|
|
21 | (2) |
|
|
|
23 | (1) |
|
|
|
23 | (1) |
|
3.4 Linux (and Other) Newsgroups |
|
|
23 | (2) |
|
|
|
25 | (2) |
|
|
|
26 | (1) |
|
|
|
26 | (1) |
|
|
|
27 | (1) |
|
|
|
27 | (1) |
|
|
|
27 | (1) |
|
3.7 Your Distribution Vendor |
|
|
28 | (1) |
| Part 2 Development Tools and Environment |
|
29 | (62) |
|
Chapter 4 Development Tools |
|
|
31 | (16) |
|
|
|
31 | (3) |
|
|
|
33 | (1) |
|
|
|
33 | (1) |
|
|
|
34 | (6) |
|
4.2.1 Complex Command Lines |
|
|
37 | (1) |
|
|
|
38 | (1) |
|
|
|
39 | (1) |
|
|
|
40 | (7) |
|
Chapter 5 gcc Options and Extensions |
|
|
47 | (6) |
|
|
|
48 | (2) |
|
|
|
50 | (3) |
|
|
|
51 | (1) |
|
|
|
51 | (1) |
|
5.2.3 Alternative Extended Keywords |
|
|
51 | (1) |
|
|
|
51 | (2) |
|
Chapter 6 Memory Debugging Tools |
|
|
53 | (14) |
|
|
|
53 | (2) |
|
|
|
55 | (5) |
|
6.2.1 Using Electric Fence |
|
|
56 | (1) |
|
|
|
57 | (1) |
|
|
|
58 | (1) |
|
|
|
59 | (1) |
|
6.2.5 Resource Consumption |
|
|
59 | (1) |
|
|
|
60 | (2) |
|
|
|
60 | (1) |
|
6.3.2 Finding Memory Leaks |
|
|
61 | (1) |
|
|
|
62 | (5) |
|
6.4.1 Finding Memory Corruption with mcheck |
|
|
62 | (1) |
|
6.4.2 Finding Memory Leaks with mpr |
|
|
63 | (4) |
|
Chapter 7 Creating and Using Libraries |
|
|
67 | (12) |
|
|
|
67 | (1) |
|
|
|
68 | (1) |
|
7.3 Designing Shared Libraries |
|
|
69 | (3) |
|
7.3.1 Managing Compatibility |
|
|
70 | (1) |
|
7.3.2 Incompatible Libraries |
|
|
71 | (1) |
|
7.3.3 Designing Compatible Libraries |
|
|
71 | (1) |
|
7.4 Building Shared Libraries |
|
|
72 | (1) |
|
7.5 Installing Shared Libraries |
|
|
73 | (3) |
|
|
|
74 | (2) |
|
7.6 Using Shared Libraries |
|
|
76 | (3) |
|
7.6.1 Using Noninstalled Libraries |
|
|
76 | (1) |
|
7.6.2 Preloading Libraries |
|
|
77 | (2) |
|
Chapter 8 Linux Development Environment |
|
|
79 | (12) |
|
8.1 Understanding System Calls |
|
|
79 | (10) |
|
8.1.1 System Call Limitations |
|
|
80 | (1) |
|
8.1.2 System Call Return Codes |
|
|
81 | (2) |
|
|
|
83 | (1) |
|
8.1.4 Common Error Return Codes |
|
|
84 | (5) |
|
8.2 Finding Header and Library Files |
|
|
89 | (2) |
| Part 3 System Programming |
|
91 | (314) |
|
Chapter 9 The Process Model |
|
|
93 | (48) |
|
|
|
93 | (2) |
|
9.1.1 Complicating Things with Threads |
|
|
94 | (1) |
|
|
|
94 | (1) |
|
|
|
95 | (8) |
|
9.2.1 The pid and Parentage |
|
|
95 | (1) |
|
|
|
96 | (4) |
|
|
|
100 | (1) |
|
9.2.4 User and Group ID Summary |
|
|
101 | (2) |
|
|
|
103 | (6) |
|
|
|
103 | (2) |
|
|
|
105 | (2) |
|
9.3.3 Establishing Usage Limits |
|
|
107 | (2) |
|
|
|
109 | (9) |
|
|
|
109 | (1) |
|
9.4.2 Watching Your Children Die |
|
|
110 | (2) |
|
9.4.3 Running New Programs |
|
|
112 | (3) |
|
9.4.4 A Bit of History: vfork() |
|
|
115 | (1) |
|
|
|
115 | (1) |
|
|
|
116 | (1) |
|
|
|
117 | (1) |
|
|
|
118 | (3) |
|
9.5.1 Running and Waiting with system() |
|
|
118 | (1) |
|
9.5.2 Reading or Writing from a Process |
|
|
119 | (2) |
|
9.6 Sessions and Process Groups |
|
|
121 | (4) |
|
|
|
122 | (1) |
|
9.6.2 Controlling Terminal |
|
|
123 | (1) |
|
|
|
123 | (2) |
|
9.7 Introduction to ladsh |
|
|
125 | (13) |
|
9.7.1 Running External Programs with ladsh |
|
|
125 | (13) |
|
|
|
138 | (3) |
|
Chapter 10 Simple File Handling |
|
|
141 | (46) |
|
|
|
144 | (7) |
|
10.1.1 File Access Permissions |
|
|
145 | (1) |
|
10.1.2 File Permission Modifiers |
|
|
146 | (2) |
|
|
|
148 | (1) |
|
10.1.4 The Process's umask |
|
|
149 | (2) |
|
10.2 Basic File Operations |
|
|
151 | (11) |
|
|
|
151 | (1) |
|
|
|
152 | (1) |
|
10.2.3 Opening Files in the File System |
|
|
152 | (2) |
|
10.2.4 Reading, Writing, and Moving Around |
|
|
154 | (5) |
|
10.2.5 Partial Reads and Writes |
|
|
159 | (2) |
|
|
|
161 | (1) |
|
|
|
161 | (1) |
|
10.3 Querying and Changing Inode Information |
|
|
162 | (11) |
|
10.3.1 Finding Inode Information |
|
|
162 | (1) |
|
10.3.2 A Simple Example of stat() |
|
|
163 | (3) |
|
10.3.3 Easily Determining Access Rights |
|
|
166 | (1) |
|
10.3.4 Changing a File's Access Permissions |
|
|
167 | (1) |
|
10.3.5 Changing a File's Owner and Group |
|
|
167 | (1) |
|
10.3.6 Changing a File's Timestamps |
|
|
168 | (1) |
|
10.3.7 Ext2 Extended Attributes |
|
|
169 | (4) |
|
10.4 Manipulating Directory Entries |
|
|
173 | (6) |
|
10.4.1 Creating Device and Named Pipe Entries |
|
|
173 | (3) |
|
10.4.2 Creating Hard Links |
|
|
176 | (1) |
|
10.4.3 Using Symbolic Links |
|
|
177 | (1) |
|
|
|
178 | (1) |
|
|
|
179 | (1) |
|
10.5 Manipulating File Descriptors |
|
|
179 | (3) |
|
10.5.1 Changing the Access Mode for an Open File |
|
|
180 | (1) |
|
10.5.2 Modifying the close-on-exec Flag |
|
|
180 | (1) |
|
10.5.3 Duplicating File Descriptors |
|
|
181 | (1) |
|
10.6 Creating Unnamed Pipes |
|
|
182 | (1) |
|
10.7 Adding Redirection to ladsh |
|
|
183 | (4) |
|
10.7.1 The Data Structures |
|
|
183 | (1) |
|
|
|
184 | (3) |
|
Chapter 11 Directory Operations |
|
|
187 | (18) |
|
11.1 The Current Working Directory |
|
|
187 | (3) |
|
11.1.1 Finding the Current Working Directory |
|
|
187 | (2) |
|
11.1.2 The . and .. Special Files |
|
|
189 | (1) |
|
11.1.3 Changing the Current Directory |
|
|
189 | (1) |
|
11.2 Changing the Root Directory |
|
|
190 | (1) |
|
11.3 Creating and Removing Directories |
|
|
190 | (1) |
|
11.3.1 Creating New Directories |
|
|
190 | (1) |
|
11.3.2 Removing Directories |
|
|
191 | (1) |
|
11.4 Reading a Directory's Contents |
|
|
191 | (2) |
|
|
|
193 | (1) |
|
|
|
193 | (6) |
|
|
|
194 | (1) |
|
|
|
195 | (4) |
|
11.6 Adding Directories and Globbing to ladsh |
|
|
199 | (6) |
|
|
|
199 | (1) |
|
11.6.2 Adding File Name Globbing |
|
|
200 | (5) |
|
Chapter 12 Advanced File Handling |
|
|
205 | (30) |
|
12.1 Input and Output Multiplexing |
|
|
205 | (10) |
|
|
|
208 | (1) |
|
12.1.2 Multiplexing with select() |
|
|
209 | (6) |
|
|
|
215 | (8) |
|
|
|
216 | (1) |
|
12.2.2 Establishing Memory Mappings |
|
|
216 | (5) |
|
|
|
221 | (1) |
|
12.2.4 Syncing Memory Regions to Disk |
|
|
221 | (1) |
|
12.2.5 Locking Memory Regions |
|
|
222 | (1) |
|
|
|
223 | (9) |
|
|
|
224 | (2) |
|
|
|
226 | (6) |
|
|
|
232 | (1) |
|
12.4 Scatter/Gather Reads and Writes |
|
|
232 | (3) |
|
Chapter 13 Signal Processing |
|
|
235 | (22) |
|
|
|
236 | (4) |
|
|
|
236 | (2) |
|
|
|
238 | (1) |
|
13.1.3 Signals and System Calls |
|
|
239 | (1) |
|
13.2 The Linux (and POSIX) Signal API |
|
|
240 | (7) |
|
|
|
240 | (1) |
|
|
|
241 | (1) |
|
|
|
242 | (2) |
|
13.2.4 Manipulating a Process's Signal Mask |
|
|
244 | (2) |
|
13.2.5 Finding the Set of Pending Signals |
|
|
246 | (1) |
|
13.2.6 Waiting for Signals |
|
|
246 | (1) |
|
|
|
247 | (5) |
|
13.4 Writing Signal Handlers |
|
|
252 | (1) |
|
|
|
253 | (4) |
|
|
|
257 | (10) |
|
|
|
257 | (3) |
|
14.1.1 Restarting Processes |
|
|
257 | (1) |
|
14.1.2 Stopping Processes |
|
|
258 | (1) |
|
14.1.3 Handling Job Control Signals |
|
|
259 | (1) |
|
14.2 Job Control in ladsh |
|
|
260 | (7) |
|
Chapter 15 Terminals and Pseudo Terminals |
|
|
267 | (52) |
|
|
|
268 | (2) |
|
15.1.1 Controlling Terminals |
|
|
269 | (1) |
|
|
|
270 | (2) |
|
|
|
272 | (17) |
|
|
|
272 | (2) |
|
15.3.2 Serial Communications |
|
|
274 | (15) |
|
|
|
289 | (1) |
|
|
|
290 | (18) |
|
|
|
291 | (4) |
|
|
|
295 | (1) |
|
|
|
296 | (1) |
|
|
|
297 | (2) |
|
|
|
299 | (1) |
|
|
|
300 | (2) |
|
15.5.7 Control Characters |
|
|
302 | (3) |
|
|
|
305 | (2) |
|
15.5.9 Controlling read() |
|
|
307 | (1) |
|
|
|
308 | (11) |
|
15.6.1 Opening Pseudo ttys |
|
|
309 | (3) |
|
15.6.2 Pseudo tty Example |
|
|
312 | (7) |
|
Chapter 16 Networking with Sockets |
|
|
319 | (38) |
|
|
|
319 | (4) |
|
|
|
320 | (1) |
|
|
|
321 | (1) |
|
16.1.3 Making Reality Play Nice |
|
|
321 | (2) |
|
|
|
323 | (1) |
|
|
|
323 | (1) |
|
16.3 Basic Socket Operations |
|
|
324 | (5) |
|
|
|
324 | (2) |
|
16.3.2 Establishing Connections |
|
|
326 | (1) |
|
16.3.3 Binding an Address to a Socket |
|
|
326 | (1) |
|
16.3.4 Waiting for Connections |
|
|
326 | (2) |
|
16.3.5 Connecting to a Server |
|
|
328 | (1) |
|
|
|
329 | (11) |
|
16.4.1 Unix Domain Addresses |
|
|
329 | (1) |
|
16.4.2 Waiting for a Connection |
|
|
330 | (2) |
|
16.4.3 Connecting to a Server |
|
|
332 | (2) |
|
16.4.4 Running the Unix Domain Examples |
|
|
334 | (1) |
|
16.4.5 Unnamed Unix Domain Sockets |
|
|
334 | (1) |
|
16.4.6 Passing File Descriptors |
|
|
334 | (6) |
|
16.5 Networking Machines with TCP/IP |
|
|
340 | (15) |
|
|
|
340 | (2) |
|
|
|
342 | (1) |
|
16.5.3 IP Socket Addresses |
|
|
342 | (1) |
|
16.5.4 Manipulating IP Addresses |
|
|
343 | (1) |
|
|
|
344 | (2) |
|
16.5.6 Host Information Lookup Example |
|
|
346 | (2) |
|
16.5.7 Looking Up Port Numbers |
|
|
348 | (3) |
|
16.5.8 Listening for TCP Connections |
|
|
351 | (2) |
|
16.5.9 TCP Client Applications |
|
|
353 | (2) |
|
|
|
355 | (2) |
|
|
|
357 | (14) |
|
17.1 Telling Time and Dates |
|
|
357 | (9) |
|
|
|
357 | (3) |
|
17.1.2 Converting, Formatting, and Parsing Times |
|
|
360 | (5) |
|
17.1.3 The Limits of Time |
|
|
365 | (1) |
|
|
|
366 | (5) |
|
|
|
367 | (1) |
|
|
|
368 | (3) |
|
Chapter 18 Random Numbers |
|
|
371 | (4) |
|
18.1 Pseudo-Random Numbers |
|
|
371 | (1) |
|
18.2 Cryptography and Random Numbers |
|
|
372 | (3) |
|
Chapter 19 Programming Virtual Consoles |
|
|
375 | (12) |
|
|
|
376 | (3) |
|
|
|
379 | (1) |
|
19.3 Determining Whether the Terminal Is a VC |
|
|
380 | (1) |
|
19.4 Finding the Current VC |
|
|
380 | (1) |
|
19.5 Managing VC Switching |
|
|
380 | (4) |
|
19.6 Example: The open Command |
|
|
384 | (3) |
|
Chapter 20 The Linux Console |
|
|
387 | (18) |
|
20.1 Capability Databases |
|
|
388 | (2) |
|
20.2 Glyphs, Characters, and Maps |
|
|
390 | (1) |
|
20.3 Linux Console Capabilities |
|
|
391 | (11) |
|
20.3.1 Control Characters |
|
|
392 | (2) |
|
|
|
394 | (1) |
|
|
|
395 | (1) |
|
20.3.4 Complex Escape Sequences |
|
|
396 | (6) |
|
20.4 Direct Screen Writing |
|
|
402 | (3) |
| Part 4 Development Libraries |
|
405 | (68) |
|
Chapter 21 String Matching |
|
|
407 | (8) |
|
21.1 Globbing Arbitrary Strings |
|
|
407 | (1) |
|
|
|
408 | (7) |
|
Chapter 22 Terminal Handling with S-Lang |
|
|
415 | (14) |
|
|
|
416 | (3) |
|
22.1.1 Initializing S-Lang Input Handling |
|
|
417 | (1) |
|
22.1.2 Restoring the Terminal State |
|
|
417 | (1) |
|
22.1.3 Reading Characters from the Terminal |
|
|
418 | (1) |
|
22.1.4 Checking for Input with SLang_input_pending() |
|
|
418 | (1) |
|
|
|
419 | (10) |
|
22.2.1 Initializing Screen Management |
|
|
420 | (1) |
|
22.2.2 Updating the Display |
|
|
420 | (1) |
|
|
|
421 | (1) |
|
22.2.4 Finishing Screen Management |
|
|
421 | (1) |
|
22.2.5 Skeleton Screen Management |
|
|
421 | (1) |
|
22.2.6 Switching Character Sets |
|
|
422 | (1) |
|
22.2.7 Writing to the Screen |
|
|
423 | (2) |
|
22.2.8 Drawing Lines and Boxes |
|
|
425 | (2) |
|
|
|
427 | (2) |
|
Chapter 23 The Database Library |
|
|
429 | (16) |
|
|
|
429 | (2) |
|
|
|
431 | (3) |
|
|
|
431 | (1) |
|
23.2.2 Closing a Database |
|
|
432 | (1) |
|
23.2.3 Obtaining the File Descriptor |
|
|
433 | (1) |
|
23.2.4 Syncing the Database |
|
|
433 | (1) |
|
|
|
434 | (1) |
|
23.4 Reading Records Sequentially |
|
|
434 | (1) |
|
23.4.1 Reading a Particular Record |
|
|
435 | (1) |
|
23.5 Modifying the Database |
|
|
435 | (2) |
|
|
|
436 | (1) |
|
|
|
436 | (1) |
|
|
|
437 | (8) |
|
Chapter 24 Parsing Command-Line Options |
|
|
445 | (12) |
|
|
|
446 | (4) |
|
|
|
446 | (2) |
|
24.1.2 Creating a Context |
|
|
448 | (1) |
|
24.1.3 Parsing the Command Line |
|
|
449 | (1) |
|
24.1.4 Leftover Arguments |
|
|
450 | (1) |
|
|
|
450 | (2) |
|
|
|
452 | (2) |
|
24.3.1 Specifying Aliases |
|
|
453 | (1) |
|
|
|
453 | (1) |
|
24.4 Parsing Argument Strings |
|
|
454 | (1) |
|
24.5 Handling Extra Arguments |
|
|
455 | (1) |
|
|
|
455 | (2) |
|
Chapter 25 Dynamic Loading at Run Time |
|
|
457 | (6) |
|
|
|
458 | (5) |
|
|
|
461 | (2) |
|
Chapter 26 Names and the User Databases |
|
|
463 | (10) |
|
26.1 ID-to-Name Translation |
|
|
463 | (8) |
|
26.1.1 Example: The id Command |
|
|
466 | (5) |
|
26.2 Modifying the System Databases |
|
|
471 | (2) |
|
26.2.1 Pluggable Authentication Modules |
|
|
471 | (1) |
|
26.2.2 Password Database Library |
|
|
472 | (1) |
| Appendices |
|
473 | (44) |
| Appendix A Direct Access to I/O Ports |
|
475 | (4) |
| A.1 Almost Portable I/O Port Access |
|
475 | (2) |
| A.2 Direct I/O Port Access |
|
477 | (2) |
| A.2.1 The Safe Way |
|
477 | (1) |
| A.2.2 The Dangerous Way |
|
478 | (1) |
| Appendix B ladsh Source Code |
|
479 | (18) |
| Appendix C The GNU Licenses |
|
497 | (20) |
| C.1 The GNU General Public License |
|
497 | (9) |
| C.2 The GNU Library General Public License |
|
506 | (11) |
| Glossary |
|
517 | (4) |
| Bibliography |
|
521 | (4) |
| Index |
|
525 | |