This article is aimed at non – class students to supplement the essential basic knowledge of ape program.

  • For computer networking basics click here

  • For basic knowledge of computer composition, click here

All right, open up the operating system!

Ask weakly: what do you need an operating system for?

Without going into the concept of an operating system, which is too hard to write, let’s look at a simple example:

  • In our JS code, we just type inconsole.log(1+1); You can see it in the browser panel2What’s going on? (A quick glance)
  • First, keyboard in the code1 + 1Output to monitor2, you need toCPUControl keyboard (input device) that will be acquired1 + 1Instruction in memory
  • Then the CONTROLLER of the CPU takes the instruction out of memory and analyzes that the instruction is for the computer to do one1 + 1The addition operation of
  • At this point the CONTROL of the CPU will control the CPU’s computing unit to do1 + 1And get the result2
  • Finally, the CPU controller controls the arithmetic unit to return the result to the memory, and the memory is also under the control of the CPU controller to return the result2Return to screen (output device)

Ok, the problem here is, if there is no operating system, a simple 1+1 calculation, your JS code also needs to consider the hardware coordination work, such as your code to coordinate CPU resources when to read your code, when to switch to another process… These dirty work is the operating system for you to block, otherwise this code can be how to write ah…

Weak weak ask: front-end learn this why?

A long time ago to see The “NodeJS”, when talking about the process communication, there is a roughly said, the Windows platform process communication is the pipeline, Linux platform is the domain socket, I see dumbstarted, what is the process communication? What is a pipe? What is domain Socket? 😭 don’t understand…. These are related to knowledge of operating system processes).

What also don’t say, brother, the study car has been rough hair!

1. Four features of the operating system

It has the following four characteristics:

  • concurrent
  • Shared
  • virtual
  • asynchronous

Next, let’s tackle each feature separately.

1.1 What is Concurrency? How is it different from parallelism?

For example, let’s say you’re playing league of Legends with your classmates in voice:

  • You use the mouse to move to play games, while the voice mouth said “teammates hang up, really pit!” This is called parallel (moving the mouse while speaking BB)
  • When you move the mouse around and hit the keyboard, this is called concurrency.

Concurrency is simply splitting time into segments that allow multiple tasks to be performed alternately. The key to parallelism is your ability to multitask.

  • So I think their key point is:Is it simultaneous?

For an operating system, the concurrency of the operating system refers to the existence of multiple running programs in the computer system.

  • For example, the previous computer is a single-core CPU, so how to run QQ, browser, notepad, PPT and other programs on the operating system at the same time, which requires the operating system with concurrency

  • CPU time slices (the microscopic amount of CPU time that an operating system assigns to each running process) rotate the amount of time that the process executes, because execution is so fast that it looks like a browser can execute tasks simultaneously.

  • Some people say, well, now that you have multiple cores, do you still need concurrency? Well, the answer is yes, if you have 8 cores, the desktop will probably perform more than 8 tasks.

1.2 What is Sharing? What does sharing have to do with concurrency?

For example, if you use QQ and wechat at the same time to send the “year-end report. PPT” file to the leader, then both QQ and wechat are reading the PPT file

  • Two processes are executing concurrently (concurrency)
  • If there is no concurrency, that is, only one process running, then there is no sharing. If there is no sharing, QQ and wechat can not send files at the same time, can not access hard disk resources at the same time, there is no concurrent.

There are two types of sharing:

  • In the above example, QQ and wechat both want to access the same file, belonging toAt the same time to share.
  • For a mutually exclusive share, like a printer,Can only be controlled by one process at a timeFor example, a printer can be used by multiple processes, but if you print multiple things at the same time, it will cause confusion of the printed results. Therefore, it is stipulated that some resources must be used by one process first, and then accessed by another process after the use is over.
  • We call a resource that only one process is allowed to access at a timeExclusive resourcesOr,Critical resources.

1.3 What is Virtual?

Example first, then definition.

