编辑推荐
适读人群 :本书适合作为高等院校计算机专业教材,也可供软件开发人员参考使用。 √ 经典原味,UNIX必备宝典。
√ 基于*新UNIX标准的独立参考书,专业、全面、清晰。
√ 大量实例、练习、可重用的代码和用于网络通信应用程序的简化库。
√ 作者为麻省理工学院博士,现任德州大学圣安东尼奥分校计算机科学系讲师。
内容简介
本书是一本基于*新UNIX 标准的完备的参考书,对UNIX 编程的要点进行了清晰易懂的介绍,从一些用于说明如何使用系统调用的短小代码段开始,逐渐过渡到能帮助读者扩展自己技能水平的实际项目中。书中对通信、并发和线程问题进行了深入探讨,对复杂的概念,例如信号和并发,进行了全面且清晰的解释。本书还覆盖了与文件、信号、信号量、POSIX 线程和客户机―服务器通信相关的内容。书中不仅提供了大量实例和练习,还专门设计了有针对性的项目并给出了参考答案。
作者简介
无(影印版无译者……………………………………………………………………………………………………………………) Kay A. Robbins , Steve Robbins (凯罗?宾斯,史蒂夫?罗宾斯)拥有麻省理工学院博士学位,就任于德州大学圣安东尼奥分校计算机学院。
目录
Contents
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
前言/序言
前言
本书是1995年由Prentice Hall出版社出版的Practical UNIX Programming: A Guide to Communication, Concurrency and Multithreading一书的第二版。为了更好地传达本书的内容,我们将书名修改为UNIX Systems Programming: Communication, Concurrency and Threads。与上一版相比,第二版不仅改变了书名,还对很多内容进行了修改。
互联网已经成为计算和社会领域的一个主导方面。私人信息已经联网,软件经常会受到不停的攻击。因此,编写正确的代码显得尤为重要。在这一版中,我们尝试尽量生成能够正确处理错误和特殊情况的代码。我们已经意识到,声称处理了所有的错误、但在给出的代码中却省略错误处理是没有效果的。不幸的是,错误处理会让代码变得更复杂,所以我们努力让代码变得更加清晰。
本书对第一版的另一个重要改进是采用了单一的UNIX规范,我们将其称为POSIX。我们再也不需要决定使用哪个厂商的库函数了——现在有正式的版本了。我们已经尽了最大努力来遵循这个标准。
练习和项目让本书变得与众不同。实际上,本书由美国国家科学基金会(National Science Foundation Grant)项目手册的一部分发展而来。在完成这个项目的初期开发后,我们逐渐认识到:完成这个项目所需要的资料分散在不同的地方——通常可以在提供了大量细节、但几乎没有概念陈述的参考书中找到。因此,本书逐渐成为一本基于最新UNIX标准的完整参考书。
本书分为4个部分,每个部分都包含主题章节和项目章节。主题章节以循序渐进的方式涵盖了指定的内容,并以“试试看”和“看看会发生什么”的形式包含了很多示例和小练习。最后都以一个或者多个练习小节结束。本书还为进程管理、并发和通信的基本概念提供了很多编程练习。这些编程练习与传统科学课程中的实验作用相同,只有通过实践才能真正理解书中的概念。这些练习由易到难,很多练习只需要不到100行代码就能实现。
下表对本书的结构进行了总结——21个章节被分为4个部分。其中的15个主题章节与8个项目章节相互独立。第一次通读本书时可以跳过项目章节。
部分 主题章节 项目章节
第一部分:基础知识 第1章 技术对程序的影响
第2章 程序
第3章UNIX中的进程
第4章UNIX I/O
第5章 文件和目录
第6章 UNIX特殊文件 第7章 令牌环
第二部分:异步事件 第8章 信号
第9章 时间和定时器 第10章 虚拟定时器
第11章 破解命令解释程序
第三部分:并发 第12章POSIX线程
第13章 进程同步
第14章 信号量
第15章 POSIX IPC 第16章 生产者消费者
第17章 虚拟机
第四部分:通信 第18章 面向连接的通信
第20章 无连接通信 第19章 WWW重定向
第21章 互联网广播
第22章 服务器性能
项目章节通过开发一个规模较大的应用程序来整合几个主题章节的资料。这些项目包含两个层面:除了说明编程思想,还引导读者理解与应用程序相关的高级主题。这些项目都是分阶段设计的,大多数完整的实现都只需要几百行代码。由于不需要编写大量代码,因此读者可以将注意力集中在概念的理解,而不是代码调试上。为了简化编程,我们提供了可用于网络通信和输出日志记录的库。对专业的程序员来说,主题章节结尾部分的练习提供了对概念的基本介绍。通常,使用本书的教师可以从中挑选几个练习和一个项目章节让学生在一学期的课程中实现。每个项目都有多种变化,因此这些项目可以在多个学期反复使用。
读者可以用不同的方式阅读本书。第一部分的主题章节是阅读本书其他部分的基础。阅读完第一部分的主题章节后,读者可以以任何顺序阅读第二部分~第四部分的内容。但后继章节结尾部分关于交互的讨论除外(例如,线程如何与信号交互)。
本书读者应该是优秀的C程序员,但不一定是UNIX C的程序员。读者应该熟悉C语言编程和基本的数据结构。对于刚刚接触UNIX的读者来说,附录A中给出了程序开发的必备知识。
本书包含标准函数的概要。概要右下角列出了指定函数的相关标准。
本书的内容是有限的。欢迎读者给我们提出意见和建议,读者可以给我们写电子邮件authors@usp.cs.utsa.edu。虽然我们已经尽最大努力保证本书没有错误。但如果你是第一个向我们指出某个错误的人,我们会在本书的配套网站上对你表示诚挚的感谢。http://usp.cs.utsa.edu/usp上提供了本书的相关信息,从这个Web站点可以下载本书中的所有代码。
致谢
非常感谢Mike Speciner和Bob Lynch通读了本书的全部手稿,并提出了很多有用的建议。我们尤其要对Mary Lou Nohr细心睿智的编辑工作表示感谢。还要感谢Neal Wagner和Radia Perlman给予我们的鼓励和建议。
从1988年至今(2003年),我们为本科生和研究生开设了操作系统课程,本书中的很多材料都曾经作为这些教学课程的一部分内容。学习这些课程的学生们经历了书稿发展的不同阶段,并对不断出现的项目进行了现场测试。他们在编程中的bug、注释、抱怨和建议让本书变得更好,并让我们对如何将这些主题联系起来有了深刻的认识。发现了早期书稿中错误的学生有Joseph Bell、Carlos Cadenas、Igor Grinshpan、Jason Jendrusch和James Manion。我们要感谢美国国家科学基金会通过NSFILI授权的USE-0950497在我们组建实验室时所提供的支持,这样我们才有机会开展最初的课程,而本书正是根据这些课程编写的。NSF(DUE-975093、DUE-9752165和DUE-0088769)还为那些用于探讨和分析操作系统概念的工具提供了支持。
我们还要感谢Prentice Hall出版社的编辑Greg Doench,感谢他在整个过程中为我们提供指导。还要感谢出版编辑William Mara让本书得以出版。感谢LATEX2ε的制作者为我们提供了可以免费使用的排版软件。
我们还要感谢我们的家人,感谢他们给予我们无限的爱和支持,尤其要感谢我们的孩子Nicole和Thomas对这个艰巨的工程所展现出的热情和理解。