跟读练习: The Most Successful Idea in Computer Science - 通过YouTube学习英语口语

C1
⏸ 已暂停
This video was sponsored by Brilliant.
77
如果句子过短或过长,请点击 Edit 进行调整。
1
This video was sponsored by Brilliant.
2
In a previous episode, we talked about  concurrency. The direction of this channel is now shifting toward lower-level concepts  more closely related to operating systems, such as CPU scheduling, threads,  paging, and virtual memory.
3
The challenge with these topics is that all of them are deeply tied to a concept  we haven’t yet covered in detail.
4
Today we’re going to dive into the  technical details of processes.
5
Hi friends, my name is George.  And this, is core dumped.
6
As we discussed in my previous video, a process  is informally defined as a program in execution, meaning that these two concepts are not the same.
7
A program is a passive entity, such as an executable file that  we can launch to start running.
8
When we run a program, what happens internally is  that its executable file is loaded into memory.
9
At this point, our program becomes a process. The execution of this process though might require additional memory to store  user input and temporary results.
10
The operating system is responsible  for allocating that memory.
11
The memory assigned to it has a special  name: the address space of the process.
12
We’ll return to this concept later  in the video, so keep it in mind.
13
A process, however, is more  than just its address space.
14
As we know, modern operating  systems use concurrency, allowing multiple processes to execute by  alternating access to computer resources.
15
Internally, alternating access to the CPU is  achieved by placing processes in a queue. We'll understand how this work by the end of this video. The key point now is that at any given moment, only one process can use the CPU,  while all others wait their turn.
16
Remember, the CPU has internal components  like general-purpose registers, the instruction register, the address  register (also known as the program counter), the stack pointer, and even flags. When a process gains access to the CPU, it uses these components to manipulate and move  data. This is what running a program essentially is, as we've covered in previous episodes. But, alternating CPU access between multiple processes is not as simple as it sounds. If we simply switch processes, the process that gains access to the CPU would find itself  in a CPU state belonging to the previous process.
17
This leads to two major issues: First, this is a severe security risk since the current process could access  sensitive information from the previous process.
18
I mean, imagine if the previous process was  hashing a password, part of that password could still be stored in the registers. Nothing  would stop the current process from reading that information for malicious purposes. So, the first concern here is security.
19
Now, let’s assume that all processes  are honest and won’t use the information from a previous process. Does that  solve all the problems? Well… no.
20
Even if the current process has no  intention of using that information, it still needs to manipulate the registers  to carry out its own tasks. In doing so, it alters the CPU state of the previous process. So, when the previous process regains CPU access later, the CPU state it had when  it was interrupted would be lost.
21
So, the second concern here  is correctness of execution.
22
This might be a bit difficult to  follow, so let me show you an example.
23
Let’s say we want to run two programs. When compiled to assembly, they look something like this. To be executed by the computer, the  code must first be compiled into machine code.
24
Since binary can be hard to follow, we’ll show the  instructions in assembly for educational purposes.
25
Let’s assume that both programs  are launched at the same time.
26
To run them, they are loaded into memory. And for simplicity, let’s also say the concurrency model used by the operating  system allows each process to execute up to two instructions before switching  CPU access to a different process.
27
To start executing the first process, the  operating system sets the program counter so the CPU can begin fetching  instructions for that process.
28
The first instruction tells the CPU  to load the value 12 into register 0.
29
That’s one instruction. This process can still  execute one more instruction before the operating system reallocates the CPU to the second process. The second instruction tells the CPU to load the value 20 into register 1. That completes two instructions. At this point, the operating system sets the program counter so  the CPU can start executing the second process.
30
Now that the program counter points to  the executable code of the second process, we can say the CPU is allocated to it. Note that while the second process now has control of the CPU, the data the first process was  working with is still present in the registers.
31
Again, we assume this second process is not  malicious and will mind its own business.
32
The first instruction of the second process tells  the CPU to load the value 100 into register 0.
33
That’s one instruction. The next instruction tells the CPU to load the value 35 into register 1. Now two consecutive instructions have been executed, so the operating system must  reallocate the CPU back to the first process.
34
For this, it needs to set the program  counter to the correct address so the first process can continue exactly where it left off. But… first mistake! We didn’t store that address anywhere before allocating the CPU to the second  process, so now we can’t resume the first process.
35
Here’s where things start to go wrong. Let’s assume that the operating system had saved the program counter value  and is able to restore it properly.
36
The first process regains control of the CPU and  continues execution from where it was interrupted.
37
Now the third instruction is telling the  CPU to add the values currently held in registers 0 and 1, which are supposed to be  12 and 20, respectively. However, since the second process modified the registers during its  execution, the CPU will now add the wrong numbers.
38
The CPU, simply following instructions, has no  way of knowing what happened, so it will continue executing the process using the incorrect data. And problems don’t stop there. In this example, the first process overwrites the value in  register 0 during the addition. So, when the operating system reallocates the CPU to the second  process, its CPU state will also be altered.
39
In a similar way, the second process will continue  executing, but it will end up not only adding the wrong values but also storing the wrong result. In the end, we’ve managed to mess up both processes' results. Where the first process should have produced 32, it now gives us 135. And where the second process  should have produced 135, it instead gives us 170.
40
Perhaps the worst part here is that these wrong  values are not deterministic. For example, if we had added a third process, or  if the second program was launched even a few milliseconds later, we would’ve  seen completely different wrong results.
41
This problem becomes a nightmare when we consider  that modern computers handle hundreds of processes at once. And to make matters worse, in practice,  it is extremely difficult to predict the exact order in which processes will execute, as  we’ll learn in the CPU scheduling video.
42
Ok but then, how do operating  systems ensure security and correctness when dealing with multiple processes?
43
Well… the solution requires extra steps. Let’s use the same example: two processes start at the same time. We still allow each  process to execute. For the first process, it loads the value 12 into register 0  and then the value 20 into register 1.
44
After this, the CPU must be  allocated to the second process.
45
But instead of simply overwriting the address  register to make the CPU jump to the executable code of the second process, the operating system  first runs a special routine to capture the current state of the CPU—like taking a snapshot. The purpose of this is to copy the contents of the registers, flags, and program  counter into memory so that when the process regains control of the CPU, the state  it had when it was interrupted can be restored.
46
The operating system keeps a copy of the CPU state  for every single process running on the computer.
47
Right after the CPU state of the interrupted  process is captured and safely stored, the CPU state of the next process is restored. In this case, since the second process hasn’t executed any instructions yet, all  of its registers are set to zero, except for the program counter, which points  to the next instruction the process should execute. At this moment, that would be the  first instruction at memory location 1013.
48
Now, the second process starts  executing, loading the value 100 into register 0 and the value 35 into register 1. After two instructions, it is interrupted to allow the CPU to be reallocated to the first process. But once again, before doing that, the CPU state of the second process  is captured and safely stored.
49
Only after storing this information does  the operating system retrieve the state of the first process and copy it into  the corresponding registers in the CPU.
50
By doing this, each time a process regains  control of the CPU, it will find the registers exactly as they were when it was interrupted. This process resolves both problems. A process can no longer access the information the previous  process was using, and since its own state hasn’t been altered by the other process, it can  continue execution with the confidence that it is working with the correct data. This action of capturing the CPU state of a process and restoring the state of  a different process so it can continue execution is known as a context switch. And this is how operating systems guarantee security and correctness when  sharing the CPU among multiple processes.
51
Ok, so, now we already know that a process  has an address space, a program counter, and registers, which can be informally  defined as the CPU state of the process.
52
But what else does a process have? Well, a process might also have a list of open files, as well as IO devices allocated to it. This is the simplest way we can visualize a process. As you can see, instead of being a single entity, a process is this  entire context, isolated from other processes.
53
And that’s the best way we cand describe  a process with a single word: A context.
54
This is why the kernel routine we learned  about earlier is called a context switch.
55
When we switch processes, we are replacing the  entire context in which the system operates.
56
This also explains, from a high-level  perspective, why multiple processes can have the same executable instructions but  still produce different results when executed.
57
It’s not only about the instructions but also the  context in which those instructions are executed.
58
Have you ever asked someone a question  and received the reply, “In what context?” When someone responds this way, it’s because the same question can have  different answers depending on the situation.
59
The question that arises now is: if a process is  this entire context, from low-level components like registers to higher-level things like a  list of files, how can we put them in a queue?
60
I mean, a process isn’t like an object we can  simply use as an element in a data structure. So, how do we manage this? The answer is the PCB.
61
No, not that PCB. In this case, PCB stands for Process Control Block, a special structure the operating  system uses to keep track of every single process.
62
Since every process is unique, it requires  an identifier, known as a process ID.
63
A process also has a state, which can  be any of several possible statuses.
64
We’ll discuss these in more detail shortly. In addition, a process has a program counter, a list of general-purpose registers, an  instruction register, and flags. Depending on the hardware, a process might also have a  stack pointer, index registers, accumulators, and other components I won’t list here. This is what I informally refer to as the CPU state of the process. Do you remember that a context switch requires capturing the CPU state for each  process? Well, this is where that data is stored.
65
Regarding memory, the operating  system must also track all the memory blocks allocated to each process. Remember when we mentioned that each process has its own address space? Well, running multiple programs concurrently introduces a new security  issue because, without extra precautions, any process could potentially read from or  write to the address space of another process.
66
The operating system needs to  be aware of these boundaries to intercept any malicious memory access. Additionally, when a new process is created, the operating system needs to be aware of  the address space of each existing process to correctly allocate an available  memory region for the new process.
67
Therefore, the Process Control Block should  contain memory management information, at least including the memory limits  of each process's address space.
68
And here we can also add other  resources allocated to the process, such as a list of IO devices or open files.
69
Now, the structure you’re seeing is just an  example. If you want to see a real implementation, we can look at the source code of  the Linux kernel under this path.
70
The first interesting thing to note is  that the structure is called a task, not a process. I’m not a kernel expert, but I think  it’s called that because Linux was originally inspired by Unix, where it was said that computers  ran tasks. I might be mistaken though, so feel free to correct me in the comments if I’m wrong. The reason is called this way is because Linux uses the term "task" to represent  the fundamental unit of execution, encompassing both threads and processes  within a single data structure, effectively treating them as the  same entity for scheduling purposes.
71
Another interesting thing I noticed when  reviewing the implementation is that the Process Control Block (PCB) contains a  pointer to the PCB of the parent process, as well as a list of all the processes created  by the process represented by the struct.
72
So, I guess we could add  that detail to our example.
73
Again, I want to emphasize that the Process  Control Block is not the process itself, but rather a representation of the process.  It serves as a repository for all the data needed to start or resume a process,  along with some accounting information.
74
And this representation is what  is actually placed in a queue.
75
And at this point, we should be ready to dive  into CPU scheduling, a topic for a future episode.
76
Finally, keep in mind that everything  we’ve cover in this video is valid for single processor systems, and multicore systems.
77
The only different is that multicore  systems can operate with multiple contexts at the same time due to each  core having its own execution pipeline.