If a truck driver that calls fan bucket is playing league of heroes, because drink drives at ordinary times too much, he loaded the car of many others, hospitalization also spent many money, so there is no money in the home, the second-hand computer that can buy a 1G ram only plays games. – League of Legends requires at least 2 gb of ram, which is strange, old drivers can still run league of Legends even if they get stuck in a battle. Why do you need two gigabytes of memory for a game that can run on a one gigabyte computer?

Only one gigabyte of ram
It's much bigger than 1G

Also, the computer or the mononuclear fan drum, but van barrels can, love the idea of action movies, listening to netease cloud music, also on the QQ sister, now that a program is assigned to the CPU to perform properly, by definition only one program running at the same time, why the computer can run at the same time so many procedures?

This is virtual processor technology. There is actually only one CPU, but it appears to the user that there are three cpus serving at the same time. (Because of the speed of the CPU to switch processes back and forth, it feels like many cpus are serving us)

The virtual section is summarized as follows:

1.4 What is asynchrony?

Asynchron is very common in JS, such as ajax requests. Instead of receiving the information immediately after the request is made and waiting for the Ajax result to return, we continue to execute the following code, waiting for the Ajax result to return and notifying the JS thread. This is very similar to CPU processing.

For example, if the CPU is executing a process, and the process needs to read a file, and the file may take an hour to read, the CPU cannot wait an hour, the CPU will continue to allocate time slices to other processes, and when the file is read (like ajax returns), the CPU will continue to execute the process that was interrupted.

So asynchrony is the nature of a process that stops and starts at an unpredictable rate, and stops and ends unpredictably.

2. Operating mechanism and architecture of the operating system

Preliminary knowledge: What is instruction

For example, here’s the picture (just a quick scan) :

A +b is a piece of program code. A + B cannot be completed in one step in the view of the CPU.

// ADD C, A,B; // ADD C, A,B; // ADD C, A,BCopy the code

As you can see here, instructions are the most basic commands that the CPU can recognize and execute.

2.1 Two instructions, two processor states, two programs

It is dangerous to say that a user is free to delete all the files on the server. Therefore, some commands cannot be used by ordinary users, but can only be used by users with higher permissions. At this point, the instructions are divided into two types, as shown in the figure below:

This raises the question: How does the CPU determine whether privileged instructions can be executed currently? The diagram below:

Kernel mode
User mode

For applications, some programs can execute privileged instructions, while others can only execute unprivileged instructions. So there are two kinds of programs in the operating system:

2.2 This section describes the OPERATING system kernel

From the figure below, let’s first look at what the operating system kernel contains

The parts of the operating system kernel that are closely related to hardware are:

  • Clock management. Operating system clock management is dependent onHardware timer(I do not know how to achieve the specific hardware, it seems to rely on the hardware periodically generate a pulse signal to achieve). Clock management is very important, like usGet time information.Process switchingAnd so on depends on clock management.
  • Interrupt handling (more on this in the next section).
  • Primitives (mentioned in an example below). Now, it can be simply understood that it is used to implement a specific function during executionUninterruptibleInstruction set. One of the most important properties of primitives is their atomicityIn one go, without interruption).

2.3 the interrupt

  • In the process of program running, the system appears a situation that must be handled by the CPU immediately, at this point, the CPUSuspend the execution of a programinsteadDeal with this new situationThe process is calledinterrupt. Here’s an example:

  • Operating system discoveryInterrupted signalThe time slice of the first program (each program can not be executed forever, the CPU will give each program a certain amount of time to execute, this period of time is called the time slice) is exhausted, should change the second application execution
  • Switch to theThe second processAfter that, the operating system willCPUtheRight to useTo the second application, and then the second application is thereUser modeNext, start the execution.
  • process2 Need to callPrinter resources, one will be executedThe system callsLet the operating system get into the core mindset to call the printer resources
  • The printer starts working,Now process 2Since you have to wait for the printer to boot, the operating system doesn’t wait (wait until the printer is ready, then come back to program 2) and switches directly toThe third applicationperform
  • When the printer is ready, the printer sends a message to the operating system via the I/O controllerInterrupt signalThe operating system went back into the nuclear mindset and found that the outage was becauseProgram 2Wait for the printer resources, now that the printer is ready, switch toProgram 2, switch to theUser modeAnd give the CPU to program 2 to continue executing.

