Translating The Linux Programming Interface – Part 0: Introduction

Tram Ho

Introduce

I am a programmer, I like many things. System programming is interesting to me. I don’t know anything yet. We will learn together. The content of the article is a translation of The Linux Programming Interface. A number of individual comments are added to the article content in parentheses. At the end of the article will include my summary, there may be some exercises I give, tips, …

Only seeing Linux, C programming probably makes many of you press the back button and read other articles. This is a famous book, and I believe you will learn a lot from books. I hope the translations will be helpful for you.

And this is the first translation. Introduction to the book.

The Linux Programming Interface – Part 0: Introduction

Mission

In this book I will describe the Linux Programming Interface – about system calls, library functions, and low level interface provided by Linux, a free version of UNIX operating system. These interfaces have been used, directly or indirectly, by all programs running on Linux. They allow applications to perform tasks such as I / O files, create or delete files, directories, create new processes, execute programs, set clocks, communicate between devices. processes, threads on the same computer and communicate between processes running on different computers on the same network. This is a set of low level interfaces, also called a system programming interface.

Although I focus on Linux, I also talk about standards and portablility issues, clearly differentiate and discuss specific details about discussing the common features of most UNIX implementations and POSIX standards. and Single UNIX Specification. Therefore, this book provides a comprehensive UNIX / POSIX programming interface and can be used by developers writing applications for other UNIX systems or focusing on cross-platform applications.

Object oriented

This book is aimed at:

  • Programmers and software designers build applications for Linux, other UNIX systems, or POSIX
  • Application programmers run between Linux and UNIX versions or between Linux and other operating systems
  • Teachers and students are teaching and learning Linux or UNIX
  • System administrators of “power users” want to expand their understanding of the Linux / UNIX programming interface.

I assume you have had programming experience, but no experience in system programming. I also assume you have experience reading C code, and know how to use Linux / Unix shell and basic commands. If you are new to Linux and UNIX., You will find help in chapter 2.

Linux and UNIX

This book can completely talk about the UNIX standards (that is, POSIX) because most of the features found in UNIX implementations are also available in Linux and vice versa. However, when writing portable applications is a worthy purpose, it is also important to describe Linux extensions to UNIX standards. Because of the popularity of Linux. On the other hand, non-standard extensions are sometimes needed, because of performance or access functionality not available in the UNIX programming interface (All UNIX implementtations provide nonstandard extensions for this reason).

Therefore, I am writing this book as a utility for programmers to work with all UNIX implementations, I also have full coverage of the features specified for Linux. Features include:

  • epoll: a mechanism to get notifications of incoming and outgoing events
  • inotify: a mechanism to track changes of files and folders
  • capabilities: mechanism to authorize a process to be executed by superuser
  • extended attributes
  • i-node flags
  • clone () system calls
  • / proc file system
  • Linux specific I / O, signals, timers, threads, shared libraries, interprocess communication, and sockets

Usage and organization

You can use this book in at least 2 ways.

  • As a tutorial on Linux / UNIX programming interface. You can read it from start to finish. After each chapter, do the exercises
  • As a comprehensive reference about Linux / UNIX programming interface.

