Linux System Programming (2nd edition)Jump to: Navigation, search
Directory
- 1 Getting Started and basic concepts
- 2 file I/O
- 3 buffered I/O
- 4 Advanced file I/O
- 5 Process Management
- 6 Advanced Process Management
- 7 Threads
- 8 file and directory management
- 9 Memory Management
- Ten Signal
- One time (not here system programming, is the C library API)
- A Appendix A C-language gcc extension
- - Appendix B Bibliography
|
Getting Started and basic conceptsfile I/O
- Read (): Eintr Eagain
- Other errors: EBADF efault EINVAL EIO
- Append mode: The file location update before each write is an atomic operation
- Deferred write:/proc/sys/vm/dirty_expire_centisecs
- O_direct: Length, offset should be an integral multiple of the underlying device sector (general 4KB)
- Lseek--Pread/pwrite: Avoids the competition when multiple threads operate on the same FD
- P51 Select () and poll () are horizontal triggers, not edge triggers
- Poll () vs Select ()
- For a large file descriptor, which examines each bit in the collection, which is just a list (but how complex data structures are passed into the kernel?). )
- Select () re-creates fd_set on return, while poll () separates events from Revents
- VFS, page buffering, page write-back
buffered I/O
- P72 ungetc: As long as there is enough memory, Linux allows unlimited time to put back
- P72 Rewind (stream) = fseek (stream, 0, Seek_set) and empty error
- P80 Fflush () simply writes the user buffered data to the kernel buffer and does not guarantee final write to the physical medium (Fsync)
- Setvbuf:_io{n,l,f}buf unbuffered/Row buffer/block buffer
- Flockfile: Allow recursive locking?
Advanced file I/O
- Vector I/O? : Readv/writev
- Epoll (Linux proprietary?) )
- Epoll_create1
- Epoll_ctl (EPFD, OP, fd, event) <--This API looks complicated enough.
- Event->events |= Epollet; Edge trigger? (Non-blocking I/O, need to examine eagain carefully?) )
- Epoll_wait
- Mmap
- Long page_size = sysconf (_sc_pagesize); or GetPageSize (), direct page_size
- P109 library functions such as glibc, often using mremap () to achieve efficient realloc ()
- Posix.1 Mprotect () either read-only, write-only, or executable, not simultaneously
- Madvise (): Accurate pre-reading? (unless it is posix_fadv_random)
- Synchronnous vs Synchronized
- asynchronous I/O (AIO)
- I/O Scheduler
- Basic operations: Merging, sorting
- Deadline
- Anticipatory
- CFQ
- Noop (not sorted)
- Sort:/inode/physical blocks by absolute path
process management
- execl
- fork
- COW: These pages are marked as read-only and a page break occurs if a process tries to modify
- fork + exec = VFO RK: Don't use. Strictly speaking, Vfork is a bug, considering that when the exec call fails, the parent process will always be suspended ...
- posix/c89 exit ()
- atexit
- SIGCHLD
- waiting for child process to terminate
- wait
- waitpid
- waitid*
- BSD wait3 wait4 (here 3,4 refers to number of parameters) /li>
- system
- blocks sigchld during command execution, while SIGINT, Sigquit are ignored
- p153 take advantage of fork (), exec system call, and WA Itpid () Implementation of system () is a useful exercise
- Security vulnerability *
- Users and Groups *
- {Actual, valid, reserved} User ID/group ID (due to allowing Setuid/setgid, which leads to complexity here, is there a better design method?)
- sessions and process groups (you only need to know when implementing the shell?).
- Daemon
- roughly handles: Pid=fork ()--SETSID ()--ChDir ("/")--chose (0..nr_open)--and OPEN ("/D Ev/null ", O_RDWR)--DUP (0);d up (0)
- Daemon (nochdir, noclose)
Advanced Process Management
- CPU constrained vs I/O constraints
- CFS (based on weights, not time slices)
- Sched_yield ()
- Nice (character value)-_-
- Better: get/setpriority
- Ioprio_get/set
- Sched_get/setaffinity
- Real-time system (the content discussed here seems a bit too much)
- Delay, jitter *, deadlines
- Real-time scheduling policy (static priority, not affected by Nice): Sched_fifo/rr/other
- Resource status (RLIMIT) *
Threads
- P205 coroutines and fibers (beyond the scope of this book?) K
- p212 lock data, not code
- Pthreads
- Linuxthreads, NPTL, ngpt? )
- Pthread_setcancelstate/type, Pthread_cancel
- Join (should have only one can) and detach (make not join)
- Mutex
file and directory management
- Stat/lstat/fstat
- Chmod/fchmod
- Chown/lchown/fchown
- Extended attribute xattr (slightly)
- Getcwd
- Chdir/fchdir
- Mkdir/rmdir/opendir/readdir/closedir/getdents
- Link (oldpath, NewPath)
- Symlink
- Unlink
- Moving files: Rename
- Device node
- /dev/null,/dev/zero,/dev/full
- /dev/random,/dev/urandom
- Out-of-band Communication (IOCTL)
- INotify
- p270 0-length array (but actually causes memory to allocate many different sizes of blocks?). )
Memory Management
- Anonymous memory mapping (does not cause fragmentation of data segments?) )
- The glibc is used to satisfy the large allocation, the threshold value is generally 128KB
- p = mmap (NULL, 512*1024, prot_read| Prot_write, map_anonymous| Map_private,-1, 0);
- mallopt*
- $ malloc_check=1./test
- P300 do not use ALLOCA () allocated memory as arguments to function calls
- C99 variable length Array (vlas): Char buf[i];
- Memory operations
- Memset, bzero ==〉 priority to use Calloc?
- memcmp
- Memmove: can safely handle memory area overlap problem (memcpy not supported)
- mlock*
- Optimistic allocation strategy (only allocated when actual write), OOM Killer
Signal
- p329 to ensure reentrant functions in the signal *
- Signal Set *
- Sigprocmask
- Sigpending
- Sigsuspend
- Sigaction
time (not here system programming, is the C library API)
- typedef long time_t;
- struct Timeval {tv_sec; tv_usec;}
- struct TM {...}
- Time-Gettimeofday
Appendix A C-language gcc extension
- __attribute__ ((noinline/pure/const/noreturn/...))
- Likely (x)/unlikely (x)
- __builtin_return_address
- Case 1 ... 10:
Appendix B Bibliography
Linux System Programming (2nd Edition) Notes (this book is basically a simple use of Linux C API, entry level)