Ok, now we can give a conclusion, how to achieve the switch between user state and core state?

  • “User mode –> core mentality” is achieved through interrupts.And interrupt the only way.
  • The switch from “kernel state –> user state” sets the program state flag bit to user state by executing a privileged instruction.

2.4 Interrupt classification

For example, what is an internal interrupt and an external interrupt:

Then said the former fan Bucket classmate, when he was a child, he did not love to study, every time he was learning to learn suddenly to be good for a long time, he came back to his mind, this is the internal interruption. Thinking about thinking about the teacher came over and gave Fan a poke in the mouth, which was an external interrupt.

Here’s the official explanation:

  • Internal interrupts are commonIllegal program operation(for example, the memory address of the data you want to get is not a memory address, but an address that the system cannot recognize),Address cross-border(for example, the system has allocated some memory for your program, but you are accessing more memory than you should),Floating overflow(for example, the system can only represent a range of 1.1 to 5.1, and you enter a 100, which is beyond the computer’s capacity to handle), orabnormal.Fall into the trap(This is when an application requests a system call. What is a system call is described in the following section.)
  • External interrupts are common asI/O interrupt(Generated by the I/O controller to send signals indicating that an operation has completed, such as when the process requests printer resources, the printer has a process ready to start, and when it is ready it gives the CPU an I/O interrupt to tell it that it is ready),Clock interrupt(generated by a timer inside the processor that allows the operating system to execute functions with a certain discipline. The operating system schedules threads once every 15ms or so, using clock interrupts.)

2.5 System Calls

Why do we need a system call?

  • For example, if your application needs to read file information, it can read data from the hard disk. This operation should be done by the CPU in the kernel mode. How can our application get the CPU to help us switch to the kernel mode to do this job?

  • Here comes the concept and function of system calls.

  • Applications request services from the operating system through system calls. All shared resources in the system are managed by the operating system in a unified manner. Therefore, all resource-related operations (such as storage allocation, I/O operations, and file management) in user programs must be performed by the operating system through system calls.

The following is a simple look at the classification of system calls:

It is important to note that library functions can be confused with system calls.

  • Libraries are reusable modulesIn user mode
  • The process enters from user mode via system callKernel modeA large part of library functions is the encapsulation of system calls

For example, the system call method used to create a process is different in Windows and Linux. In Node, however, a process can be created simply by calling the same function method. For example,

// introduce the module to create the childProcess const childProcess = require('child_process'Const cpuNum = require(const cpuNum = require('os').cpus().length // Creates the same number of child processes as the number of cpusfor (let i = 0; i < cpuNum; ++i) {
  childProcess.fork('./worker.js')}Copy the code

2.6 Definition, composition, organization, status, and transition of processes

2.6.1 Why introduce the concept of processes?
  • Early computers only supportedSingle channel programWhen process A executes, the CPU, memory, and I/O devices are all controlled by process A. After process A finishes executing, process B is replaced with process B. Then, the corresponding resources, such as CPU and memory, can be used by process B.
  • Modern computers aremultiprogrammingExecution is when multiple programs appear to be executing together at the same time, and each program execution requires resources allocated by the system to execute, such asCPU,memory.
  • In the case of memory, the operating system needs to know what memory is allocated to program A, and what memory is allocated to program B, and this needs to be recorded in A little book, which is part of the process, and one of the responsibilities of the process isRecord the current running state of the program.
  • The system configures a data structure for each running program, calledProcess control block(PCB), used to describe various information about the process (such as where the code snippet is located).
2.6.2 Process Definition?

Briefly, a process is the process of a program with independent functions running on a set of data. (Emphasis on dynamic)

2.6.3 What are the components of A PCB

The following figure, respectively explain

  • Process identifier PIDEquivalent to an ID card. When a process is created, the operating system assigns a unique and unique ID to the process,Used to distinguish between different processes.
  • User identifierUIDUsed to represent the processOwning userWho is it.
  • The current status and priority of the process are described in detail in the next section
  • The program segment pointer refers to the program in the current processWhere is the memory.
  • Data segment pointer refers to the data in the current processWhere is the memory.
  • The keyboard and mouse are processes that areAllocated I/O devices.
  • The various register values refer to the values of the program counter, such as the result of some calculation half, which need to be saved when the process switches.
