Fundamental Concepts
Introduction to the basic concepts in the system
(although it is possible to run programs on a computer without a kernel, the presence of a kernel greatly t He writing and with the other programs, and increases, and flexibility available to programmers.
The Linux executable kernel is below/boot/vmlinuz.
(a) kernel's mission
1. Process Scheduling
2. Memory Management
3. Provision of a file system
4. Creation and termination of process creation and termination processes
The kernel can load a new program in memory, providing it with the resources (e.g., CPU, memory, and access to files) th At it needs into order to run. Such an instance of the a running program is termed a process. Once a process has completed execution, the kernel ensures that is the resources it uses are freed for subsequent reuse by LA ter programs.
5. Access to Devices
6. Networking
7. Provision of a system call application programming interface (API)
(03) Kernel description
By contrast, a running system has one kernel that knows and controls everything. The kernel facilities The running of all processes on the system. The kernel decides which process would next obtain access to the CPU, where it'll do, and the. The kernel maintains data structures containing information about all running processes and updates these structures as PR Ocesses are created, change state, and terminate. The kernel also maintains data structures all of the low-level data structures this enable the filenames used by programs To is translated into physical location on the disk. The kernel also maintains data structures that map the virtual memory of each process into the physical memory of the comp Uter and the Swap area (s) on disk. All communication between processes are done via mechanisms provided by the kernel. In response to requests from processes, the kernel creates new processes and terminates existing. Lastly, the kernel (in particular, device drivers)Performs all direct communication with the input and output devices, transferring information to and from user processes as re Quired.
(04) Directory
A directory is a special file whose contents take the form of a table of filenames coupled with references to the CORRESPO nding files. This filename-plus-reference association is called a link.
(05) Soft Link
And the shortcuts under Windows are very close to the meaning of that file.
Hard links actually create an alias for the file, and the linked file and the original file are actually the same file. You can see from the ls-i that the inode numbers for these two files are the same, that they are the same file, and that the soft link establishes a pointer to the contents of the linked file as pointers to the original files, which are two files.
(06) Relative path
A relative pathname specifies the location of a file relative to a process ' s-working directory, and is distinguish Ed from a absolute pathname by the absence of initial slash.
(07) File permissions, users are divided into three types of
For the purpose of accessing a file, the system divides users into three categories:the owner of the file (sometimes term Ed the user of the file, users who are members of the group matching the file's group ID (group), and the rest of the world (O ther).
(08) Unified I/O interface
The kernel translates the application ' I/O requests into appropriate File-system or device-driver operations that perform I/O on the target file or device.
(09) File descriptor
A file descriptor is typically obtained by a call to open (), which takes a pathname argument a file specifying upon I/O is performed.
To perform file I/O, C programs typically employ I/O functions contained in the standard C library. This is set of functions, referred to as the Stdio Library, includes fopen (), fclose (), scanf (), printf (), fgets (), fputs (), And so on. The stdio functions are layered on top of the I/O system calls (open (), close (), read (), write (), and.
(10) Process
When "a" is executed, the kernel loads the code of the "program" into virtual memory, allocates spaces for program variable s, and sets up kernel bookkeeping data structures to record various information (such as process ID, termination status, u Ser IDs, and group IDs, about the process.
A process can terminate in one of two ways:by requesting it own termination using the _exit () system call (or the Relate D exit () library function), or by being killed the delivery of a signal. In either case, the process yields a termination status, a small nonnegative integer value This is available for Inspectio n by the parent process using the "Wait" () system call.
(11) Mapping, mainly the mmap () function
(12) Dynamic library and Static library
If A is linked against a shared library, then, instead of copying object modules to the library into the Executa BLE, the linker just writes a record into the executable to indicate this at run time the executable needs to use that Sha Red Library. When the executable was loaded into memory in run time, a program called the Dynamic linker ensures the shared Librari Es required by the executable are found and loaded into memory.
(13) Inter-process communication and synchronization
Signals, pipes, sockets, File locking, massage queues, semaphores, shared memory.
(14) Signal
For example, the kernel could send a signal to a process when one of the following occurs:
The user typed the interrupt character (usually control-c) on the keyboard;
One of the process ' s children has terminated;
A timer (alarm clock) set by the process has expired; Or
The process attempted to access a invalid memory address.
(15) thread
One way of envisaging (imagine) threads is as a set of processes that share the same virtual memory, as OK as a range of other Attributes. Each thread are executing the same program code and shares the same data area and heap. However, each thread has it own stack containing the local variables and function call linkage information.
(Sessions), controlling terminals, and controlling processes
This part has not yet been understood.
Session A is a collection of process groups.
Sessions are used mainly by Job-control shells.
(17) pseudo terminal, do not understand.
Time is divided into system time and process time.
(a) Client-server architecture
A client-server application is one this is broken into two component processes:
A client, which asks the server to carry out some service by sending it a request message; and
A server, which examines the client ' s request, performs appropriate actions, and then sends a response Client.
(proc) file system
The/proc file system is a virtual file system this provides an interface to kernel data structures in a form that looks l IKE files and directories on a file system. This provides is easy to mechanism for viewing and changing various system attributes.
(20) Summary
In this chapter, we surveyed a range of fundamental concepts related to Linux system programming. An understanding of this concepts should provide readers with limited experience on Linux or UNIX with enough background To begin learning system programming.