Linux System Programming (2nd Edition) Notes (this book is basically a simple use of Linux C API, entry level)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.