2.6.4 Process organization

In a system, there are usually dozens, hundreds, or even thousands of PCBS. In order to manage them effectively, these PCBS should be organized in a proper way. Here is an organization, similar to a linked list in a data structure.

2.6.5 Process Status

A process is an execution of a program. During this process, sometimes the process is being processed by the CPU, and sometimes it needs to wait for the CPU service, so it can be seen that the state of the process will change. To facilitate the management of each process, the operating system needs to properly divide the process into several states.

There are three basic states of a process:

Two other states of the process:

2.6.6 Process Status change

The state of a process is not static, and in some cases it will change dynamically.

How these process state transitions are accomplished brings us to the next role, called ‘primitives.

  • Primitive isUninterruptibleAtomic operations. Let’s take an example of how a primitive can guarantee uninterruptibility.

Interrupt off instruction
Interrupt on command

  • First execute the close interrupt instruction
  • Then an interrupt signal comes from outside and is not processed
  • After the start interrupt instruction is executed, other interrupt signals have a chance to be processed.

2.6 Process communication

Why do we need interprocess communication?

Because a process is the unit that allocates system resources (including memory address space), each process has an independent memory address space.

2.6.1 Process Communication: Shared storage

Since the storage space of two processes cannot be accessed by each other, the operating system provides one memory space for both processes to access. This is the principle of shared storage.

Among them, introduce storage area-based sharing.

  • Let me draw a block in memoryShared storage areaThe format and location of data are controlled by the process, not the operating system.
2.6.2 Process communication method — Pipeline

  • Pipeline data is based onCharacters of the flow(note that it is not a byte stream) to the pipeline, and when the pipeline is full, to the processwrite()The system call will block until the reader process picks up the data. When the read process takes all the data, the pipe becomes empty, and the read process’sread()The system call will be blocked.
  • If it’s not full, it’s not allowed to read. If they are not available, they are not allowed to write.
  • Once the data is read out, it’s dropped from the pipe, which meansReading processThere can be no more than one.
2.6.3 Process communication method — Message passing

Data exchange between processes is in formatted messages. Processes exchange data through the send message/receive message primitives provided by the operating system.

What did the message mean? Just like when you send QQ messages, the source of the message header is you, and the message body is the content you send. The diagram below:

Next, let’s look at an indirect mode of communication (much like the intermediary mode or publish/subscribe mode), as shown in the figure below: the intermediary is the mailbox through which the process sends and receives messages.

2.7 the thread

Why introduce threads?

  • For example, when you play QQ, QQ is a process, if the PROCESS of QQ is not multi-threaded concurrent, then QQ process can onlyDo one thing at a time(such as QQ typing chat)
  • But our real scene is QQ chat at the same time, but also can send files, but also video chat, which shows that if QQNo multi-threaded concurrency capability, the usefulness of QQ is greatly reduced. So weNeed to thread, that is,Need the process to have the ability to concurrentlyMultiple event capability.

Changes since the introduction of threads

3 Process synchronization and mutual exclusion

Synchronization. It refers to a sequence of events occurring in multiple processes. That is, some processes must execute before others.

For example, process A needs to read the information generated by process B from the buffer, and when the buffer is empty, process B blocks because it cannot read the information. Process B wakes up only when process A generates information to put into the buffer. The concept is shown in Figure 1.

The mutex. Multiple processes cannot use the same resource at the same time. When one process uses a resource, other processes must wait.

For example, if process B needs to access the printer, but process A owns the printer, process B will be blocked until process A releases the printer resources and process B can continue executing. The concept is shown in Figure 3.

3.1 Semaphore (just understand the concept)

Semaphores are mainly used to solve synchronization and mutual exclusion of processes, and we need to understand that when it comes to the relationship between synchronization and mutual exclusion (we program most logic problems about processes, isn’t it synchronization and mutual exclusion?).

