Chapter 1 Overview of operating system

What is an operating system?

Users who want software to run on computer hardware must rely on an operating system.

  1. A layer of software that is closest to hardware, the lowest level of software.
  2. It is the manager of system resources, responsible for the management and coordination of hardware, software and other resources
  3. Provide easy-to-use services for upper-layer users or applications
  4. Providing services to other software, the operating system interacts with the software in order to allocate any necessary resources to it to run.

2. Main functions of the OPERATING system

  1. Process management: process synchronization, process communication, process deadlocks, and so on.
  2. Memory management: memory allocation, virtual memory, address mapping, and more.
  3. File management: storage space management, file read and write management and protection and so on.
  4. Device management: device allocation, virtual devices, and so on.

Operating systems divide computers into two states: user state and kernel state.

Kernel-mode encapsulates some underlying code to avoid malicious software damage to the operating system. If a process needs to use kernel-mode functions when running in user mode, it needs to make system calls to fall into kernel state, which is completed by the operating system.

3. Why distinguish user mode from kernel mode?

  1. Security: prevent user programs from maliciously or accidentally damaging system/memory/hardware resources;
  2. Encapsulation: the user program does not need to implement more low-level code;
  3. Scheduling: If multiple user programs are waiting for keyboard input, scheduling is needed. Unified to the operating system scheduling more convenient.

A process running in user mode may read data directly from a user program

Kernel-running processes can access almost any resource on the computer

What is a system call? And library functions

  1. Commonly used software is running in user mode, if these software needs to perform the kernel-mode functions provided by the operating system (such as files, processes, memory management, etc.) must be completed by system call to the operating system. This process involves switching between user mode and kernel mode, which costs a lot.

  2. Library function: is to write some commonly used functions into a file, so that users write applications to call, generally provided by a third party, occur in the user address space. For example, class libraries in Java.

Common system calls:

  • Equipment management. Request or release the device, and start the device.
  • File management. Read, write, create, and delete files.
  • Process control. Complete the process creation, cancellation, blocking, and wake up functions.
  • Process communication. Completes functions such as messaging or signaling between processes.
  • Memory management. The system allocates and reclaims memory, and obtains the size and address of the memory occupied by a job.

Linux system calls mainly include the following:

Task Commands
Process control fork(); exit(); wait();
Process of communication pipe(); shmget(); mmap();
File operations open(); read(); write();
Equipment operation ioctl(); read(); write();
Information maintenance getpid(); alarm(); sleep();
security chmod(); umask(); chown();

5. How does the computer switch between user mode and kernel mode?

Interrupt is the only way for CPU to switch from user state to kernel state. The essence of interrupt is that the operating system needs to intervene in the management work, so that the operating system can obtain the control of the computer. Only with interrupt can multiple programs be executed concurrently.

When an interrupt occurs:

  1. When an interrupt occurs, the CPU immediately goes into a core mindset
  2. When an interruption occurs, the currently running process is suspended and the operating system kernel handles the interruption
  3. Different interrupt signals are processed differently.

There are different types of interrupts:

  1. External interruption:
  2. Internal interrupt: The source of the signal is inside the CPU

6. What is the difference between concurrency and parallelism?

Concurrency is macroscopically the ability to run multiple programs simultaneously over a period of time, while parallelism is the ability to run multiple instructions at the same time.

Parallelism requires hardware support, such as multi-pipeline, multi-core processor, or distributed computing system.

The operating system enables programs to run concurrently by introducing processes and threads.

7. What’s the difference between asynchronous and synchronous?

Synchronization is when all operations are completed and the result is returned to the user.

Asynchronous, not waiting for all operations to complete, corresponding to the user request.

8. What is virtual technology?

Virtualization transforms one physical entity into multiple logical entities.

There are two main virtualization technologies: time (time) division multiplexing and space (space) division multiplexing.

Multiple processes can execute concurrently on the same processor using time division multiplexing, where each process takes turns occupying the processor, executing only a small time slice at a time and switching quickly.

Virtual memory uses space division multiplexing, which abstracts physical memory into an address space that each process has its own. The pages in the address space are mapped to physical memory. All pages in the address space do not need to be in physical memory. When a page that is not in physical memory is used, the page replacement algorithm is performed to replace the page into memory.

Virtual memory technology is essentially memory time-sharing multiplexing, allowing programs to run in a much smaller memory space.