An in-depth guide to programming Linux from the most recognized leaders in the Open Source community.
Table of Contents
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),.
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.
Mark Mitchell received a bachelor of arts degree in computer science from Harvard in 1994 and a master of science degree from Stanford in 1999. His research interests centered on computational complexity and computer security. Mark has participated substantially in the development of the GNU Compiler Collection, and he has a strong interest in developing quality software.
Jeffrey Oldham received a bachelor of arts degree in computer science from Rice University in 1991. After working at the Center for Research on Parallel Computation, he obtained a doctor of philosophy degree from Stanford in 2000. His research interests center on algorithm engineering, concentrating on flow and other combinatorial algorithms. He works on GCC and scientific computing software.
Alex Samuel graduated from Harvard in 1995 with a degree in physics. He worked as a software engineer at BBN before returning to study physics at Caltech and the Stanford Linear Accelerator Center. Alex administers the Software Carpentry project and works on various other projects, such as optimizations in GCC.
Mark and Alex founded CodeSourcery LLC together in 1999. Jeffrey joined the company in 2000. CodeSourcery's mission is to provide development tools for GNU/Linux and other operating systems; to make the GNU tool chain a commercial-quality, standards-conforming development tool set; and to provide general consulting and engineering services. CodeSourcery's Web site is http://www.codesourcery.com.