Shadowing Practice: The Most Successful Idea in Computer Science - Learn English Speaking with YouTube

C1
⏸ Paused
This video was sponsored by Brilliant.
77 sentences
If sentences are too short or too long, click Edit to adjust them.
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.

Download App

Everything you need to speak fluently

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

Context & Background

In the video titled "The Most Successful Idea in Computer Science," the speaker, George, delves into the intricate workings of computer processes, emphasizing the difference between a program and a process. The discussion covers essential concepts such as memory allocation, CPU scheduling, and the significance of ensuring security and correctness when multiple processes interact. This technical subject matter also serves as a fascinating backdrop for English learners, particularly those interested in enhancing their vocabulary and technical comprehension in the realm of computer science.

Top 5 Phrases for Daily Communication

  • “Program in execution” - A useful phrase to describe active processes in various applications.
  • “Memory allocation” - Essential for discussing storage and data handling.
  • “Security risk” - Important in conversations surrounding technology and privacy.
  • “Correctness of execution” - A phrase that can be applied beyond computing, referring to accuracy in various tasks.
  • “Context switch” - This term is pivotal in discussing multitasking in both technology and daily life management.

Step-by-step Shadowing Guide

To effectively apply the shadowing technique with this video and improve your English speaking practice, follow these steps:

  1. Listen Actively: First, watch the video without attempting to repeat. Focus on understanding the speaker's content and context.
  2. Segment the Transcript: Break down the transcript into manageable parts. This allows for easier repetition and enables you to grasp complex phrases.
  3. Repeat After the Speaker: Play the video and pause after each sentence or phrase. Try to mimic George’s intonation and pace to enhance your English pronunciation.
  4. Record Yourself: Use your phone or computer to record your voice while you practice. Listening to your own recordings helps identify areas needing improvement.
  5. Engage with Context: Engage with the phrases in practical contexts. Discuss topics related to computer science with friends or fellow learners to solidify your knowledge.

By consistently applying this shadowing technique, you will not only enhance your vocabulary related to technology but also gain greater confidence in your overall English speaking practice. This method of learning, particularly through resources like learn English with youtube, enriches your understanding of complex concepts while helping you articulate them effectively in English.

What is the Shadowing Technique?

Shadowing is a science-backed language learning technique originally developed for professional interpreter training and popularized by polyglot Dr. Alexander Arguelles. The method is simple but powerful: you listen to native English audio and immediately repeat it out loud — like a shadow following the speaker with just a 1–2 second delay. Unlike passive listening or grammar drills, shadowing forces your brain and mouth muscles to simultaneously process and reproduce real speech patterns. Research shows it significantly improves pronunciation accuracy, intonation, rhythm, connected speech, listening comprehension, and speaking fluency — making it one of the most effective methods for IELTS Speaking preparation and real-world English communication.