Worksheet 11

Tom Cat became the new leader of the Cat Kingdom. He had one big idea: he wanted to get rid of all the dogs.

His plan was simple. He wanted to fill the whole world with “Meow” sounds. He thought if there were too many “Meows,” there would be no room left for dogs.

He asked Le Chat (Cat Kingdom’s Sovereign AI) for help. “Generate a program that produces a lot of ‘Meows’,” he said.

Le Chat gave him a script called meow.sh.

cat meow.sh

echo Meow.
echo Meow.
meow.sh &

“Thank you very much,” Tom Cat said. He went to the kingdom’s main computer and got ready to run the script.

“Wait a moment!” shouted Nini (Tom’s computer helper), “That script will …”

But Tom Cat didn’t listen. He smiled and pressed Enter.

The computer screen filled up fast.

Meow. Meow. Meow. Meow. Meow. Meow. Meow. Meow. Meow.Meow.Meow.Meow.Meow.Meow.Meow.Meow.

The computer fans got very loud, and then… everything stopped. The whole system was frozen.

Nini sighed. He pushed the power button to reboot the computer.

“That,” Nini said, “was a fork bomb. You didn’t get rid of the dogs. You just crashed our computer.

Video Lecture

eLearn link of the video lecture

 _________________________________________
( Wa CoW! OS is lazy smart ... put off    )
( work until necessary. eh? I won't study )
( until there's a quiz. If the quiz       )
( suddenly gets canceled, then I will     )
( save a full copy of my weekend! How     )
( smart. Saves a lot of brain memory.     )
 -----------------------------------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

懷疑人生的時候,玩一下 cowsay. Recall that there are many cats and cows on Linux, but not many dogs (and Tom Cat wants zero dog).

Readings

If you have time, read through the textbook chapters this week after watching the video. This will help you understand the concepts covered in the video deeper.

Programming Lab

If you struggle to set up a proper programming environment in lab 1, make sure you read this before proceeding to lab 2: xv6 environment setup.

Lab 2: xv6 F0rk B0mb

Learning Objectives

  • I understand how Copy-on-Write (CoW) works to make the fork() system call fast.
  • I can explain the mechanism of CoW (the use of read-only permissions, the use of reference counting, and the handling of the resulting page fault).
  • I can distinguish between the three main causes of a page fault: invalid address (segfault), protection fault, and page-not-present.
  • I understand the difference between the “valid” bit and the “present” bit in a PTE.
  • I can distinguish between a minor page fault (page is in memory) and a major page fault (page must be read from disk).
  • I understand the major page fault handling process.
  • I understand the difference between anonymous pages (like stack/heap) and file-backed pages (like code) and how the OS evicts them differently.
  • I understand the concept of the LRU page replacement policy.
  • I understand the concept of second-chance/clock algorithm.
  • I understand what compressed swap is.
  • I understand what the Out-of-Memory (OOM) killer is.
Back to top