Preface 1
Chapter 1. Introduction 1
1.1 Introduction 1
1.2 Logging In 1
1.3 Files and Directories 3
1.4 Input and Output 6
1.5 Programs and Processes 9
1.6 ANSI C Features 12
1.7 Error Handling 14
1.8 User Identification 16
1.9 Signals 17
1.10 Unix Time Values 19
1.11 System Calls and Library Functions 20
1.12 Summary 23
2.2.1 ANSI C 25
2.2 Unix Standardization 25
Chapter 2. Unix Standardization and Implementations 25
2.1 Introduction 25
2.2.2 IEEE POSIX 26
2.2.3 X/Open XPG3 28
2.2.4 FIPS 28
2.3 Unix Implementations 28
2.3.1 System V Release 4 29
2.3.2 4.3+BSD 29
2.5 Limits 30
2.4 Relationship of Standards and Implementations 30
2.5.1 ANSI C Limits 31
2.5.2 POSIX Limits 32
2.5.3 XPG3 Limits 34
2.5.4 sysconf, pathconf, and fpathconf Functions 34
2.5.5 FIPS 151-1 Requirements 39
2.5.6 Summary of Limits 41
2.5.7 Indeterminate Run-Time Limits 41
2.7 Primitive System Data Types 44
2.6 Feature Test Macros 44
2.8 Conflicts Between Standards 45
2.9 Summary 46
Chapter 3. File I/O 47
3.1 Introduction 47
3.2 File Descriptors 47
3.3 open Function 48
3.4 creat Function 50
3.6 lseek Function 51
3.5 close Function 51
3.7 read Function 54
3.8 write Function 55
3.9 I/O Efficiency 55
3.10 File Sharing 56
3.11 Atomic Operations 60
3.12 dup and dup2 Functions 61
3.13 fcntl Function 63
3.14 ioctl Function 67
3.15 /dev/fd 69
3.16 Summary 70
Chapter 4. Files and Directories 73
4.1 Introduction 73
4.2 stat, fstat, and lstat Functions 73
4.3 File Types 74
4.4 Set-User-ID and Set-Group-ID 77
4.5 File Access Permissions 78
4.6 Ownership of New Files and Directories 81
4.7 access Function 82
4.8 umask Function 83
4.9 chmod and fchmod Functions 85
4.10 Sticky Bit 88
4.11 chown, fchown, and lchown Functions 89
4.12 File Size 90
4.13 File Truncation 91
4.14 Filesystems 92
4.15 link, unlink, remove, and rename Functions 95
4.16 Symbolic Links 99
4.17 symlink and readlink Functions 102
4.18 File Times 102
4.19 utime Function 103
4.20 mkdir and rmdir Functions 106
4.21 Reading Directories 107
4.22 chdir, fchdir, and getcwd Functions 112
4.23 Special Device Files 114
4.24 sync and fsync Functions 116
4.25 Summary of File Access Permission Bits 117
4.26 Summary 118
Chapter 5. Standard I/O Library 121
5.1 Introduction 121
5.2 Streams and FILE Objects 121
5.3 Standard Input, Standard Output, and Standard Error 122
5.4 Buffering 122
5.5 Opening a Stream 125
5.6 Reading and Writing a Stream 127
5.7 Line-at-a-Time I/O 130
5.8 Standard I/O Effciency 131
5.9 Binary I/O 133
5.10 Positioning a Stream 135
5.11 Formatted I/O 136
5.12 Implementation Details 138
5.13 Temporary Files 140
5.14 Alternatives to Standard I/O 143
5.15 Summary 143
6.2 Password File 145
Chapter 6. System Data Files and Information 145
6.1 Introduction 145
6.3 Shadow Passwords 148
6.4 Group File 149
6.5 Supplementary Group IDs 150
6.6 Other Data Files 152
6.7 Login Accounting 153
6.8 System Identification 154
6.9 Time and Date Routines 155
6.10 Summary 159
Chapter 7. The Environment of a Unix Process 161
7.1 Introduction 161
7.2 main Function 161
7.3 Process Termination 162
7.4 Command-Line Arguments 165
7.5 Environment List 166
7.6 Memory Layout of a C Program 167
7.8 Memory Allocation 169
7.7 Shared Libraries 169
7.9 Environment Variables 172
7.10 set jmp and longjmp Functions 174
7.11 getrlimit and setrlimit Functions 180
7.12 Summary 184
Chapter 8. Process Control 187
8.1 Introduction 187
8.2 Process Identifiers 187
8.3 fork Function 188
8.4 vfork Function 193
8.5 exit Functions 195
8.6 wait and waitpid Functions 197
8.7 wait3 and wait4 Functions 202
8.8 Race Conditions 203
8.9 exec Functions 207
8.10 Changing User IDs and Group IDs 213
8.11 Interpreter Files 217
8.12 system Function 221
8.13 Process Accounting 226
8.14 User Identification 231
8.15 Process Times 232
8.16 Summary 235
Chapter 9. Process Relationships 237
9.1 Introduction 237
9.2 Terminal Logins 237
9.3 Network Logins 241
9.4 Process Groups 243
9.5 Sessions 244
9.6 Controlling Terminal 246
9.7 tcgetpgrp and tcsetpgrp Functions 247
9.8 Job Control 248
9.9 Shell Execution of Programs 252
9.10 Orphaned Process Groups 256
9.11 4.3+BSD Implementation 259
9.12 Summary 261
Chapter 10. Signals 263
10.1 Introduction 263
10.2 Signal Concepts 263
10.3 signal Function 270
10.4 Unreliable Signals 274
10.5 Interrupted System Calls 275
10.6 Reentrant Functions 278
10.7 SIGCLD Semantics 279
10.8 Reliable Signal Terminology and Semantics 282
10.9 kill and raise Functions 283
10.10 alarm and pause Functions 285
10.11 Signal Sets 291
10.12 sigprocmask Function 292
10.13 sigpending Function 293
10.14 sjgaction Function 296
10.15 sigsetjmp and siglongjmp Functions 299
10.16 sigsuspend Function 303
10.17 abort Function 309
10.18 system Function 310
10.19 sleep Function 317
10.20 Job-Control Signals 319
10.21 Additional Features 320
10.22 Summary 323
Chapter 11.Terminal I/O 325
11.1 Introduction 325
11.2 Overview 325
11.3 Special Input Characters 331
11.4 Getting and Setting Terminal Attributes 335
11.5 Terminal Option Flags 336
11.6 stty Command 342
11.7 Baud Rate Functions 343
11.8 Line Control Functions 344
11.9 Terminal Identification 345
11.10 Canonical Mode 349
11.11 Noncanonical Mode 352
11.12 Terminal Window Size 358
11.13 termcap,terminfo,and curses 360
11.14 Summary 360
Chapter 12.Advanced I/O 363
12.1 Introduction 363
12.2 Nonblocking I/O 363
12.3 Record Locking 367
12.4 Streams 383
12.5 I/O Multiplexing 394
12.5.1 select Function 396
12.5.2 poll Function 400
12.6 Asynchronous I/O 402
12.6.1 System V Release 4 403
12.6.2 4.3+BSD 403
12.7 readv and writev Functions 404
12.8 readv and writen Functions 406
12.9 Memory Mapped I/O 407
12.10 Summary 413
13.2 Daemon Characteristics 415
Chapter 13. Daemon Processes 415
13.1 Introduction 415
13.3 Coding Rules 417
13.4 Error Logging 418
13.4.1 SVR4 Streams log Drier 419
13.4.2 4.3+BSD syslog Facility 421
13.5 Client-Server Model 424
13.6 Summary 424
14.1 Introduction 427
Chapter 14. Interprocess Communication 427
14.2 Pipes 428
14.3 Popen and pclose Functions 435
14.4 Coprocesses 441
14.5 FIFOs 445
14.6 System V IPC 449
14.6.1 Identifiers and Keys 449
14.6.2 Permission Structure 450
14.6.3 Configuration Limits 451
14.6.4 Advantages and Disadvantages 451
14.7 Message Queues 453
14.8 Semaphores 457
14.9 Shared Memory 463
14.10 Client-Server Properties 470
14.11 Summary 472
15.1 Introduction 475
15.2 Stream Pipes 475
Chapter 15. Advanced Interprocess Communication 475
15.3 Passing File Descriptors 479
15.3.1 System V Release4 481
15.3.2 4.3BSD 484
15.3.3 4.3+BSD 487
15.4 An Open Server, Version 1 490
15.5 Client-Server Connection Functions 496
15.5.1 System V Release 4 497
15.2.2 4.3+BSD 501
15.6 An Open Server, Version 2 505
15.7 Summary 514
Chapter 16. A Database Library 515
16.1 Introduction 515
16.2 History 515
16.3 The Library 516
16.4 Implementation Overview 518
16.5 Centralized or Decentralized? 521
16.6 Concurrency 522
16.7 Source Code 524
16.8 Performance 545
16.9 Summary 550
Chapter 17. Communicating with a PostScript Printer 551
17.1 Introduction 551
17.2 PostScript Communication Dynamics 551
17.3 Printer Spooling 554
17.4 Source Code 556
17.5 Summary 578
18.2 History 579
Chapter 18. A Modem Dialer 579
18.1 Introduction 579
18.3 Program Design 580
18.4 Data Files 582
18.5 Server Design 584
18.6 Server Source Code 586
18.7 Client Design 615
18.8 Client Source Code 617
18.9 Summary 629
Chapter 19. Pseudo Terminals 631
19.1 Introduction 631
19.2 Overview 631
19.3 Opening Pseudo-Terminal Devices 636
19.3.1 System V Release 4 638
19.3.2 4.3+BSD 640
19.4 pty_fork Function 641
19.5 pty Program 644
19.6 Using the pty Program 648
19.7 Advanced Features 655
19.8 Summary 656
Appendix A. Function Prototypes 659
Appendix B. Miscellaneous Source Code 679
B.1 Our Header File 679
B.2 Standard Error Routines 681
Appendix C. Solutions to Selected Exercises 687
Bibliography 713
Index 719