CS计算机代考程序代写 Java Elixir Excel Operating Systems CMPSC 473

Operating Systems CMPSC 473
CPU/memory virtualization
February 4, 2021 – Lecture 5 Instructor: Bhuvan Urgaonkar

• • •
Project 1 …
Feedback on Raj’s 311 tutorial
More such tutorials? Topics? Here are some candidates:
• Makefiles (gcc, linking, …)
• Creating libraries
• More gdb (e.g., multi-threading)
• Some important shell utilities (grep, awk, find, …)
Administrative

Clarification on trap (via exit ())

Quiz 5.1
Which of the following is true? A system call is executed:
1. Entirely in user mode
2. Entirely in kernel mode
3. Partly in user mode and partly in kernel mode

Quiz 5.2
Which of the following is/are true?
1. A process may not successfully do load/store into the OS part of its address space
2. A process may successfully do load/store into all of its address space other than the part that belongs to the OS
3. The OS may do stores into parts of the process address space

Quiz 5.3
For each of the following, identify if it is a function you write or a library function or a system call:
1. printf 2. fork 3. main 4. getpid

Quiz 5.4
For each of the following, identify if it is a privileged or an unprivileged instruction or neither:
1. load
2. fork
3. store
4. add
5. return-from-trap (chapter 6)
6. jmp

Quiz 5.5
What will happen if your code segment contains a bit sequence that is not a valid member of the ISA
1. The CPU will execute some interpretation of this sequence which may cause harm to your process (e.g., memory corruption)
2. This may provide a way for the process to cause harm to another process or even the OS!
3. A trap will be raised and the process notified of its error

Quiz 5.6
Which of the following is/are true of what happens when you execute a command on a shell prompt:
1. Commands are system calls and system calls raise trap => a trap will be raised
2. Commands are privileged instructions and the shell is a user process trying to execute a privileged instruction => a trap will be raised
3. A command is a process created by the shell (itself a part of the OS) using fork, a system call, followed by the shell calling exec with the command’s executable as an argument to exec
4. A command is a process created by the shell (itself a process) using fork, a system call, followed by the shell calling exec with the command’s executable as an argument to exec


Quiz 5.7
Where in the address space will x be?
• Code • Data • Heap • Stack

What is special about an OS?
Recall that in Lecture 1 we asked how an OS was different from
• Other virtualization engines, e.g., the Java Virtual Machine
• Other control programs, e.g., gdb
• Other resource managers, e.g., malloc library
How would you define an OS now based on what we have learnt so far?

Suggestions for a few things to explore on your own
• The Linux and glibc cross-reference sites: • https://elixir.bootlin.com/linux/latest/source • https://elixir.bootlin.com/glibc/latest/source
• AnexcellentarticlebyProf.SergeyBratus (Dartmouth) on getpid invocation/implementation:
• https://www.cs.dartmouth.edu/~sergey/cs258/surprise s-with-linux-getpid.txt

• Kernelvs.OS
A Clarification on Terminology
• Wewillbeusingtheseinterchangeably
• Sometimes OS is used to refer to an entire distro and the kernel refers to the part of it that runs with the CPU in privileged mode
• According to this, Redhat and Ubuntu are different operating systems but have the same kernel

T1 T2 Time
A OS B OS A
Q2: how does the OS get to start running here?
• Need some way outside the process’s control to force control back to the OS

Interrupts
• TheremustbeamechanismviawhichtheOSgetsachance to run on the CPU every so often
– E.g., a timer interrupt that periodically lets the OS run, typically, once every few milliseconds

Interrupts
• Interrupts are special conditions external to the CPU that
require OS attention
• Note difference from traps
• CPU designed to switch to kernel mode upon detecting an interrupt
• Examples:
• A keystroke
• A mouse click
• A disk completing a read/write operation
• A network packet arriving on the network card
More generally:

Interrupts
• CPU/OS design and operation for interrupts exactly like for traps
• A CPU has its own well-defined set of interrupts
• OS must implement a handler for each of these (part of OS
code just like trap handlers)
• Table containing addresses of interrupt handles populated by OS during bootup, address of this table know to the CPU

Interrupts and Traps
Process 1
Process 1
Process 2
USER MODE KERNEL MODE
Trap
Intr
Intr
Time
Intr
• Onlytwowaystoenterkernelmodefromusermode

Quiz 5.8
• Using recursion is generally considered undesirable in the design of trap/interrupt handlers. Why?

Quiz 5.9
• We learnt that there is a kernel stack per process (actually per thread as we will see soon) for trap/interrupt handling. Why have this separate stack when there is already a user stack?

Signals vs. Interrupts/Traps
• Signals are software-defined interrupts
• Creation: Two ways:
• OS creates a signal for a process
• A process creates a signal for another with OS help
• kill system call
• Problem 5 on Project 1 uses kill
• Conveyance: by the OS (will elaborate on this in a later lecture)
• Handling: Just like the OS implements interrupt handlers, a process implements signal handlers for all the signals defined by the OS