没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux与UNIX系统编程手册
"The Linux Programming Interface" 是一本关于Linux和UNIX系统编程的手册,涵盖了广泛的系统编程主题,包括历史、标准、基本概念以及深入的技术细节。
本书详细介绍了以下关键知识点:
1. **历史与标准**:讲解了Linux和UNIX系统的起源与发展,以及它们遵循的开放标准和规范。
2. **基础概念**:涵盖操作系统的基本原理,如进程、内存管理、文件系统等。
3. **系统编程概念**:讨论了系统级编程中的一些核心概念,为后续章节打下基础。
4. **文件I/O**:阐述了通用的I/O模型,包括打开、读取、写入和关闭文件等操作,以及进一步的细节。
5. **进程**:介绍了进程的创建、管理和通信,包括fork、exec、wait等系统调用。
6. **内存分配**:讲解如何在程序中动态地分配和释放内存,涉及malloc、calloc、realloc和free等函数。
7. **用户和组**:探讨了用户身份、权限和组管理,以及相关的系统调用和工具。
8. **进程凭证**:涵盖了进程的身份验证信息,如用户ID、组ID和权限集。
9. **时间管理**:讨论了系统时间、定时器以及睡眠操作。
10. **系统限制和选项**:介绍了如何查询和调整系统的资源限制。
11. **系统和进程信息**:讲述了获取系统和进程状态的方法,如ps命令和/proc文件系统。
12. **I/O缓冲**:讨论了如何利用缓冲提高I/O效率。
13. **文件系统**:深入剖析了Linux的文件系统,包括VFAT、EXT系列和网络文件系统。
14. **文件属性**:讲解了常规和扩展文件属性,以及如何修改和查询这些属性。
15. **访问控制列表(ACL)**:介绍了如何使用ACL来实现更精细的文件访问控制。
16. **目录和链接**:涵盖了目录结构、硬链接和软链接的使用。
17. **文件事件监控**:讨论了inotify机制,用于监视文件系统变化。
18. **信号**:涵盖了信号的基本概念、处理函数以及高级特性。
19. **计时器和睡眠**:介绍了如何设置定时事件,如alarm、sleep和timer_create等。
20. **进程创建**:详细讲解了进程的创建过程,包括fork和vfork。
21. **进程终止**:探讨了进程的正常和异常退出,以及信号在进程终止中的角色。
22. **子进程监控**:讨论了wait和waitpid等函数,用于等待子进程结束。
23. **程序执行**:深入分析了程序启动的细节,如exec家族的函数。
24. **线程**:介绍了多线程编程,包括线程创建、同步、取消和线程安全。
25. **进程组、会话和作业控制**:涵盖了终端、进程组和作业控制的概念。
26. **进程优先级和调度**:讨论了如何改变进程的优先级和调度策略。
27. **进程资源**:讲述了进程使用的资源,如内存、CPU时间等。
28. **守护进程**:解释了如何编写后台运行的服务程序。
29. **安全特权编程**:讨论了编写安全的具有特权的程序的方法,如setuid和capabilities。
30. **登录会计**:介绍了记录用户登录和注销信息的过程。
31. **共享库**:涵盖了动态链接库的基本概念和高级特性。
32. **进程间通信(IPC)**:全面介绍了管道、FIFO、System V IPC(消息队列、信号量、共享内存)和POSIX IPC。
33. **文件锁定**:讲解了如何在多个进程之间同步对文件的访问。
34. **套接字编程**:从基础到高级,涵盖了UNIX域套接字和TCP/IP网络编程,包括服务器设计和高级话题。
35. **终端**:讨论了终端设备、伪终端和控制台输入/输出。
36. **替代I/O模型**:介绍了一些非标准的I/O方法和模式。
这本书是Linux程序员的必备参考书,无论你是初学者还是经验丰富的开发者,都能从中学习到丰富的知识和实践经验。作者Michael Kerrisk不仅详尽地解释了Linux编程接口,还确保书中提到的bug被修复,并改进了相关的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页未读,继续阅读
2018-12-27 上传
2023-07-27 上传
2013-01-13 上传
2019-03-15 上传
2012-12-11 上传
2012-01-06 上传
2018-05-18 上传
shilcare
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Angular实现MarcHayek简历展示应用教程
- Crossbow Spot最新更新 - 获取Chrome扩展新闻
- 量子管道网络优化与Python实现
- Debian系统中APT缓存维护工具的使用方法与实践
- Python模块AccessControl的Windows64位安装文件介绍
- 掌握最新*** Fisher资讯,使用Google Chrome扩展
- Ember应用程序开发流程与环境配置指南
- EZPCOpenSDK_v5.1.2_build***版本更新详情
- Postcode-Finder:利用JavaScript和Google Geocode API实现
- AWS商业交易监控器:航线行为分析与营销策略制定
- AccessControl-4.0b6压缩包详细使用教程
- Python编程实践与技巧汇总
- 使用Sikuli和Python打造颜色求解器项目
- .Net基础视频教程:掌握GDI绘图技术
- 深入理解数据结构与JavaScript实践项目
- 双子座在线裁判系统:提高编程竞赛效率
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功