I have grouped the chapters of this book into sections like below.

  1. Foundations and concepts: History of UNIX, C, Linux, overview of UNIX standards (chapter 1); a programmer-oriented introduction to Linux and UNIX concepts (chapter 2), and the basic concepts of system programming on Linux and Unix (chapter 3).
  2. Basic features of the system programming interface: I / O files (chapters 4 and 5). Progress (Chapter 6). Memory allocation (chapter 7). users and groups (Chapter 8). process cridential (chapter 9); time (chapter 10). system limits and options (chapter 11); Obtain system and process information (chapter 12).
  3. Advanced features of the system programming interface: file IO buffering (chapter 13). file system (Chapter 14). file attributes (chapter 15). extened attributes (chapter 16). access control lists (chapter 17). directories and links (chapter 18). monitoring file event (chapter 19); signals (chapters 20 to 22) and timers (chapters 23)
  4. Process, Programs and threads: Creating new program ties, stopping program languages, monitoring subprocesses, and executing programs (chapters 24 to 28) and POSIX threads (chapters 29 to 33).
  5. Advanced process and program topics: process groups, sessions, job control (chapter 34), process priorities and scheduling (chapter 35); process resources (chapter 36). daemons (chapter 37); writing secure privileged programs (chapter 38); capabilities (chapter 39); login accounting (chapter 40); and shared libraries (chapters 41 and 42).
  6. Interprocess communication (IPC): overview of IPC (chapter 43); pipes and FIFOS (chapter 44). System V IPC – message queues, semaphores, shared memory (chapters 45-48). memory mappings (chapter 49). virtual memory operations (chapter 50). POSIX IPC – message queues … chapters 51 to 54); file locking (chapter 55).
  7. Sockets and network programming: IPC and network programming with sockets (chapters 56 to 61)
  8. Advanced IO topics. terminals (chapter 62). alternative IO models (chapter 63), and pseudoterminal (chapter 64).

Sample programs

I illustrate how to use most of the interfaces described in the book briefly, complete programs, many of which are designed to allow you to easily try from the command line to see system calls. and library functions. In conclusion, the book includes many examples of about 15,000 lines of C code and shell session logs.

While reading and testing examples is effective to get started, the most effective way to reinforce the concepts discussed is to write code, try to fix sample programs to try to implement ideas, or write one. new program.

All source code in the book is available and downloadable from the website of this book. The purpose and details of the programs are described in the comments of the source code. Makefiles are provided to build programs and come with README files that send program details.

Source code is free to redistribute or repair with the GNU Affero General Public License (Affero GPL) version 3.

Homeworks

Most chapters have exercises, sometimes with exercises that suggest sample code. Other exercises are questions related to the concepts discussed in the chapter and also have suggestions for programs you can write to reinforce your understanding. You can find solutions to select exercises in Appendix F

Standards and portability

Through this book, I talk about portability issues. You will find frequently related standards, especially POSIX.1-2001 and Single UNIX Specification version 3 (SUSv3) standard. You will also find details about the changes. About non-standard features. I will denote different scopes in UNIX implementations. I also highlight the important features of LINUX, as well as the small differences between system call implementations, and libraries on Linux and UNIX implementations. Where a feature is not specified, you can assume that it is the standard feature that appears in most UNIX implementations.

I have tested most of the sample programs presented in the book with Solaris, FreeBSD, Mac OS X, Tru64 UNIX and HP-UX. To improve portability of some system features, the website for this book provides an alternative version of the examples with the extended code appearing in the book.

Linux kernel and C library versions

The book focuses mainly on Linux 2.6.x, the kernel version is most widely used at the time of writing. Details about Linux 2.4 are also covered. I also pointed out the differences about Linux 2.4 and 2.6. New features in 2.6.x, exactly 2.6.34 will be recorded.

With respect to the C library, focus on the GNU C library (glibc) version 2. Other points in the glibc 2.x version are also noted.

(Now the Linux kernel has version 5. But we still follow this book.)

Use progmramming interface from other languages.

Although the sample programs are written in C, you can use the interfaces described in books from many other languages ​​- for example, translation languages ​​such as C ++, Pascal, Modula, Ada, FORTRAN, D, and languages. Scripting languages ​​such as Perl, Python, Ruby (Java is another model).

summary

The next article is difficult to talk about the history of UNIX / Linux. Get ready for the next post. Let’s start by installing and using linux. Please use as the main operating system.

Do not try to remember, use it

Some other sources

Ariff Butt’s Channel https://www.youtube.com/channel/UCMqUl4U_8LwHiXT09_ouzxQ The Linux Command line http://linuxcommand.org/tlcl.php

Share the news now

Source : Viblo