Advanced Linux Programming is divided into two parts. The first covers generic UNIX system services, but with a particular eye towards Linux specific information. This portion of the book will be of use even to advanced programmers who have worked with other Linux systems since it will cover Linux specific details and differences. For programmers without UNIX experience, it will be even more valuable. The second section covers material that is entirely Linux specific. These are truly advanced topics, and are the techniques that the gurus use to build great applications. While this book will focus mostly on the Application Programming Interface (API) provided by the Linux kernel and the C library, a preliminary introduction to the development tools available will allow all who purchase the book to make immediate use of Linux.
Linux programming involves creating code, compiling it, running it, and debugging it. This book teaches the advanced aspects of Linux programming. It is written for Linux programmers who are reasonably skilled in the C programming language and who need to cover the Linux C library.
I. ADVANCED UNIX PROGRAMMING WITH LINUX. 1. Getting Started.
Editing with Emacs. Compiling with GCC. Automating the Process with GNU Make. Debugging with GNU Debugger (GDB). Finding More Information. 2. Writing Good GNU/Linux Software.
Interaction With the Execution Environment. Coding Defensively. Writing and Using Libraries. 3. Processes.
Looking at Processes. Creating Processes. Signals. Process Termination. 4. Threads.
Thread Creation. Thread Cancellation. Thread-Specific Data. Synchronization and Critical Sections. GNU/Linux Thread Implementation. Processes Vs. Threads. 5. Interprocess Communication.
Shared Memory. Processes Semaphores. Mapped Memory. Pipes. Sockets.
II. MASTERING LINUX. 6. Devices.
Device Types. Device Numbers. Device Entries. Hardware Devices. Special Devices. PTYs. ioctl. 7. The /proc File System.
Extracting Information from /proc. Process Entries. Hardware Information. Kernel Information. Drives, Mounts, and File Systems. System Statistics. 8. Linux System Calls.
Using strace. access: Testing File Permissions. fcntl: Locks and Other File Operations. fsync and fdatasync: Flushing Disk Buffers. getrlimit and setrlimit: Resource Limits. getrusage: Process Statistics. gettimeofday: Wall-Clock Time. The mlock Family: Locking Physical Memory. mprotect: Setting Memory Permissions. nanosleep: High-Precision Sleeping. readlink: Reading Symbolic Links. sendfile: Fast Data Transfers. setitimer: Setting Interval Timers. sysinfo: Obtaining System Statistics. uname. 9. Inline Assembly Code.
When to Use Assembly Code. Simple Inline Assembly. Extended Assembly Syntax. Example. Optimization Issues. Maintenance and Portability Issues. 10. Security.
Users and Groups. Process User IDs and Process Group IDs. File System Permissions. Real and Effective IDs. Authenticating Users. More Security Holes. 11. A Sample GNU/Linux Application.
Overview. Implementation. Modules. Using the Server. Finishing Up.
III. APPENDIXES. Appendix A. Other Development Tools.
Static Program Analysis. Finding Dynamic Memory Errors. Profiling. Appendix B. Low-Level I/O.
Reading and Writing Data. stat. Vector Reads and Writes. Relation to Standard C Library I/O Functions. Other File Operations. Reading Directory Contents. Appendix C. Table of Signals.
Appendix D. Online Resources.
General Information. Information About GNU/Linux Software. Other Sites. Appendix E. Open Publication License Version 1.0.
Requirement on Both Unmodified and Modified Versions. Copyright. Scope of License. Requirements on Modified Works. Good-Practice Recommendations. License Options. Open Publication Policy Appendix. Appendix F. GNU General Public License.
Preamble. Terms and Conditions for Copying, Distribution and Modification. End of Terms and Conditions. How to Apply These Terms to Your New Programs. Index.
Table of Program Listings.
main.c (C source file),. reciprocal.cpp (C++ source file),. reciprocal.hpp (header file),. arglist.c (argc and argv parameters),. getopt_long.c (getopt_long function),. print_env.c (printing execution environment),. client.c (network client program),. temp_file.c (mkstemp function),. readfile.c (resource allocation during error checking),. test.c (library contents),. app.c (program with library functions),. tifftest.c (libtiff library),. print-pid.c (printing process IDs),. system.c (system function),. fork.c (fork function),. fork-exec.c (fork and exec functions),. sigusr1.c (signal handlers),. zombie.c (zombie processes),. sigchld.c (cleaning up child processes),. thread-create.c (creating threads),. thread-create2 (creating two threads), 64. thread-create2.c (revised main function),. primes.c (prime number computation in a thread),. detached.c (creating detached threads),. critical-section.c (critical sections),. tsd.c (thread-specific data),. cleanup.c (cleanup handlers),. cxx-exit.cpp (C++ thread cleanup),. job-queue1.c (thread race conditions),. job-queue2.c (mutexes),. job-queue3.c (semaphores),. spin-condvar.c (condition variables),. condvar.c (condition variables),. thread-pid (printing thread process IDs),. shm.c (shared memory),. sem_all_deall.c (semaphore allocation and deallocation),. sem_init.c (semaphore initialization),. sem_pv.c (semaphore wait and post operations),. mmap-write.c (mapped memory),. mmap-read.c (mapped memory),. pipe.c (parent-child process communication),. dup2.c (output redirection),. popen.c (popen command),. socket-server.c (local sockets),. socket-client.c (local sockets),. socket-inet.c (Internet-domain sockets),. random_number.c (random number generation),. cdrom-eject.c (ioctl example),. clock-speed.c (cpu clock speed from /proc/cpuinfo),. get-pid.c (process ID from /proc/self), 151. print-arg-list.c (printing process argument lists),. print-environment.c (process environment),. get-exe-path.c (program executable path),. open-and-spin.c (opening files),. print-uptime.c (system uptime and idle time),. check-access.c (file access permissions),. lock-file.c (write locks),. write_journal_entry.c (data buffer flushing),. limit-cpu.c (resource limits),. print-cpu-times.c (process statistics),. print-time.c (date/time printing),. mprotect.c (memory access),. better_sleep.c (high-precision sleep),. print-symlink.c (symbolic links),. copy.c (sendfile system call),. itemer.c (interal timers),. sysinfo.c (system statistics),. print-uname (version number and hardware information),. bit-pos-loop.c (bit position with loop), 194. bit-pos-asm.c (bit position with bsrl),. simpleid.c (printing user and group IDs),. stat-perm.c (viewing file permissions with stat system call),. setuid-test.c (setuid programs),. pam.c (PAM example),. temp-file.c (temporary file creation), 214. grep-dictionary.c (word search),. server.h (function and variable declarations),. common.c (utility functions),. module.c (loading server modules), 226. server.c (server implementation),. main.c (main server program),. time.c (show wall-clock time),. issue.c (GNU/Linux distribution information),. diskfree.c (free disk space information),. processes.c (summarizing running processes),. Makefile (Makefile for sample application program),. hello.c (Hello World),. malloc-use.c (dynamic memory allocation),. calculator.c (main calculator program), 274. number.c (unary number implementation),. stack.c (unary number stack),. definitions.h (header file for calculator program),. create-file.c (create a new file),. timestamp.c (append a timestamp),. write-all.c (write all buffered data),. hexdump.c (print a hexadecimal file dump),. lseek-huge.c (creating large files),. read-file.c (reading files into buffers),. write-args.c (writev function),. listdir.c (printing directory listings),.