没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux与Unix系统编程深度指南
"LinuxUnix系统编程手册(英文版).pdf"
《LinuxUnix系统编程手册》是一本详尽的编程指南,专为在Linux和Unix环境下进行系统级编程的程序员所编写。这本书由Michael Kerrisk撰写,被业界广泛赞誉为必备的编程工具书。书中涵盖了从基础到高级的各类系统编程接口,提供了深入的描述和丰富的实例,帮助读者理解低级别编程API的细节和微妙之处。
此书的核心内容包括以下几个关键知识点:
1. **进程管理**:详细讲解了进程的创建、通信、同步和调度机制,包括fork、exec、waitpid等系统调用的使用,以及信号处理的概念。
2. **文件和I/O**:介绍了打开、关闭、读写文件的函数,如open、read、write、close,以及标准I/O库的使用。此外,还涉及到了管道、套接字和命名管道等I/O复用技术。
3. **内存管理**:涵盖了动态内存分配(malloc、calloc、realloc、free)、内存映射(mmap、munmap)以及共享内存和内存保护的概念。
4. **文件系统**:讨论了文件系统的基本操作,如文件权限、硬链接、软链接、目录操作,并深入解析了异步I/O和文件系统性能优化。
5. **网络编程**:详细阐述了套接字编程,包括TCP/IP、UDP协议,以及socket选项、套接字地址结构等。同时,还介绍了服务器架构,如并发服务器设计和网络安全问题。
6. **进程间通信(IPC)**:涵盖了信号量、消息队列、共享内存和管道等多种进程间通信机制,以及相关函数的使用方法。
7. **线程编程**:讲解了线程的创建、同步和销毁,包括pthread库的使用,如pthread_create、pthread_join、pthread_mutex等。
8. **错误处理**:如何正确地捕获和处理系统调用失败,以及理解和使用errno变量和strerror函数。
9. **标准库和POSIX兼容性**:讨论了C标准库函数和POSIX标准,如何确保代码在不同的Linux和Unix系统上具有可移植性。
10. **系统调用和库函数**:全面介绍和解释了大量的系统调用和库函数,帮助读者深入理解其工作原理。
Michael Kerrisk在书中不仅详细描述了各种接口,还积极与开源社区互动,报告并修复程序中的错误,提升了相关man页面的质量,使这本手册成为了Linux编程领域的权威参考书。无论是初学者还是经验丰富的开发者,都能从中受益匪浅,提升自己的系统编程技能。
xiv Contents in Detail
11 SYSTEM LIMITS AND OPTIONS 211
11.1 System Limits............................................................................................................. 212
11.2 Retrieving System Limits (and Options) at Run Time ........................................................ 215
11.3 Retrieving File-Related Limits (and Options) at Run Time.................................................. 217
11.4 Indeterminate Limits ................................................................................................... 219
11.5 System Options......................................................................................................... 219
11.6 Summary.................................................................................................................. 221
11.7 Exercises .................................................................................................................. 222
12 SYSTEM AND PROCESS INFORMATION 223
12.1 The /proc File System................................................................................................. 223
12.1.1 Obtaining Information About a Process:
/proc/PID................................... 224
12.1.2 System Information Under
/proc.............................................................. 226
12.1.3 Accessing
/proc Files ............................................................................ 226
12.2 System Identification:
uname() .................................................................................... 229
12.3 Summary.................................................................................................................. 231
12.4 Exercises .................................................................................................................. 231
13 FILE I/O BUFFERING 233
13.1 Kernel Buffering of File I/O: The Buffer Cache .............................................................. 233
13.2 Buffering in the
stdio Library ....................................................................................... 237
13.3 Controlling Kernel Buffering of File I/O........................................................................ 239
13.4 Summary of I/O Buffering .......................................................................................... 243
13.5 Advising the Kernel About I/O Patterns........................................................................ 244
13.6 Bypassing the Buffer Cache: Direct I/O........................................................................ 246
13.7 Mixing Library Functions and System Calls for File I/O .................................................. 248
13.8 Summary.................................................................................................................. 249
13.9 Exercises .................................................................................................................. 250
14 FILE SYSTEMS 251
14.1 Device Special Files (Devices) ..................................................................................... 252
14.2 Disks and Partitions ................................................................................................... 253
14.3 File Systems.............................................................................................................. 254
14.4 I-nodes..................................................................................................................... 256
14.5 The Virtual File System (VFS) ....................................................................................... 259
14.6 Journaling File Systems............................................................................................... 260
14.7 Single Directory Hierarchy and Mount Points ................................................................ 261
14.8 Mounting and Unmounting File Systems ....................................................................... 262
14.8.1 Mounting a File System:
mount() ............................................................ 264
14.8.2 Unmounting a File System:
umount() and umount2() ................................ 269
14.9 Advanced Mount Features.......................................................................................... 271
14.9.1 Mounting a File System at Multiple Mount Points....................................... 271
14.9.2 Stacking Multiple Mounts on the Same Mount Point................................... 271
14.9.3 Mount Flags That Are Per-Mount Options ................................................. 272
14.9.4 Bind Mounts......................................................................................... 272
14.9.5 Recursive Bind Mounts........................................................................... 273
14.10 A Virtual Memory File System:
tmpfs............................................................................ 274
14.11 Obtaining Information About a File System:
statvfs()...................................................... 276
14.12 Summary.................................................................................................................. 277
14.13 Exercise ................................................................................................................... 278
Contents in Detail xv
15 FILE ATTRIBUTES 279
15.1 Retrieving File Information: stat() ................................................................................. 279
15.2 File Timestamps......................................................................................................... 285
15.2.1 Changing File Timestamps with
utime() and utimes()................................. 287
15.2.2 Changing File Timestamps with
utimensat() and futimens() ........................ 289
15.3 File Ownership ......................................................................................................... 291
15.3.1 Ownership of New Files ........................................................................ 291
15.3.2 Changing File Ownership:
chown(), fchown(), and lchown()....................... 291
15.4 File Permissions......................................................................................................... 294
15.4.1 Permissions on Regular Files................................................................... 294
15.4.2 Permissions on Directories...................................................................... 297
15.4.3 Permission-Checking Algorithm ............................................................... 297
15.4.4 Checking File Accessibility:
access()......................................................... 299
15.4.5 Set-User-ID, Set-Group-ID, and Sticky Bits ................................................. 300
15.4.6 The Process File Mode Creation Mask:
umask()........................................ 301
15.4.7 Changing File Permissions:
chmod() and fchmod()..................................... 303
15.5 I-node Flags (
ext2 Extended File Attributes) ................................................................... 304
15.6 Summary.................................................................................................................. 308
15.7 Exercises .................................................................................................................. 309
16 EXTENDED ATTRIBUTES 311
16.1 Overview ................................................................................................................. 311
16.2 Extended Attribute Implementation Details .................................................................... 313
16.3 System Calls for Manipulating Extended Attributes......................................................... 314
16.4 Summary.................................................................................................................. 318
16.5 Exercise ................................................................................................................... 318
17 ACCESS CONTROL LISTS 319
17.1 Overview ................................................................................................................. 320
17.2 ACL Permission-Checking Algorithm............................................................................. 321
17.3 Long and Short Text Forms for ACLs............................................................................. 323
17.4 The
ACL_MASK Entry and the ACL Group Class................................................................ 324
17.5 The
getfacl and setfacl Commands ............................................................................... 325
17.6 Default ACLs and File Creation ................................................................................... 327
17.7 ACL Implementation Limits .......................................................................................... 328
17.8 The ACL API ............................................................................................................. 329
17.9 Summary.................................................................................................................. 337
17.10 Exercise ................................................................................................................... 337
18 DIRECTORIES AND LINKS 339
18.1 Directories and (Hard) Links........................................................................................ 339
18.2 Symbolic (Soft) Links .................................................................................................. 342
18.3 Creating and Removing (Hard) Links:
link() and unlink()............................................... 344
18.4 Changing the Name of a File:
rename() ....................................................................... 348
18.5 Working with Symbolic Links:
symlink() and readlink().................................................. 349
18.6 Creating and Removing Directories:
mkdir() and rmdir() ............................................... 350
18.7 Removing a File or Directory:
remove()......................................................................... 352
18.8 Reading Directories:
opendir() and readdir() ................................................................ 352
18.9 File Tree Walking:
nftw() ........................................................................................... 358
18.10 The Current Working Directory of a Process ................................................................. 363
18.11 Operating Relative to a Directory File Descriptor ........................................................... 365
18.12 Changing the Root Directory of a Process:
chroot() ........................................................ 367
18.13 Resolving a Pathname:
realpath() ................................................................................ 369
xvi Contents in Detail
18.14 Parsing Pathname Strings: dirname() and basename() .................................................... 370
18.15 Summary.................................................................................................................. 372
18.16 Exercises .................................................................................................................. 373
19 MONITORING FILE EVENTS 375
19.1 Overview ................................................................................................................. 376
19.2 The
inotify API .......................................................................................................... 376
19.3
inotify Events ............................................................................................................ 378
19.4 Reading
inotify Events................................................................................................ 379
19.5 Queue Limits and
/proc Files....................................................................................... 385
19.6 An Older System for Monitoring File Events:
dnotify....................................................... 386
19.7 Summary.................................................................................................................. 386
19.8 Exercise ................................................................................................................... 386
20 SIGNALS: FUNDAMENTAL CONCEPTS 387
20.1 Concepts and Overview............................................................................................. 388
20.2 Signal Types and Default Actions ................................................................................ 390
20.3 Changing Signal Dispositions:
signal()......................................................................... 397
20.4 Introduction to Signal Handlers ................................................................................... 398
20.5 Sending Signals:
kill() ............................................................................................... 401
20.6 Checking for the Existence of a Process........................................................................ 403
20.7 Other Ways of Sending Signals:
raise() and killpg() ..................................................... 404
20.8 Displaying Signal Descriptions .................................................................................... 406
20.9 Signal Sets ............................................................................................................... 406
20.10 The Signal Mask (Blocking Signal Delivery) .................................................................. 410
20.11 Pending Signals ........................................................................................................ 411
20.12 Signals Are Not Queued............................................................................................ 412
20.13 Changing Signal Dispositions:
sigaction()..................................................................... 416
20.14 Waiting for a Signal:
pause()...................................................................................... 418
20.15 Summary.................................................................................................................. 418
20.16 Exercises .................................................................................................................. 419
21 SIGNALS: SIGNAL HANDLERS 421
21.1 Designing Signal Handlers ......................................................................................... 422
21.1.1 Signals Are Not Queued (Revisited) ........................................................ 422
21.1.2 Reentrant and Async-Signal-Safe Functions............................................... 422
21.1.3 Global Variables and the
sig_atomic_t Data Type..................................... 428
21.2 Other Methods of Terminating a Signal Handler ........................................................... 428
21.2.1 Performing a Nonlocal Goto from a Signal Handler.................................. 429
21.2.2 Terminating a Process Abnormally:
abort()............................................... 433
21.3 Handling a Signal on an Alternate Stack:
sigaltstack() ................................................... 434
21.4 The
SA_SIGINFO Flag................................................................................................... 437
21.5 Interruption and Restarting of System Calls ................................................................... 442
21.6 Summary.................................................................................................................. 445
21.7 Exercise ................................................................................................................... 446
22 SIGNALS: ADVANCED FEATURES 447
22.1 Core Dump Files ....................................................................................................... 448
22.2 Special Cases for Delivery, Disposition, and Handling ................................................... 450
22.3 Interruptible and Uninterruptible Process Sleep States..................................................... 451
22.4 Hardware-Generated Signals...................................................................................... 452
22.5 Synchronous and Asynchronous Signal Generation ....................................................... 452
Contents in Detail xvii
22.6 Timing and Order of Signal Delivery ........................................................................... 453
22.7 Implementation and Portability of
signal()..................................................................... 454
22.8 Realtime Signals........................................................................................................ 456
22.8.1 Sending Realtime Signals....................................................................... 458
22.8.2 Handling Realtime Signals ..................................................................... 460
22.9 Waiting for a Signal Using a Mask:
sigsuspend() .......................................................... 464
22.10 Synchronously Waiting for a Signal............................................................................. 468
22.11 Fetching Signals via a File Descriptor........................................................................... 471
22.12 Interprocess Communication with Signals ..................................................................... 474
22.13 Earlier Signal APIs (System V and BSD) ........................................................................ 475
22.14 Summary.................................................................................................................. 477
22.15 Exercises .................................................................................................................. 478
23 TIMERS AND SLEEPING 479
23.1 Interval Timers........................................................................................................... 479
23.2 Scheduling and Accuracy of Timers ............................................................................. 485
23.3 Setting Timeouts on Blocking Operations...................................................................... 486
23.4 Suspending Execution for a Fixed Interval (Sleeping) ..................................................... 487
23.4.1 Low-Resolution Sleeping:
sleep().............................................................. 487
23.4.2 High-Resolution Sleeping:
nanosleep()...................................................... 488
23.5 POSIX Clocks............................................................................................................ 491
23.5.1 Retrieving the Value of a Clock:
clock_gettime() ........................................ 491
23.5.2 Setting the Value of a Clock:
clock_settime() ............................................. 492
23.5.3 Obtaining the Clock ID of a Specific Process or Thread ............................. 493
23.5.4 Improved High-Resolution Sleeping:
clock_nanosleep() ............................... 493
23.6 POSIX Interval Timers................................................................................................. 495
23.6.1 Creating a Timer:
timer_create() ............................................................. 495
23.6.2 Arming and Disarming a Timer:
timer_settime() ........................................ 498
23.6.3 Retrieving the Current Value of a Timer:
timer_gettime()............................. 499
23.6.4 Deleting a Timer:
timer_delete() .............................................................. 499
23.6.5 Notification via a Signal........................................................................ 499
23.6.6 Timer Overruns..................................................................................... 503
23.6.7 Notification via a Thread....................................................................... 504
23.7 Timers That Notify via File Descriptors: the
timerfd API ................................................... 507
23.8 Summary.................................................................................................................. 511
23.9 Exercises .................................................................................................................. 512
24 PROCESS CREATION 513
24.1 Overview of fork(), exit(), wait(), and execve() .............................................................. 513
24.2 Creating a New Process:
fork()................................................................................... 515
24.2.1 File Sharing Between Parent and Child .................................................... 517
24.2.2 Memory Semantics of
fork() ................................................................... 520
24.3 The
vfork() System Call .............................................................................................. 522
24.4 Race Conditions After
fork() ....................................................................................... 525
24.5 Avoiding Race Conditions by Synchronizing with Signals............................................... 527
24.6 Summary.................................................................................................................. 529
24.7 Exercises .................................................................................................................. 530
25 PROCESS TERMINATION 531
25.1 Terminating a Process: _exit() and exit()....................................................................... 531
25.2 Details of Process Termination..................................................................................... 533
25.3 Exit Handlers ............................................................................................................ 533
25.4 Interactions Between
fork(), stdio Buffers, and _exit() ..................................................... 537
xviii Contents in Detail
25.5 Summary.................................................................................................................. 538
25.6 Exercise ................................................................................................................... 539
26 MONITORING CHILD PROCESSES 541
26.1 Waiting on a Child Process ........................................................................................ 541
26.1.1 The
wait() System Call........................................................................... 541
26.1.2 The
waitpid() System Call ...................................................................... 544
26.1.3 The Wait Status Value ........................................................................... 545
26.1.4 Process Termination from a Signal Handler .............................................. 549
26.1.5 The
waitid() System Call........................................................................ 550
26.1.6 The
wait3() and wait4() System Calls...................................................... 552
26.2 Orphans and Zombies ............................................................................................... 553
26.3 The
SIGCHLD Signal .................................................................................................... 555
26.3.1 Establishing a Handler for
SIGCHLD .......................................................... 555
26.3.2 Delivery of
SIGCHLD for Stopped Children ................................................. 559
26.3.3 Ignoring Dead Child Processes ............................................................... 559
26.4 Summary.................................................................................................................. 561
26.5 Exercises .................................................................................................................. 562
27 PROGRAM EXECUTION 563
27.1 Executing a New Program: execve() ............................................................................. 563
27.2 The
exec() Library Functions......................................................................................... 567
27.2.1 The
PATH Environment Variable ............................................................... 568
27.2.2 Specifying Program Arguments as a List................................................... 570
27.2.3 Passing the Caller’s Environment to the New Program ............................... 570
27.2.4 Executing a File Referred to by a Descriptor:
fexecve()................................ 571
27.3 Interpreter Scripts ...................................................................................................... 572
27.4 File Descriptors and
exec() .......................................................................................... 575
27.5 Signals and
exec() ..................................................................................................... 578
27.6 Executing a Shell Command:
system() .......................................................................... 579
27.7 Implementing
system() ................................................................................................ 582
27.8 Summary.................................................................................................................. 588
27.9 Exercises .................................................................................................................. 589
28 PROCESS CREATION AND PROGRAM EXECUTION IN
MORE DETAIL 591
28.1 Process Accounting.................................................................................................... 591
28.2 The
clone() System Call .............................................................................................. 598
28.2.1 The
clone() flags Argument ..................................................................... 603
28.2.2 Extensions to
waitpid() for Cloned Children ............................................. 609
28.3 Speed of Process Creation.......................................................................................... 610
28.4 Effect of
exec() and fork() on Process Attributes.............................................................. 612
28.5 Summary.................................................................................................................. 616
28.6 Exercise ................................................................................................................... 616
29 THREADS: INTRODUCTION 617
29.1 Overview ................................................................................................................. 617
29.2 Background Details of the Pthreads API ........................................................................ 620
29.3 Thread Creation........................................................................................................ 622
29.4 Thread Termination.................................................................................................... 623
29.5 Thread IDs................................................................................................................ 624
29.6 Joining with a Terminated Thread................................................................................ 625
29.7 Detaching a Thread................................................................................................... 627
剩余1555页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2017-08-04 上传
102 浏览量
2014-07-25 上传
2017-04-23 上传
2010-03-31 上传
2021-08-03 上传
blackhawk0826
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Unity5.5 (1).zip
- awsm-loggly:JAWS awsm模块可为您的lambda提供日志记录
- 关于用于校准机动车辆中的加速度传感器的方法和装置的介绍说明.rar
- 高频电子线路 第一讲 概论-教程与笔记习题
- 基于java的-171-springboot智慧党建系统-源码.zip
- plastron:在Fedora 4存储库上进行批处理操作的实用程序
- 0041、基于protues仿真的伺服电机控制系统(仿真图、源代码、报告)
- 学生音乐学习动机与音乐学业情绪的研究综述6.25-论文.zip
- EmanInfiniteScroll:我的面试应用
- bpb:browserify转换,通过处理抽象语法树(AST),将“ process.browser”安全地替换为“ true”
- 半导体芯片制造智能制造系列资料 ----- 半导体切片
- django+bootstrap实现增删改查
- 关于用于在车辆和操作装置中提供操作装置的方法(1)的介绍说明.rar
- scaffold-clean-architecture:Gradle插件可以使用Java创建干净的应用程序,该应用程序已经可以正常运行,它遵循了我们的最佳实践!
- 基于java的-184-ssm基于vue的消防物资存储系统--LW-源码.zip
- russian-travel:专案3
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功