I Fundamentals 1
1 Technology’s Impact on Programs 3
1.1 TerminologyofChange 4
1.2 Time andSpeed 5
1.3 Multiprogramming and Time Sharing 7
1.4 Concurrency at the Applications Level 9
1.5 Security and Fault Tolerance 13
1.6 Buffer Overflows for Breaking and Entering 14
1.7 UNIXStandards 18
1.8 AdditionalReading 20
2 Programs, Processes and Threads 21
2.1 How a Program Becomes a Process 22
2.2 Threads andThreadofExecution 23
2.3 Layout of a Program Image 24
2.4 LibraryFunctionCalls 26
2.5 Function Return Values and Errors 29
2.6 ArgumentArrays 31
2.7 Thread-SafeFunctions 38
2.8 UseofStaticVariables 40
2.9 StructureofStaticObjects 42
2.10 Process Environment 48
2.11 Process Termination 51
2.12 Exercise: An env Utility 54
2.13 Exercise: Message Logging 55
2.14 AdditionalReading 56
3 Processes in UNIX 59
3.1 Process Identification 60
3.2 ProcessState 61
3.3 UNIX Process Creation and fork 64
3.4 The wait Function 71
3.5 The exec Function 78
3.6 Background Processes and Daemons 84
3.7 Critical Sections 86
3.8 Exercise: Process Chains 87
3.9 Exercise: Process Fans 88
3.10 AdditionalReading 89
4 UNIX I/O 91
4.1 DeviceTerminology 92
4.2 Reading and Writing 92
4.3 OpeningandClosingFiles 102
4.4 The select Function 107
4.5 The pollFunction 116
4.6 File Representation 119
4.7 Filters and Redirection 128
4.8 FileControl 132
4.9 Exercise: Atomic Logging 135
4.10 Exercise: A cat Utility 141
4.11 AdditionalReading 143
5 Files and Directories 145
5.1 UNIXFileSystemNavigation 146
5.2 Directory Access 152
5.3 UNIX File System Implementation 158
5.4 Hard Links and Symbolic Links 162
5.5 Exercise: The which Command 173
5.6 Exercise: Biffing 174
5.7 Exercise: News biff 177
5.8 Exercise: Traversing Directories 179
5.9 AdditionalReading 181
6 UNIX Special Files 183
6.1 Pipes 184
6.2 Pipelines 188
6.3 FIFOs 192
6.4 Pipes and the Client-Server Model 196
6.5 TerminalControl 203
6.6 AudioDevice 214
6.7 Exercise:Audio 219
6.8 Exercise: Barriers 221
6.9 Exercise: The stty Command 223
6.10 Exercise: Client-Server Revisited 223
6.11 AdditionalReading 223
7 Project: The Token Ring 225
7.1 RingTopology 226
7.2 RingFormation 227
7.3 RingExploration 234
7.4 SimpleCommunication 236
7.5 MutualExclusionwithTokens 237
7.6 MutualExclusionbyVoting 238
7.7 Leader Election on an Anonymous Ring 239
7.8 TokenRingforCommunication 241
7.9 Pipelined Preprocessor 243
7.10 Parallel Ring Algorithms 246
7.11 FlexibleRing 250
7.12 AdditionalReading 251
II Asynchronous Events 253
8 Signals 255
8.1 BasicSignalConcepts 256
8.2 GeneratingSignals 256
8.3 Manipulating Signal Masks and Signal Sets 261
8.4 Catching and Ignoring Signals—sigaction 267
8.5 Waiting for Signals—pause, sigsuspend and sigwait 273
8.6 Handling Signals: Errors and Async-signal Safety 283
8.7 Program Control with siglongjmp and sigsetjmp 286
8.8 Programming with Asynchronous I/O 288
8.9 Exercise:DumpingStatistics 299
8.10 Exercise: Spooling a Slow Device 299
8.11 AdditionalReading 300
9 Times and Timers 301
9.1 POSIXTimes 302
9.2 SleepFunctions 314
9.3 POSIX:XSI IntervalTimers 315
9.4 Realtime Signals 320
9.5 POSIX:TMRIntervalTimers 324
9.6 Timer Drift, Overruns and Absolute Time 329
9.7 AdditionalReading 339
10 Project: Virtual Timers 341
10.1 ProjectOverview 342
10.2 SimpleTimers 344
10.3 Setting One of Five Single Timers 347
10.4 Using Multiple Timers 357
10.5 A Robust Implementation of Multiple Timers 363
10.6 POSIX:TMRTimer Implementation 367
10.7 mycron, a Small Cron Facility 367
10.8 AdditionalReading 368
11 Project: Cracking Shells 369
11.1 BuildingaSimpleShell 370
11.2 Redirection 374
11.3 Pipelines 376
11.4 Signal Handling in the Foreground 380
11.5 Process Groups, Sessions and Controlling Terminals 386
11.6 Background Processes in ush 391
11.7 JobControl 398
11.8 Job Control for ush 402
11.9 AdditionalReading 405
III Concurrency 407
12 POSIX Threads 409
12.1 A Motivating Problem: Monitoring File Descriptors 410
12.2 Use of Threads to Monitor Multiple File Descriptors 411
12.3 ThreadManagement 415
12.4 ThreadSafety 431
12.5 User Threads versus Kernel Threads 433
12.6 Thread Attributes 436
12.7 Exercise: ParallelFileCopy 443
12.8 AdditionalReading 444
13 Thread Synchronization 447
13.1 POSIX Synchronization Functions 448
13.2 MutexLocks 448
13.3 At-Most-Once and At-Least-Once-Execution 461
13.4 Condition Variables 465
13.5 Signal Handling and Threads 473
13.6 Readers and Writers 478
13.7 A strerror_r Implementation 483
13.8 Deadlocks and Other Pesky Problems 483
13.9 Exercise: Multiple Barriers 485
13.10 AdditionalReading 486
14 Critical Sections and Semaphores 487
14.1 Dealing with Critical Sections 488
14.2 Semaphores 491
14.3 POSIX:SEM Unnamed Semaphores 494
14.4 POSIX:SEM Semaphore Operations 496
14.5 POSIX:SEM Named Semaphores 502
14.6 Exercise: LicenseManager 507
14.7 AdditionalReading 509
15 POSIX IPC 511
15.1 POSIX:XSI Interprocess Communication 512
15.2 POSIX:XSI Semaphore Sets 514
15.3 POSIX:XSISharedMemory 525
15.4 POSIX:XSI Message Queues 535
15.5 Exercise: POSIX Unnamed Semaphores 542
15.6 Exercise: POSIX Named Semaphores 543
15.7 Exercise: Implementing Pipes with Shared Memory 544
15.8 Exercise: Implementing Pipes with Message Queues 547
15.9 AdditionalReading 548
16 Project: Producer Consumer Synchronization 549
16.1 The Producer-Consumer Problem 550
16.2 Bounded Buffer Protected by Mutex Locks 551
16.3 Buffer Implementation with Semaphores 555
16.4 Introduction to a Simple Producer-Consumer Problem 560
16.5 Bounded Buffer Implementation Using Condition Variables 564
16.6 Buffers with Done Conditions 565
16.7 ParallelFileCopy 573
16.8 ThreadedPrintServer 575
16.9 AdditionalReading 580
17 Project: The Not Too Parallel Virtual Machine 581
17.1 PVM History, Terminology, and Architecture 582
17.2 The Not Too Parallel Virtual Machine 584
17.3 NTPVMProjectOverview 585
17.4 I/OandTestingofDispatcher 591
17.5 Single Task with No Input 600
17.6 SequentialTasks 601
17.7 ConcurrentTasks 604
17.8 Packet Communication, Broadcast and Barriers 605
17.9 TerminationandSignals 605
17.10 Ordered Message Delivery 606
17.11 AdditionalReading 606
IV Communication 607
18 Connection-Oriented Communication 609
18.1 TheClient-ServerModel 610
18.2 CommunicationChannels 610
18.3 Connection-Oriented Server Strategies 614
18.4 Universal Internet Communication Interface (UICI) 618
18.5 UICI Implementations of Different Server Strategies 621
18.6 UICIClients 624
18.7 Socket ImplementationofUICI 629
18.8 Host Names and IP Addresses 641
18.9 Thread-SafeUICI 649
18.10 Exercise: PingServer 652
18.11 Exercise: Transmission of Audio 653
18.12 AdditionalReading 655
19 Project: WWWRedirection 657
19.1 TheWorldWideWeb 658
19.2 Uniform Resource Locators (URLs) 658
19.3 HTTPPrimer 660
19.4 WebCommunicationPatterns 665
19.5 Pass-through Monitoring of Single Connections 672
19.6 Tunnel Server Implementation 674
19.7 ServerDriver forTesting 675
19.8 HTTPHeaderParsing 676
19.9 SimpleProxyServer 679
19.10 ProxyMonitor 680
19.11 ProxyCache 683
19.12 Gateways asPortals 684
19.13 GatewayforLoadBalancing 685
19.14 Postmortem 686
19.15 AdditionalReading 690
20 Connectionless Communication and Multicast 691
20.1 Introduction to Connectionless Communication 692
20.2 Simplified Interface for Connectionless Communication 693
20.3 Simple-RequestProtocols 697
20.4 Request-ReplyProtocols 702
20.5 Request-Reply with Timeouts and Retries 708
20.6 Request-Reply-Acknowledge Protocols 714
20.7 ImplementationofUICIUDP 715
20.8 ComparisonofUDPandTCP 724
20.9 Multicast 725
20.10 Exercise:UDPPortServer 729
20.11 Exercise: StatelessFileServer 730
20.12 AdditionalReading 732
21 Project: Internet Radio 733
21.1 ProjectOverview 734
21.2 AudioDeviceSimulation 735
21.3 UDP Implementation with One Program and One Receiver 735
21.4 UDP Implementation with Multiple Programs and Receivers 746
21.5 UDP Implementation of Radio Broadcasts 747
21.6 Multicast Implementation of Radio Broadcasts 750
21.7 TCPImplementationDifferences 750
21.8 Receiving Streaming Audio Through a Browser 755
21.9 AdditionalReading 759
22 Project: Server Performance 761
22.1 ServerPerformanceCosts 762
22.2 ServerArchitectures 762
22.3 ProjectOverview 767
22.4 Single-ClientDriver 767
22.5 Multiple-Client Driver 771
22.6 Thread-per-request and Process-per-request Implementations 774
22.7 Thread-worker-pool Strategy 774
22.8 Thread-worker Pool with Bounded Buffer 775
22.9 Process-worker Pool 775
22.10 InfluenceofDiskI/O 776
22.11 PerformanceStudies 780
22.12 Report Writing 790
22.13 AdditionalReading 792
· · · · · · (
收起)