没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux编程接口详解:Linux与UNIX系统编程手册
"《Linux编程接口:Linux和UNIX系统编程手册》第1版"
《Linux编程接口:Linux和UNIX系统编程手册》是针对那些希望深入理解Linux操作系统编程接口的专业人士的一本权威指南。这本书由Michael Kerrisk撰写,他以其对Linux内核的深刻理解和对编程接口的详尽解释而著称。书中的内容不仅覆盖了基础的编程概念,还深入探讨了高级主题,旨在帮助读者成为精通Linux系统的程序员。
书中的关键知识点包括:
1. **Linux系统调用**:书中详细介绍了如何使用C语言来调用Linux内核提供的系统调用,如open、read、write、close等,这些都是进行文件操作的基础。
2. **进程管理**:涵盖了进程创建(fork、vfork、clone)、进程间通信(管道、信号量、消息队列、共享内存)以及进程同步与互斥。
3. **线程编程**:讨论了pthread库,包括线程创建、线程同步(锁、条件变量、读写锁)和线程属性设置。
4. **文件系统和I/O操作**:阐述了文件描述符、缓冲I/O、非阻塞I/O和异步I/O的使用方法,以及软硬链接、符号链接和文件权限管理。
5. **网络编程**:详细讲解了套接字API,包括TCP/IP、UDP以及多路复用I/O(select、poll、epoll)。
6. **信号处理**:介绍了如何使用signal、sigaction函数处理进程收到的信号,以及信号在进程间传播的行为。
7. **内存管理**:深入解析了虚拟内存系统,包括内存映射、动态内存分配(malloc、calloc、realloc、free)和内存对齐。
8. **错误处理和调试**:讨论了错误检测机制,如errno和strerror,以及如何有效地调试Linux程序。
9. **标准化和兼容性**:对比了Linux编程接口与其他Unix变种的差异,并强调遵循POSIX标准的重要性。
10. **程序启动和初始化**:解释了进程的生命周期,包括环境变量、启动脚本和初始化过程。
11. **man页面**:书中还涉及到了编写和改进man页面的实践,这对于开发高质量开源软件至关重要。
本书不仅仅是理论介绍,还包含了大量的实例代码,有助于读者通过实践来掌握这些知识。它得到了来自Google软件工程师、《理解Linux虚拟内存管理器》作者和SUSE开放源码项目经理的高度评价,他们一致认为这本书是Linux编程领域的必备参考书。
通过阅读《Linux编程接口》,无论是初学者还是经验丰富的开发者,都能从中获取到大量有价值的信息,提升自己的Linux编程技能。这本书不仅有助于理解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页未读,继续阅读
2009-05-13 上传
2009-07-29 上传
2013-04-24 上传
2021-10-02 上传
2022-09-21 上传
2022-09-20 上传
legend0011
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 高清艺术文字图标资源,PNG和ICO格式免费下载
- mui框架HTML5应用界面组件使用示例教程
- Vue.js开发利器:chrome-vue-devtools插件解析
- 掌握ElectronBrowserJS:打造跨平台电子应用
- 前端导师教程:构建与部署社交证明页面
- Java多线程与线程安全在断点续传中的实现
- 免Root一键卸载安卓预装应用教程
- 易语言实现高级表格滚动条完美控制技巧
- 超声波测距尺的源码实现
- 数据可视化与交互:构建易用的数据界面
- 实现Discourse外聘回复自动标记的简易插件
- 链表的头插法与尾插法实现及长度计算
- Playwright与Typescript及Mocha集成:自动化UI测试实践指南
- 128x128像素线性工具图标下载集合
- 易语言安装包程序增强版:智能导入与重复库过滤
- 利用AJAX与Spotify API在Google地图中探索世界音乐排行榜
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功