下载应用

Everything you need to speak fluently

AI PronunciationScore every sentence
IPA PracticeMaster every sound
VocabularyBuild your word bank
Vocab GameLearn while playing

关于本课

在这一课中,我们将深入探讨计算机科学中的进程及其在操作系统中的重要性。视频中讨论了进程与程序的区别,以及如何在多进程环境下实现安全与准确的执行。通过学习这些技术细节,学习者不仅能够了解计算机的运行方式,还能提高他们的英语口语能力,特别是在计算机科学相关的话题上。我们将通过语言练习来巩固这些概念,并将其应用于实际的英语对话中。

关键词汇与短语

  • 进程 (Process): 一个正在执行的程序的状态。
  • 地址空间 (Address Space): 分配给进程的内存区域。
  • 并发 (Concurrency): 多个进程同时执行的能力。
  • 中央处理器 (CPU): 计算机的核心处理单元。
  • 程序计数器 (Program Counter): 指向下一条将执行指令的地址。
  • 上下文切换 (Context Switch): 保存一个进程的状态并恢复另一个进程的状态。
  • 注册器 (Register): 用于存储临时数据的内部存储单元。
  • 安全性 (Safety): 确保信息不被未经授权的访问。

练习技巧

在进行英语口语练习时,尤其是观看这段视频时,建议采用shadow speech(影子语音)的方式跟读。为了更有效地进行雅思口语练习,您可以尝试以下方法:

  • 从视频的开头部分开始,注意说话者的语速和音调。尽量跟随说话者的节奏,不要急于完成,而是要确保每个音节的正确发音。
  • 重复重要的技术词汇,例如“进程”和“地址空间”,以增强您的专业术语积累,并将其应用于口语交流中。
  • 时不时暂停视频,反复练习与自己说话内容的同步,确保完全理解每个概念。
  • 可以尝试简洁地解释视频中的概念,使用自然流畅的英文,使自己在表达时更自信。
  • 也可以和朋友一起观看视频,进行讨论,提升口语表达能力,找出彼此在理解上的差异。

通过这些练习,您将能够有效提高自己的英语口语练习能力,特别是在看YouTube学英语时更能掌握实用的表达和技巧。

什么是跟读法?

跟读法 (Shadowing) 是一种有科学依据的语言学习技巧,最初开发用于专业口译员的培训,并由多语言者Alexander Arguelles博士普及。这个方法简单而强大:您在听英语母语原声的同时立即大声重复——就像是一个延迟1-2秒紧跟说话者的影子。与被动听力或语法练习不同,跟读法强迫您的大脑和口腔肌肉同时处理并模仿真实的讲话模式。研究表明它能显着提高发音准确性,语调,节奏,连读,听力理解和口语流利度——使其成为雅思口语备考和真实英语交流最有效的方法之一。