New to Linux programming and Linux system administration Show me the newest Linux articles and tutorials on developerWorks The Linux on developerWorks contains hundreds of articles, tutorials, and tips to help developers with Linux programming and application development, as well as Linux system administration. But if you are trying to find your way in a new topic, all of that information can be overwhelming. It places all the Linux basics in context and ties together relevant developerWorks articles, tutorials, and tips, as well as IBM learning services education, workshops, and IBM products for your further investigation. So, what is Linux, anyway? In the simplest terms, Linux is an operating system. Linux itself is actually just the kernel; it implements multitasking and multiuser functionality, manages hardware, allocates memory, and enables applications to run.
|Published (Last):||12 January 2017|
|PDF File Size:||16.16 Mb|
|ePub File Size:||7.14 Mb|
|Price:||Free* [*Free Regsitration Required]|
Introduction and Essential Concepts This book is about system programming, which is the practice of writing system software. System software lives at a low level, interfacing directly with the kernel and core system libraries. Your shell and your text editor, your compiler and your debugger, your core utilities and system daemons are all system software.
But so are the network server, the web server, and the database. These components are entirely system software, primarily if not exclusively interfacing with the kernel and the C library.
Other software such as high-level GUI applications lives at a higher level, delving into the low level only on occasion. Some programmers spend all day every day writing system software; others spend only part of their time on this task.
There is no programmer, however, who does not benefit from an understanding of system programming. In particular, this book is about system programming on Linux. Linux is a modern Unix-like system, written from scratch by Linus Torvalds and a loose-knit community of programmers around the globe.
Although Linux shares the goals and philosophy of Unix, Linux is not Unix. Instead, Linux follows its own course, diverging where desired and converging only where practical. The core of Linux system programming is the same as on any other Unix system. Beyond the basics, however, Linux differentiates itself—in comparison with traditional Unix systems, Linux supports additional system calls, behaves distinctly, and offers new features. System Programming Traditionally, all Unix programming was system-level programming.
Unix systems historically did not include many higher-level abstractions. Consequently, it can be said that this book is a book on Linux programming in general. But note that this book does not cover the Linux programming environment —for example, there is no tutorial on make in these pages. What is covered is the system programming API exposed on a modern Linux machine. We can compare and contrast system programming with application programming, which differ in some important aspects but are quite similar in others.
Where system programs interface primarily with the kernel and system libraries, application programs also interface with high-level libraries. These libraries abstract away the details of the hardware and operating system. Such abstraction has several goals: portability with different systems, compatibility with different versions of those systems, and the construction of higher-level toolkits that are easier to use, more powerful, or both.
How much of a given application uses system versus high-level libraries depends on the level of the stack at which the application was written. Some applications are written exclusively to higher-level abstractions. But even these applications, far from the lowest levels of the system, benefit from a programmer with knowledge of system programming.
Despite this trend in application programming, the majority of Unix and Linux code is still written at the system level. This is traditional system programming—Apache, bash, cp, Emacs, init, gcc, gdb, glibc, ls, mv, vim, and X. These applications are not going away anytime soon. The umbrella of system programming often includes kernel development, or at least device driver writing. But this book, like most texts on system programming, is unconcerned with kernel development.
Instead, it focuses on user-space system-level programming, that is, everything above the kernel although knowledge of kernel internals is a useful adjunct to this text. Device driver writing is a large, expansive topic, best tackled in books dedicated to the subject. What is the system-level interface, and how do I write system-level applications in Linux?
What exactly do the kernel and the C library provide? How do I write optimal code, and what tricks does Linux provide? What interesting system calls are provided in Linux compared to other Unix variants? How does it all work? Those questions are at the center of this book. Cornerstones of System Programming There are three cornerstones of system programming in Linux: system calls, the C library, and the C compiler.
Each deserves an introduction. System Calls System programming starts and ends with system calls. System calls often shortened to syscalls are function invocations made from user space—your text editor, favorite game, and so on—into the kernel the core internals of the system in order to request some service or resource from the operating system. Linux implements far fewer system calls than most other operating system kernels. In the Linux kernel, each machine architecture such as Alpha, x, or PowerPC can augment the standard system calls with its own.
Consequently, the system calls available on one architecture may differ from those available on another. Nonetheless, a very large subset of system calls—more than 90 percent—is implemented by all architectures. It is this shared subset, these common interfaces, that we cover in this book.
Invoking system calls It is not possible to directly link user-space applications with kernel space. For reasons of security and reliability, user-space applications must not be allowed to directly execute kernel code or manipulate kernel data.
The application can then trap into the kernel through this well-defined mechanism and execute only code that the kernel allows it to execute. The exact mechanism varies from architecture to architecture. On i, for example, a user-space application executes a software interrupt instruction, int, with a value of 0x This instruction causes a switch into kernel space, the protected realm of the kernel, where the kernel executes a software interrupt handler—and what is the handler for interrupt 0x80?
None other than the system call handler! The application tells the kernel which system call to execute and with what parameters via machine registers. System calls are denoted by number, starting at 0.
On the i architecture, to request system call 5 which happens to be open , the user-space application stuffs 5 in register eax before issuing the int instruction. Parameter passing is handled in a similar manner. On i, for example, a register is used for each possible parameter—registers ebx, ecx, edx, esi, and edi contain, in order, the first five parameters.
In the rare event of a system call with more than five parameters, a single register is used to point to a buffer in user space where all of the parameters are kept. Of course, most system calls have only a couple of parameters. Other architectures handle system call invocation differently, although the spirit is the same. As a system programmer, you usually do not need any knowledge of how the kernel handles system call invocation. That knowledge is encoded into the standard calling conventions for the architecture, and handled automatically by the compiler and the C library.
On modern Linux systems, the C library is provided by GNU libc, abbreviated glibc, and pronounced gee-lib-see or, less commonly, glib-see. The GNU C library provides more than its name suggests.
In addition to implementing the standard C library, glibc provides wrappers for system calls, threading support, and basic application facilities. Over time, support was added for more and more languages. Consequently, nowadays gcc is used as the generic name for the family of GNU compilers. However, gcc is also the binary used to invoke the C compiler.
In this book, when I talk of gcc, I typically mean the program gcc, unless context suggests otherwise. APIs and ABIs Programmers are naturally interested in ensuring their programs run on all of the systems that they have promised to support, now and in the future. They want to feel secure that programs they write on their Linux distributions will run on other Linux distributions, as well as on other supported Linux architectures and newer or earlier Linux versions.
At the system level, there are two separate sets of definitions and descriptions that impact portability. Both define and describe the interfaces between different pieces of computer software. It provides abstraction by providing a standard set of interfaces——usually functions—that one piece of software typically, although not necessarily, a higher-level piece can invoke from another piece of software usually a lower-level piece.
For example, an API might abstract the concept of drawing text on the screen through a family of functions that provide everything needed to draw the text. It may use the API as-is, or not use it at all: take it or leave it! A real-world example of an API is the interfaces defined by the C standard and implemented by the standard C library. This API defines a family of basic and essential functions, such as memory management and string-manipulation routines.
It defines how an application interacts with itself, how an application interacts with the kernel, and how an application interacts with libraries. Whereas an API ensures source compatibility, an ABI ensures binary compatibility, guaranteeing that a piece of object code will function on any system with the same ABI, without requiring recompilation. ABIs are concerned with issues such as calling conventions, byte ordering, register use, system call invocation, linking, library behavior, and the binary object format.
The calling convention, for example, defines how functions are invoked, how arguments are passed to functions, which registers are preserved and which are mangled, and how the caller retrieves the return value. Although several attempts have been made at defining a single ABI for a given architecture across multiple operating systems particularly for i on Unix systems , the efforts have not met with much success.
Instead, operating systems—Linux included—tend to define their own ABIs however they see fit. The ABI is intimately tied to the architecture; the vast majority of an ABI speaks of machine-specific concepts, such as particular registers or assembly instructions.
Thus, each machine architecture has its own ABI on Linux. In fact, we tend to call a particular ABI by its machine name, such as Alpha, or x Thus, the ABI is a function of both the operating system say, Linux and the architecture say, x System programmers ought to be aware of the ABI but usually need not memorize it.
The ABI is enforced by the toolchain—the compiler, the linker, and so on—and does not typically otherwise surface. Knowledge of the ABI, however, can lead to more optimal programming and is required if writing assembly code or developing the toolchain itself which is, after all, system programming.
New to Linux programming and Linux system administration
Introduction and Essential Concepts This book is about system programming, which is the practice of writing system software. System software lives at a low level, interfacing directly with the kernel and core system libraries. Your shell and your text editor, your compiler and your debugger, your core utilities and system daemons are all system software. But so are the network server, the web server, and the database. These components are entirely system software, primarily if not exclusively interfacing with the kernel and the C library.
Your UNIX/Linux: The Ultimate Guide
Gazahn Learn more about Amazon Prime. There is another review here that gives the lack of illustrations as a drawback, but I disagree as all of the example code is well presented and there is no real need for any sort of illustration beyond that. Hello World, this is a test. Track my order s Anti-bot validation Type the characters you see in the picture above.