没有合适的资源?快使用搜索试试~ 我知道了~
首页Linux 编程接口详解:UNIX 系统编程手册
Linux 编程接口详解:UNIX 系统编程手册
需积分: 10 3 下载量 116 浏览量
更新于2024-07-26
收藏 6.92MB PDF 举报
Linux 编程接口详解
本书《The Linux Programming Interface - A Linux and UNIX System Programming Handbook》是一本深入探讨 Linux 编程接口的权威指南,旨在帮助读者深入理解 Linux 操作系统的编程接口、UNIX 系统编程的细节和 Linux 编程的各种标准。
**Linux 编程接口**
Linux 编程接口是指 Linux 操作系统提供的一组 API,允许开发者编写可以在 Linux 操作系统上运行的软件。这些 API 包括系统调用、库函数、设备驱动程序接口等,都是 Linux 编程的基础设施。
**Linux 系统编程**
Linux 系统编程是指使用 Linux 操作系统提供的各种 API 和工具来编写可以在 Linux 操作系统上运行的软件。Linux 系统编程包括系统调用、进程管理、文件系统管理、网络编程等多方面的内容。
**UNIX 系统编程**
UNIX 系统编程是指使用 UNIX 操作系统提供的各种 API 和工具来编写可以在 UNIX 操作系统上运行的软件。UNIX 系统编程包括系统调用、进程管理、文件系统管理、网络编程等多方面的内容。
**Linux 编程的标准**
Linux 编程的标准是指 Linux 操作系统提供的一组编程标准,包括 POSIX、SUS、 LSB 等标准。这些标准规定了 Linux 操作系统的编程接口、数据类型、函数库等方面的内容。
**Linux 虚拟内存管理**
Linux 虚拟内存管理是指 Linux 操作系统提供的一种虚拟内存管理机制,允许开发者在 Linux 操作系统上编写高效的虚拟内存管理程序。Linux 虚拟内存管理包括虚拟内存空间管理、页面置换算法、内存分配算法等多方面的内容。
**Linux 设备驱动程序接口**
Linux 设备驱动程序接口是指 Linux 操作系统提供的一组设备驱动程序接口,允许开发者编写可以在 Linux 操作系统上运行的设备驱动程序。Linux 设备驱动程序接口包括字符设备驱动程序接口、块设备驱动程序接口、网络设备驱动程序接口等多方面的内容。
**Linux 编程的应用**
Linux 编程的应用非常广泛,包括操作系统开发、嵌入式系统开发、网络编程、数据库编程等多方面的内容。Linux 编程的应用还可以扩展到移动设备、汽车电子、机器人等领域。
本书《The Linux Programming Interface - A Linux and UNIX System Programming Handbook》是一本非常实用的 Linux 编程指南,涵盖了 Linux 编程的方方面面,为读者提供了深入理解 Linux 操作系统的编程接口和 UNIX 系统编程的细节的机会。
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页未读,继续阅读
2013-09-27 上传
2011-01-26 上传
2016-11-08 上传
2018-04-18 上传
点击了解资源详情
点击了解资源详情
点击了解资源详情
点击了解资源详情
点击了解资源详情
bug_xiaohei
- 粉丝: 0
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 探索数据转换实验平台在设备装置中的应用
- 使用git-log-to-tikz.py将Git日志转换为TIKZ图形
- 小栗子源码2.9.3版本发布
- 使用Tinder-Hack-Client实现Tinder API交互
- Android Studio新模板:个性化Material Design导航抽屉
- React API分页模块:数据获取与页面管理
- C语言实现顺序表的动态分配方法
- 光催化分解水产氢固溶体催化剂制备技术揭秘
- VS2013环境下tinyxml库的32位与64位编译指南
- 网易云歌词情感分析系统实现与架构
- React应用展示GitHub用户详细信息及项目分析
- LayUI2.1.6帮助文档API功能详解
- 全栈开发实现的chatgpt应用可打包小程序/H5/App
- C++实现顺序表的动态内存分配技术
- Java制作水果格斗游戏:策略与随机性的结合
- 基于若依框架的后台管理系统开发实例解析
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功