Linux系统编程.pdf

Linux系统编程.pdf
 

书籍描述

编辑推荐
如何编写那些直接依赖于Linux内核和核心系统库提供的服务的软件?通过《Linux系统编程(影印版第2版)》这本详尽的书籍,Linux内核参与者Robert Love(洛夫)为你提供了Linux系统编程方面的教程,Linux系统调用的参考手册,以及对于如何编写更聪明和更快的代码的来自内部人士的建议。
Love清晰地指出了POSIX标准函数和Linux特别提供服务之间的差异。通过关于多线程的新章节,这本修订和扩展的版本在理论和实践上相结合,从多个编程主题上提供了深入的见解。

作者简介
作者:(美国)洛夫(Robert Love)

洛夫(Robert Love)在Linux早期就已经介入,他为Linux内核和GNOME桌面环境做出了自己的贡献。Robert是Google公司的资深软件工程师,他隶属于设计和发布Android的开发队伍。

目录
Foreword
Preface
1.Introduction and Essential Concepts
System Programming
Why Learn System Programming
Cornerstones of System Programming
System Calls
The C Library
The C Compiler
APIs and ABIs
APIs
ABIs
Standards
POSIX and SUS History
C Language Standards
Linux and the Standards
This Book and the Standards
Concepts of Linux Programming
Files and the Filesystem
Processes
Users and Groups
Permissions
Signals
Interprocess Communication
Headers
Error Handling
Getting Started with System Programming
2.File I/O
Opening Files
The open() System Call
Owners of New Files
Permissions of New Files
The creat0 Function
Return Values and Error Codes
Reading via read()
Return Values
Reading All the Bytes
Nonblocking Reads
Other Error Values
Size Limits on read()
Writing with write()
Partial Writes
Append Mode
Nonblocking Writes
Other Error Codes
Size Limits on write()
Behavior of write()
Synchronized I/O
fsync0 and fdatasync0
sync0
The O SYNC Flag
O_DSYNC and O_RSYNC
Direct I/O
Closing Files
Error Values
Seeking with lseek0
Seeking Past the End of a File
Error Values
Limitations
Positional Reads and Writes
Error Values
Truncating Files
Multiplexed I/O
select()
poll()
poll() Versus select()
Kernel Internals
The Virtual Filesystem
The Page Cache
Page Writeback
Conclusion
3.Buffered I/O
User—Buffered I/O
Block Size
Standard I/O
File Pointers
Opening Files
Modes
Opening a Stream via File Descriptor
Closing Streams
Closing All Streams
Reading from a Stream
Reading a Character at a Time
Reading an Entire Line
Reading Binary Data
Writing to a Stream
Writing a Single Character
Writing a String of Characters
Writing Binary Data
Sample Program Using Buffered I/O
Seeking a Stream
Obtaining the Current Stream Position
Flushing a Stream
Errors and End—of—File
Obtaining the Associated File Descriptor
Controlling the Buffering
Thread Safety
Manual File Locking
Unlocked Stream Operations
Critiques of Standard I/O
Conclusion
4.Advanced File I/O
Scatter/Gather I/O
readv() and writev()
Event Poll
Creating a New Epolllnstance
Controlling Epoll
Waiting for Events with Epoll
Edge— Versus Level—Triggered Events
Mapping Files into Memory
mmap()
munmap()
Mapping Example
Advantages of mmap0
Disadvantages ofmmap()
Resizing a Mapping
Changing the Protection of a Mapping
Synchronizing a File with a Mapping
Giving Advice on a Mapping
Advice for Normal File I/O
The posix_fadvise() System Call
The readahead0 System Call
Advice Is Cheap
Synchronized, Synchronous, and Asynchronous Operations
Asynchronous I/O
I/O Schedulers and I/O Performance
Disk Addressing
The Life of an I/O Scheduler
Helping Out Reads
Selecting and Configuring Your I/O Scheduler
Optimzing I/O Performance
Conclusion
5.Process Management
Programs, Processes, and Threads
The Process ID
Process ID Allocation
The Process Hierarchy
pid_t
Obtaining the Process ID and Parent Process ID
Running a New Process
The Exec Family of Calls
The fork() System Call
Terminating a Process
Other Ways to Terminate
atexit()
on_ exit()
SIGCHLD
Waiting for Terminated Child Processes
Waiting for a Specific Process
Even More Waiting Versatility
BSD Wants to Play: wait3() and wait4()
Launching and Waiting for a New Process
Zombies
Users and Groups
Real, Effective, and Saved User and Group IDs
Changing the Real or Saved User or Group ID
Changing the Effective User or Group ID
Changing the User and Group IDs, BSD Style
Changing the User and Group IDs, HP—UX Style
Preferred User/Group ID Manipulations
Support for Saved User IDs
Obtaining the User and Group IDs
Sessions and Process Groups
Session System Calls
Process Group System Calls
Obsolete Process Group Functions
Daemons
Conclusion
……
6.Advanced Process Management
7.Threading
8.File and Directory Management
9.MemoryManagement
10.Signals
11.Time
A.GCC Extensions to the C Language
B.Bibliography
Index

文摘
版权页:



插图:



Furthermore, when the process issues an exec call, the effective user is usually unchanged.But it is during the exec callthat the key difference between real and effective IDs emerges: by executing a setuid (suid) binary, the process can change its effective user ID.To be exact, the effective user ID is set to the user ID ofthe owner ofthe programFile.For instance, because the /usr/bin/passwd File is a setuid file and root is its owner,when a normal user's shell spawns a process to exec this File, the process takes on the effective user ID of root regardless of who the executing user is.
Nonprivileged users may set the effective user ID to the real or the saved user ID, asyou'll see momentarily The superuser may set the effective user ID to any value.The saved user ID is the process's original effective user ID.When a process forks, the child inherits the saved user ID ofits parent.Upon an exec call, however, the kernel sets the saved user ID to the effective user ID, thereby making a record of the effective userID at the time of the exec.Nonprivileged users may not change the saved user ID; thesuperuser can change it to the same value as the real user ID.What is the point of all these values? The effective user ID is the value that matters: it'sthe user ID that is checked in the course of validating a process's credentials.The real user ID and saved user ID act as surrogates or potential user ID values that nonroot processes are allowed to switch to and from.The real user ID is the effective user ID belonging to the user actually running the program, and the saved user ID is the effectiveuser ID from before a suid binary caused a change during exec.
(hanging the Real or Saved User or Group ID
The user and group IDs are set via two system calls:
A call to setuid ( )sets the effective user ID ofthe current process.Ifthe current effective user ID of the process is O (root), the real and saved user IDs are also set.The root user may provide any value for uid, thereby setting all three of the user ID values to uid.A nonroot user is allowed only to provide the real or saved user ID for uid.In other words, a nonroot user can only set the effective user ID to one of those values.

内容简介
《Linux系统编程(第2版)(影印版)(英文版)》深入浅出地对Linux操作系统的Shell命令与Shell编程、系统管理与网络服务、应用程序开发与系统函数调用进行了描述,并详细分析了Linux操作系统的实现原理和思想。全书共分为7章。主要内容包括Linux操作系统基础、Linux系统管理基础、Shell及其编程、Linux进程管理及进程通信、Linux文件系统、Linux系统函数调用和Linux网络管理。《Linux系统编程(第2版)(影印版)(英文版)》可作为计算机及相关专业的Linux课程学习教材,可供Linux系统管理员和网络管理员作为参考用书,也可为Linux系统环境下的程序员编程提供帮助。

购买书籍

当当网购书 京东购书 卓越购书

PDF电子书下载地址

相关书籍

搜索更多