In the previous article, we know that most operating systems can provide abstraction for the underlying hardware, acting as a middleman for the management of the upper application software and the lower hardware resources, and the interface level abstraction of the lower hardware to facilitate the invocation of the upper application software.

In the interaction of resources and information up and down, the operating system must provide a practical concept from the abstract to the concrete to help establish better communication and communication. Therefore, this article is based on some basic concepts of operating system, and introduces how operating system establishes an accurate communication bridge between hardware and application software.

1 process

Processes and procedures

The most common concept in operating systems is “process”. There are plenty of interview questions and technical optimizations to justify its importance in understanding operating systems. In fact, through “process”, programmers can more intuitively understand the software they are developing, and can deeply understand what the operating system does in the software running.

Simply put, a process is a program that is executing. Each process contains its own segment of address space, which can be considered a portion of memory space. In such an address space, processes can read and write to memory as needed.

The address space typically contains executable programs, their data and their stacks. There is also a set of resources associated with each process, typically including registers (including program counters and stack Pointers) and all the other information needed to run the program. From this we can see that the program itself is only a description of instructions, data and its organizational form, and the actual running instance of the program is a process.

However, process and program are not completely equal, they are not a simple one-to-one correspondence, but in different levels of expression. Their main differences are:

  • A program is the static text of a process, while a process is a dynamic process that executes a program.
  • Process and program are not one-to-one correspondence, the same program can run in different processes, a process can also execute multiple programs;
  • The program is a kind of text that can be saved for a long time, while the process is a temporary execution process.
  • Processes are independent units of operating system allocation and scheduling, while programs are applications above the operating system hierarchy.

Process status

From the above we know that a process can be viewed as a dynamic process in which a program runs. In order to better describe the process, we define three basic states for the running process, including ready, executing and blocking.

This is known as the three-state model, which describes the state of a process over its lifetime. The transition process for each state can be illustrated in the following figure.

Ready state means that the process has been allocated all necessary resources except CPU. In this state, the process is ready to execute as soon as the CPU gives it permission to execute.

When there are multiple processes in the ready state, the different processes are grouped into different queues according to their priorities. A process that enters the ready state because its time slice has run out is placed in a lower priority queue, while a process that enters the ready state because its I/O operation has completed is placed in a higher priority queue.

The execution status refers to the normal running status of the process. When the executing process waits for an event to be sent (usually for I/O), it abandons the CPU and enters a temporary blocking state. Once the CPU is free, it will be allocated to another ready process through a different scheduling algorithm.

The blocking state corresponds to a buffer state between the ready state and the execution state. When a process in the executing state cannot execute normally, it first enters the blocking state, waits for the required request to complete, and then returns to the ready state, waiting for the next CPU allocation and execution.

The three-state model is the most simplified model to describe the process state transition. In fact, these three states cannot handle the complex process running process. Therefore, in order to better manage and schedule the process, on the basis of the three-state model, two process states are introduced, namely the creation state and the termination state, which is the five-state model.

The created state refers to the newly created state of a Process. In this state, you need to wait for the operating system to complete the creation and allocation of all required information about the Process, including the creation of Process Control blocks (PCBS), the loading of programs, and the creation of address space. After these preparations are complete, the process moves to a ready state and is placed in a ready queue.

PCB: Process control block, used to store the process management and control information data structure

The create state may not seem very useful, since the process must have completed the creation when it was ready. However, it is still introduced to ensure the integrity of the process control block. You cannot enter the ready state until you have completed all of the process preparation (PCB generation creation and resource allocation) in the Create state.

This ensures the correctness of the ready process and improves the flexibility of the operating system to manage the process. The operating system can manage process creation and resource allocation from the very beginning, saving system resource control to a greater extent.

The termination state represents the end of a process. After the process is executed, the operating system needs to handle the running results of the process in the termination state. Such cleanup involves recycling resources used by the process and passing on information needed by other processes. Finally, the operating system also needs to free the memory of the terminated process, empty its PCB and return the memory to the system.

A terminating state means the end of a process’s execution cycle, but it does not mean that the process is normally terminated. When a process has unexpected errors or is terminated by the operating system or other processes, it enters the terminated state and reclaims various resources.

In fact, even the five-state model of a process is not enough to describe the complex running process of a process. Due to the limitation of the internal resources of the system, not all the requirements of running for all processes can be met. Therefore, on this basis, the state of suspension ready and the corresponding state of suspension blocking are introduced.

In the seven-state model, active readiness refers to the state in which a process is in main memory and can be scheduled. The static ready state refers to the state when the ready process is switched to auxiliary storage, which cannot be directly scheduled. Only when there is no active ready process in main storage or the suspended process has a higher priority, the system will bring the suspended ready process back to main storage and convert it to active ready state.

An active blocked state means that the process is in main memory and enters the active ready state as soon as the waiting event occurs. Static blocking refers to the state in which the blocking process switches to auxiliary storage and enters the static ready state once the waiting event is generated.

