Skip to content

Summary of the Book The Linux Programming Interface

yan li edited this page Jun 25, 2020 · 7 revisions

2.1 Linux kernel

what is linux kernel

Linux kernel is a central software layer that manages and allocates computer resources (i.e., the CPU, RAM, and devices). Linux kernel executable resides at the pathname /boot/vmlinuz, e.g. vmlinuz-4.15.0-88-generic

kernel performs the following tasks

Process scheduling

Linux is a preemptive multitasking(抢占式多任务) operating system, Multitasking means that multiple processes (i.e., running programs) can simultaneously reside in memory and each may receive use of the CPU(s). Preemptive means that the rules governing which processes receive use of the CPU and for how long are determined by the kernel process scheduler.

Memory management

  • Processes are isolated from one another and from the kernel.
  • Only part of a process needs to be kept in memory.

Provision of a file system

Creation and termination of processes

Access to devices

Networking

Provision of a system call application programming interface (API)*

Processes can request the kernel to perform various tasks using kernel entry points known as system calls

Kernel mode and user mode

Areas of virtual memory can be marked as being part of user space or kernel space.

Process versus kernel views of the system

Difference between Process and kernel:a process can request that the kernel create another process. a Process can not create another process and can not finish itself. Kernel controlls everything about processes.

2.4 Single Directory Hierarchy, Directories, Links, and Files

symbolic link

A symbolic link provides an alternative name for a file. Symbolic link is a specially marked file containing the name of another file.

File ownership and permissions

  • read permission allows the contents of (i.e., the filenames in) the directory to be listed;
  • write permission allows the contents of the directory to be changed (i.e., filenames can be added, removed, and changed);
  • execute (sometimes called search) permission allows access to files within the directory (subject to the permissions on the files themselves).

Filters

  1. A filter is the name often applied to a program that reads its input from stdin, performs some transformation of that input, and writes the transformed data to stdout.
  2. Examples of filters include cat, grep, tr, sort, wc, sed, and awk.

2.7 Processes

  • A process is an instance of an executing program. When a program is executed, the kernel loads the code of the program into virtual memory, allocates space for program variables, and sets up kernel bookkeeping(簿记) data structures to record various information (such as process ID, termination status, user IDs, and group IDs) about the process.
  • processes are the entities among which the kernel must share the various resources of the computer

Process memory layout

A Process has the following segments(parts):

  • Text: the instructions of the program.
  • Data: the static variables used by the program.
  • Heap: an area from which programs can dynamically allocate extra memory.
  • Stack: a piece of memory that grows and shrinks(缩小) as functions are called and return and that is used to allocate storage for local variables and function call linkage information.

Daemons

A daemon is a process, that is long-lived and run in the background and has no controlling terminal.

certain daemons are run as kernel threads

the following processes sind daemons: cron, sshd, httpd and inetd

Clone this wiki locally