In the operating system, commonly used P, V semaphore to achieve synchronization and mutual exclusion between processes, we briefly understand a common semaphore, record semaphore to briefly understand the nature of the semaphore is what. (C language, there will be remarks)

/* Definition of recorded semaphore */
typedef struct {
    int value; // The remaining resources
    Struct process *L // Wait queue
} semaphore
Copy the code

The semaphore structure is composed of two parts. One part is the value of the remaining resource. For example, if two printers are idle, the remaining resource is 2, and who is using the printer, the remaining resource is minus 1.

Struct process *L means, for example, if both printers are in use, and you want to use the printer, you’re going to put the request for the printer resource in a blocking queue, and L is the address of the blocking queue.

/*P operation, which is the request resource operation of the record semaphore */ voidwait (semaphore S) {
    S.value--;
    if(S.value < 0){ block (S.L); }}Copy the code

Note that if there are not enough resources left, use the block primitive to move the process from the running state to the blocked state and hang onto the semaphore S waiting queue.

Void singal (semaphore S) {s.value ++; /* void singal (s.value ++);if(S.value <= 0){ wakeup (S.L); }}Copy the code

After releasing a resource, if there is another process waiting for the resource, such as a printer resource, the wakeup primitive is used to wakeup a process in the waiting queue from the blocked state to the continued state.

3.2 Producer-consumer problem (just understand the concept)

The main reason for this is that node’s flow mechanism is essentially a producer-consumer problem. It is easy to see how this problem can be solved.

producers
A certain amount of data is put into the buffer
Repeat the process
Buffers consume this data

Here we need two synchronous semaphores and one mutex semaphores

Semaphore mutex = 1; semaphore mutex = 1; Semaphore empty = n; Semaphore full = 0; // Semaphore full = 0;Copy the code

The producer code is as follows

producer () {
    while(1) {// produce a product P(empty); // Lock the buffer P(mutex); The code here is to produce a product // unlock V(mutex); V(full); }}Copy the code

The consumer code is as follows

producer () {
    while(1) {// consume a product P(full); // Lock the buffer P(mutex); Here the code is to consume a product // unlock V(mutex); // Consume a product V(empty); }}Copy the code

4 Basic memory knowledge and concepts

Why do WE need memory

Memory is the computer other hardware equipment and CPU communication bridge, transfer station. Programs need to be put into memory before they can be processed by the CPU.

4.1 How does the CPU distinguish where the data of the program is in memory

  • Through to theStorage unit addressing of memoryThe implementation. (The storage unit is usually in bytes.)
  • As shown in the figure below, memory storage units, like a hotel room, are numbered. For example, the data of program 1 is stored on the 1st floor, and number 1 of the 1st floor is stored in the programlet a = 1This code.

4.2 Memory Management – Allocates and reclaims memory space

  • Memory allocation can be divided into contiguous allocation and discontiguous allocation. Contiguous allocation means that the user process must allocate a contiguous memory space.

  • We are only talking about dynamic partition allocation in continuous allocation here.

  • What is dynamic partition allocation? It does not partition memory in advance. Instead, when the process loads memory, partitions are created dynamically based on the size of the process, and the partition size is just the right size for the process. For example, a computer has 64MB of memory, 8MB of system area, 56MB of user area… Now we have several processes to load into memory, as shown below.

  • The problem is that if process 1 runs out and the data in memory is deleted, thenFree area(that is, as the process exits, there will be a lot of free memory areas)

Let’s talk about a simpler method called the free partition table method to solve this problem. In the following figure, the table on the right is a free partition table.

For example, in the following figure, there are three free partitions, 20MB, 10MB, and 4MB, respectively. Now process 5 needs a 4MB free partition. How to allocate the partition?

We need to follow some dynamic partition allocation algorithm, such as the first adaptive algorithm, which means to start at the lower address every time, find the first partition that meets the size of the free partition. There is also the best fit algorithm, which is to find the smallest partition block from the free partition table suitable for allocation to meet the requirements.

The obvious disadvantage of continuous allocation is that in most cases, the size of the process to be allocated cannot be exactly the same as the size of the remaining free partition, resulting in a lot of memory fragmentation that is hard to exploit.

Here we introduce a better method of allocating free partitions, basic paging storage. The following figure

Each of them equal in size
4KB
"Frame"
0

The address space of the user process is divided into areas equal to the size of the page box, called “pages.” Each page also starts at 0.

There is a one-to-one correspondence between process pages and memory page boxes. Each page does not have to be stored consecutively, also does not have to be in order, can be placed in the non-adjacent each page box.

5 File Management

What is the file?

A file is a meaningful set of information/data.

Computers store various files. What are the properties of a file? How should the data within the file be organized? How do you organize them between files?

5.1 File Properties

  • The file name. That’s the name of the file, but it’s in the same directoryDon't allowFiles with the same name.
  • Identifier. An operating system used to distinguish between filesInternal name.
  • Type. File type.
  • Position. fileStorage path, which is also the location on the hard drive (which needs to be converted to the address on the physical hard drive)
  • Creation time, last modification time, and file owner are literal.
  • Protect information. For example, for this fileExecute permissions, whether you have permission to delete files, modify file permissions, etc.

5.2 How is the Data in a File Organized

As shown in the figure below, files are mainly divided into structured files and unstructured files.

5.3 How are Files Organized

Organized by a tree structure. For example, the organization relationship between Windows files is as follows:

Let’s take a closer look at the logical structure of the file

5.4 Logical Structure of the file

Logical structure refers to how the data inside the file is organized in the view of the user, while “physical structure” refers to how the file is stored in external storage, such as a hard disk, in the view of the operating system.

For example, “linear table” is a logical structure, in the user’s view, linear table is a group of sequential relationship of elements, such as: A, B, C, D,e….

  • "Linear table"This logical structure can be implemented with different physical structures, such as:Sequential list/linked list.The order sheetThe elements of are logically as well as physically adjacent: andThe listElements of may be physically noncontiguous.
  • Therefore, sequential tables can be implemented"Random access"And the"The list"Random access is not possible.

Next I look at the three logical structures that have structured files

5.4.1 Sequential files

What is a sequential file

Records can be of fixed or variable length, and individual records can be physically stored sequentially or chained

  • Sequential files are structured and can be divided intoString structureandSequential structure.
  • String structure refers to the order andKeyword independentUsually, the order of recording is determined by the time of recording.
  • The order structure must ensure that the records are in orderKeyword arrangement.

It is important to note that the way sequential files are stored and whether they are sorted by keyword will affect whether the data supports random access and whether records can be quickly found by keyword.

5.4.2 Index files

For variable length record files, to find the ith record, the first i-1 record must be searched in order, but in many scenarios, variable length records must be used. How to solve this problem? This brings us to index files in a moment

  • These variable-length records are recorded in an index table. An index entry contains the index number, length, and pointer.

  • The keyword can be used as the content of the index number. If the keyword itself is arranged in order, you can also search in half according to the keyword.

  • If you want to delete/add a record, you also need to operate on the index table. Secondly, if you want to add a record to the index table, it is only 1KB, but if you want to add a record to the index table, it may be 8KB, so the index table is much larger than the record. The storage space utilization is low.

5.4.3 Indexing sequential files

Indexing sequential files is a combination of indexing and sequential file ideas. In an index order file, an index table is also created for the file, but the difference is that each record corresponds to one index entry, but a group of records corresponds to one index entry.

5.5 File Directory

First, we need to understand what a file control block is. Let’s assume that we are currently on disk D of Windows, as shown below

As you can see, the directory itself is a structured file that records information about the files and directories in the directory, such as names and types. These records are called “file control blocks” (FCBS).

The structure of a file directory is usually a tree. For example, in Linux, / refers to the root path, and /home is the secondary directory under the root path

  • It’s important to note that the tree directoryFile sharing is not easy to implementSo on the basis of the tree directory structure, add some directed edges pointing to the same node (can be simply understood as a reference relationship, just like the object in JS).
  • In other words, it has to beEach shared nodeSet up aShared counterIs used to record how many places are sharing the node at this point. onlyThe shared counter is reduced to 0, the node is deleted.

5.6 File Storage Space Management

First, let’s see that the disk is divided into directory areas and file areas.

Next, let’s look at two common file storage space management algorithms, as shown in the following figure, if the disk is free data blocks are blue, non-free data blocks are orange.

For allocating continuous storage space, you can use the free table method (just this simple method) to allocate and reclaim disk blocks. For allocation, algorithms such as first fit, best fit, etc. can be used to determine which interval to assign to the file. (The free table is shown below)

  • First fit means that when data is inserted, the free table in turn checks the entries in the free table and finds the first free interval that meets the condition.

  • The best fit algorithm means that when data is inserted, the free table in turn checks the free table entries, and then finds the free interval that meets the condition and has the smallest free block.

How to recycle disk blocks, mainly divided into the following four cases

  • There are no adjacent free zones before and after the reclamation area
  • The recovery area is free before and after
  • The front of the recycling area is unprecedented to go
  • After the recovery area is the free area

The most important thing to note is the issue of entry merging. (For example, if there are free areas before and after the reclamation, merge them into one free area)

5.7 File Sharing

There are two types of file sharing

  • Note that multiple users share the same file, which means there is only “one” file of data on the system. And when a user modifies the data in the file, other users can see the changes.

  • Softlink can be understood as a shortcut in Windows.

  • A hard link can be interpreted as a reference count in js. Only when the reference is zero will the file be deleted.

5.8 File Protection

The operating system can protect files by the following three methods:

  • Password protection. Set one for the file"Password"(such as 123), the user must provide the corresponding password when requesting access to the file. The password is usually placed in the corresponding fileFCB or index nodeOn.
  • Encryption protection. Use one of the"Password"Encrypts files, which need to be provided when accessing filesThe correct "password"In order to properly decrypt the files.
  • Access control. Add a FCB or inode type to each fileAccess control list, which records the operations that each user can perform on the file.

6 I/O devices

What is an I/O device

I/O means Input/Output. An I/O device is an external device that can Input data to a computer or receive Output data from a computer. It is a hardware component in a computer.

6.1 I/O Device Classification by Feature

  • A human-computer interaction device that has a slow data transmission speed

  • Storage devices, which can transmit data quickly

  • A network communication device whose transmission speed is between that of a human-computer interaction device and a storage device

6.2 I/O controller

The CPU cannot directly control the mechanical components of the I/O device. Therefore, the I/O device also has an electronic component that acts as an “intermediary” between the CPU and the mechanical components of the I/O device to realize the CONTROL of the CPU over the device. This electronic component is the I/O controller.

  • Receiving and recognizing instructions from the CPU means that, for example, a command from the CPU to read a file, the I/O controller has a correspondingControl registerTo store commands and arguments
  • Reporting the device status to the CPU means that the I/O controller has the correspondingStatus registerIs used to record I/O devicesWhether freeorbusy
  • Data exchange means that the I/O controller sets the correspondingData register. When output, the data register is usedTemporarily store data from the CPU, which is then transmitted to the device by the controller.
  • Address recognition means that in order to distinguish the registers within the registers of the device controller, it is also necessary to set a characteristic for each register"Address". The I/O controller uses the “address” provided by the CPU to determine which register the CPU wants to read or write

6.3 I/O Control Mode

  • Here we refer to the current more advanced way, channel control mode.

  • A channel can be understood as a kind of “weak chicken CPU”. A channel can identify and execute a series of channel instructions.

The greatest advantage of channels is that they greatly reduce the frequency of CPU intervention. When I/O devices complete tasks, channels will send interrupts to the CPU, and there is no need to poll the I/O devices to ask if they have completed the tasks assigned by the CPU.

End of this article.

Preview: Introduction to data structures (common data structures and the form of storage in memory, and the time complexity of adding, deleting, modifying and checking) will follow.

Note: Most of the information for this article comes from the following learning videos

  • Operating System _ Tsinghua University (Chen Yu)
  • 2019 Wang Dao examination grind operating system
  • Operating system (Harbin University of Technology Li Zhijun teacher) 32