There is so much more to know about processes, including PCBS, interprocess communication, and thread-related concepts and fundamentals. However, due to the space limitation of this article, it is not good to expand too much here. The thread state model has been introduced briefly, but the details of processes and threads will be covered in more detail in the next few articles.

The reason for the great effort to introduce the threading model is simply that it is the most intuitive connection between threads and the operating system. The purpose of constantly optimizing the threading model is to make the operating system better able to manage the problem of program software and resource allocation. Through the management of threads to achieve the purpose of reasonable allocation of resources. This itself is an important embodiment of the role of the operating system, it can be said that the operating system is the first major soul concept.

2 Address Space

The concept of address space is mentioned slightly in the introduction of processes, and in fact has an inseparable relationship with processes. Generally speaking, each process has its corresponding address space, which stores the information and data that the process needs to run the program.

We know that every computer has some main memory to hold the programs that are being executed. In a very simple operating system, only one program runs in memory at a time. To run the second program, you must delete the first program and then place the second program in memory.

More complex operating systems can solve this problem by allowing multiple programs to be stored in memory at the same time. And to prevent them from interfering with each other (and crosstalk with the operating system), some sort of protection mechanism is generally found in the hardware.

Typically, each process has a set of addresses that it can use, usually from 0 to a maximum. In the simplest case, the maximum amount of address space that a process has is less than the total capacity of main memory. In this way, the process can fill up its address space and have enough space in main memory to hold this information.

But what if a process’s address space is larger than the computer’s main memory, and the process wants to use it all?

In the earliest computers, such demands were excessive. Now, thanks to a technology called virtual memory, the operating system can abstract the address space into a set of addresses that processes can reference, separating the address space from the computer’s physical memory. As a result, the address space of the process may be larger than the physical memory of the computer.

The management of address space and physical memory is an important part of operating system functionality, as well as the basis for an in-depth understanding of operating system forward/thread management.

3 files

Another key concept supported by almost all operating systems is the file system. The main function of the operating system is to hide the features of disks and other I/O devices and provide programmers with a neat abstract model of device-independent or hardware-independent files.

Obviously you need to create files, delete files, read files, and write files through operating system calls. Before reading a file, it must be placed on disk and opened, and after it is read, it should be closed so that calls can be provided to perform these operations.

hierarchy

To provide a place to store and find files, most PC operating systems have the concept of a directory as a way of grouping files together. Directories are presented in the form of folders in which multiple directories can be nested.

The entire file system is modeled as a hierarchy, like a multi-fork tree. Search from the top folder in the form of tree trunks and branches to find the file directory at the bottom.

|

Each file in the directory hierarchy can be specified by giving its pathname at the top of the directory hierarchy (the root directory). Such absolute pathnames contain a list of directories that must be traversed from the root directory to reach the file, separated by slashes.

D:/study/ learning resources/personal/private learning ぶ keynote speech. Mp4

Each process has a current working directory in which to look for pathnames that do not begin with a slash. This is called the relative path. In addition, a process can change its working directory by issuing a system call specifying a new working directory.

One thing to note is that before you can read or write a file, you must first open it and then check permissions. If access is allowed, the system returns a small integer called the file descriptor for subsequent operations. If access is forbidden, an error code is returned.

mount

Another important concept in the operating system file system is mount. Most desktop computers have one or more CD-ROM drives into which you can insert CD-ROMs, DVDS, and optical discs. (The following uses Unix as an example.)

These external CD – ROM drives are actually considered a file system, independent of and unrelated to the root file system on the computer’s own hard disk. To provide an elegant way to handle these removable media, the operating system allows the file system on the disc to be attached to the main tree of the root file system, known as mount.

However, the file system cannot be used because the pathname cannot be specified on the CD-ROM. UNIX does not allow the use of drive names or numbers as prefixes to pathnames. This is the device dependency that the operating system should eliminate. Instead, the system call allows the file system on the CD-ROM to attach to the root file system.

In Figure 1-15 (b), the file system on the CD-ROM is installed in directory B, so you can access the files /b/x and /b/y. If directory B contains other files, they will not be accessible when installing the CD-ROM because /b will refer to the root directory of the CD-ROM. In general, though, file systems almost always hang on empty directories. If the system contains multiple hard disks, they can all be mounted into a single tree.

|

|

The special file

Another important concept in file systems is dedicated files. The purpose of providing a dedicated file is to make the I/O device look like a file. In this way, you can read and write them using the same system calls you use to read and write files.

There are two kinds of special files: block special files and character special files. Block special files are used to model devices that consist of a set of randomly addressable blocks, such as disks. By opening and reading a block-specific file, the program can directly access the corresponding block on the device, regardless of the structure of the file system contained on it.

Similarly, character-specific files can be used to model printers, modems, and other devices that accept or output character streams. By convention, special files are stored in the /dev directory. For example, dev/ LP might be a printer (once called a line printer).

