Operating Systems 2020W Lecture 3

From Soma-notes

Video

Video from the lecture given on January 15, 2020 is now available.

Notes

Lecture 3
---------

Structure of a UNIX system

ls
emacs     <--- regular programs, running in user mode
firefox
vi /etc/hostname
-------------  user/supervisor mode boundary

linux kernel  <--- in between the hardware and regular programs
                   runs in supervisor mode
hardware

user and supervisor mode are CPU modes
 - on x86 chips, they are actually ring 3 and ring 0, but ring 0 and 1 aren't
   used so much

ring 0 = supervisor mode
ring 3 = user mode

in supervisor mode, programs have access to all hardware features
in user mode, programs have limited access to hardware

it is much safer to run in user mode
 - can't crash the system

drivers: code added to the kernel to help it understand specific hardware


on UNIX, the root user can do "anything", while regular users have limited privileges
 - root on UNIX is the same as Administrator on Windows

a root user has to ask the kernel to do things.  The kernel will generally
say yes, but it can say no to anything
 - and there are ways to configure systems where root is very limited

programs running as root are still running in user mode on the CPU
only the kernel runs in supervisor mode

Focus in first half of class is on the userspace/kernel space boundary and user programs.  Second half, we talk about the kernel.

please don't stream the lecture over the Carleton VPN.
 - I'll show you ways to access the class VMs without the VPN


programs running in userspace can't do I/O on their own, or access much hardware
 - they get their CPU allotment and some RAM, that's it
 - if they want want more RAM or want to talk to the disk, keyboard, screen, etc
   they have to ask the kernel for access

running programs ask the kernel for things via system calls

you can run many copies of the same program
each copy of a running program is referred to as a process

processes run in user mode
the kernel runs in supervisor mode

a "user" is just a label for one or more process
 - really a number (uid)


different processes can use the same memory addresses
  - address 2000 means different things for different processes
  - each process has its own addresses

a system call has to
 - switch the CPU mode to supervisor mode
 - jump to a standard entry point, so the kernel can decide what to do

CPU mode: can be user mode or supervisor mode

a function call can't on its own invoke kernel code
 - (the kernel of course is divided into functions like any C program)

a kernel is just a program...but with special privileges and special responsibilities

what is a system call, actually?
 - a special CPU instruction


what is a CPU?
what is an instruction?