跟讀練習: The Most Successful Idea in Computer Science - 通過影片學習英語口語

選擇練習模式

每種模式都會開啟全屏練習室。

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.

下載應用

流利口語所需的一切

AI 發音評分逐句打分
音標練習掌握每個音
詞彙學習建立你的詞庫
詞彙遊戲邊玩邊學
FOR YOU

推薦影片

關於本課

在這一課中,我們將深入探討電腦科學中的程序及其在作業系統中的重要性。影片中討論了程序與程式的區別,以及如何在多程序環境下實現安全與準確的執行。通過學習這些技術細節,學習者不僅能夠了解計算機的執行方式,還能提高他們的英語口語能力,特別是在電腦科學相關的話題上。我們將通過語言練習來鞏固這些概念,並將其應用於實際的英語對話中。

關鍵詞彙與短語

  • 程序 (Process): 一個正在執行的程式的狀態。
  • 地址空間 (Address Space): 分配給程序的記憶體區域。
  • 併發 (Concurrency): 多個程序同時執行的能力。
  • 中央處理器 (CPU): 計算機的核心處理單元。
  • 程式計數器 (Program Counter): 指向下一條將執行指令的地址。
  • 上下文切換 (Context Switch): 儲存一個程序的狀態並恢復另一個程序的狀態。
  • 註冊器 (Register): 用於儲存臨時資料的內部儲存單元。
  • 安全性 (Safety): 確保資訊不被未經授權的訪問。

練習技巧

在進行英語口語練習時,尤其是觀看這段影片時,建議採用shadow speech(影子語音)的方式跟讀。為了更有效地進行雅思口語練習,您可以嘗試以下方法:

  • 從影片的開頭部分開始,注意說話者的語速和音調。儘量跟隨說話者的節奏,不要急於完成,而是要確保每個音節的正確發音。
  • 重複重要的技術詞彙,例如“程序”和“地址空間”,以增強您的專業術語積累,並將其應用於口語交流中。
  • 時不時暫停影片,反覆練習與自己說話內容的同步,確保完全理解每個概念。
  • 可以嘗試簡潔地解釋影片中的概念,使用自然流暢的英文,使自己在表達時更自信。
  • 也可以和朋友一起觀看影片,進行討論,提升口語表達能力,找出彼此在理解上的差異。

通過這些練習,您將能夠有效提高自己的英語口語練習能力,特別是在看YouTube學英語時更能掌握實用的表達和技巧。

影片中的語法

說話人最常用的結構,並附上影片中的原話:

結構影片中的用法
被動語態 be + 過去分詞 — 強調發生了什麼,而不是誰做的was sponsored · is loaded · is achieved
現在完成時 have/has + 過去分詞 — 過去發生但與現在仍有關聯的事we've covered · have been executed · we've managed
定語從句 who / which + 從句 — 補充說明人或事物registers, which can · state, which can

什麼是跟讀法?

跟讀法 (Shadowing) 是一種有科學依據的語言學習技巧,最初開發用於專業口譯員的培訓,並由多語言者Alexander Arguelles博士普及。這個方法簡單而強大:您在聽英語母語原聲的同時立即大聲重複——就像是一個延遲1-2秒緊跟說話者的影子。與被動聽力或語法練習不同,跟讀法強迫您的大腦和口腔肌肉同時處理並模模擬實的講話模式。研究表明它能顯著提高發音準確性,語調,節奏,連讀,聽力理解和口語流利度——使其成為雅思口語備考和真實英語交流最有效的方法之一。

影子跟讀法: 閱讀完整分步指南 →