In addition, there is a special file, which is pipes. Yes, the one used for interprocess communication. In fact, a pipe is a pseudo-file that can be used to connect two processes. If processes A and B want to talk using pipes, they must be set up in advance.

|

When process A wants to send data to process B, it will write to the pipe as if it were an output file. In fact, the implementation of a pipe is very similar to the implementation of a file. Process B can read data by reading data from the pipe as if it were an input file.

Therefore, communication between processes is very similar to reading and writing ordinary files. Even more powerful, special system calls are made when the process discovers that the output file being written is not a real file, but a pipe. Of course, the implementation is not covered here, but will be covered later when we talk about interprocess communication. Keep paying attention and get more

4 Input/output

All computers have physical devices that take inputs and produce outputs, known as I/O. After all, what good would a computer be if the user did the required work and didn’t know what to do and couldn’t get the results?

There are many input and output devices in modern computers, including keyboard, mouse, monitor, printer and so on. These devices are managed and allocated resources by the operating system.

Therefore, each operating system has an I/O subsystem to manage its I/O devices. Some I/O software is device agnostic, which means that it is equally applicable to many or all I/O devices. Other I/O software, such as device drivers, is used for specific I/O devices.

I/O devices are classified as follows:

(1) Character device, also known as human-computer interaction device. The user communicates with the computer system through these devices. Most of them send and receive data in character units, and data communication speed is relatively slow.

For example, keyboard and monitor integrated character terminals, printers, scanners, including the mouse, and early card and paper tape input and output machines. Graphics display with graphics card is relatively fast and can be used to display complex graphics in image processing.

(2) Block device, also called external memory, users can realize long-term storage of programs and data through these devices. In contrast to character devices, they transfer in blocks, such as disks, tapes, and optical discs. The common block sizes range from 512 to 32768B.

(3) Network communication equipment. These devices mainly include network cards and modems for communication with remote devices. Such devices have higher transmission speeds than character devices but lower than external memory.

5 protect

We know that the operating system can manage and control processes and resources, and in this management process, the correctness of process operation must be ensured. Therefore, the operating system needs to provide a protection mechanism to ensure that processes run and obtain resources correctly.

Conceptually, operating system protection refers to a mechanism that controls the access of programs, processes, or users to computer system resources. Processes in the operating system must be protected from the activities of other processes. Mechanisms are used to ensure that files, memory segments, CPUS, and other resources can be manipulated only by processes that are properly authorized from the operating system.

In layman’s terms, computers contain a lot of information that users often want to protect and keep secret. This information may include emails, business plans, tax returns, and so on. Operating systems need to adopt mechanisms to manage system security. For example, some important files can only be accessed by authorized users.

Files in the system are protected by assigning a 9-bit binary guard code to each file. The protection code consists of three 3-bit fields, one for the owner, one for other members of the owner group, and one for other owners.

Each field has three bits, one for read permission, one for write permission, and one for execute permission. These three bits are called RWX bits. For example, the guard code rwxr-x–x means that the owner can read, write, and execute the file, that other group members can read or execute (but not write) the file, and that all other owners can execute (but not read or write) the file.

In addition to file protection, there are many other security protection mechanisms in operating systems. These mechanisms run through all aspects of the operating system to ensure its reliability in resource allocation and program execution.

6 Virtual Memory

Virtual memory is certainly familiar, it mainly solves a series of limitations brought by physical memory. Virtual memory enables you to run programs larger than your computer’s physical memory by moving them quickly back and forth between RAM and disk.

Because virtual memory exists, an application thinks it has contiguous available memory, that is, a contiguous complete address space. In practice, it may not be contiguous in physical memory, but is often split into physical memory fragments and even temporarily stored on external disk storage for data exchange as needed.

In general, virtual memory treats main memory like a cache of address Spaces stored on disk space, holding only active blocks and passing data back and forth between disk and main memory as needed. At the same time, it simplifies memory management by providing a consistent address space for processes.

In addition, the operating system provides a separate virtual address space for each process, thus protecting the address space of each process from being corrupted by other processes.

It can be seen that the proposal of virtual memory solves the problems of memory space utilization, the security of reading and writing memory, the security of communication between processes and the efficiency of reading and writing memory. Most operating systems now use virtual memory, which has become one of the most fundamental concepts in operating systems.

conclusion

These concepts are very common in the learning system of operating systems and are inescapable points of understanding. Of course, none of these concepts can be explained in a thousand words, but learning is a gradual process. This paper introduces the function of these six important terms in operating system from the point of view of concept, so as to reflect the idea of operating system design and management.

Articles on operating systems will continue to be published to give you a step-by-step understanding of this extremely important subject area. The thread and process relationship, thread communication and synchronization, virtual memory implementation mechanism, file system and other aspects of the article will be pushed in turn, also please like it