<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_17</id>
	<title>Operating Systems 2021F Lecture 17 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_17"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_17&amp;action=history"/>
	<updated>2026-04-06T04:46:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_17&amp;diff=23503&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 16, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec17-20211116.m4v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_17&amp;diff=23503&amp;oldid=prev"/>
		<updated>2021-11-16T22:15:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 16, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec17-20211116.m4v...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on November 16, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec17-20211116.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec17-20211116.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Class zoom meetings-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
 - due dates&lt;br /&gt;
    - remember they are all in brightspace&lt;br /&gt;
       - when officially due&lt;br /&gt;
       - when last accepted&lt;br /&gt;
         - if you miss the officially due, you&amp;#039;re behind&lt;br /&gt;
	   but we&amp;#039;ll take work without penalty until last&lt;br /&gt;
	   accepted&lt;br /&gt;
	   &lt;br /&gt;
 - symbolic links&lt;br /&gt;
 - stat vs lstat&lt;br /&gt;
 - device files&lt;br /&gt;
 - kernel &amp;amp; userspace&lt;br /&gt;
 - kernel modules&lt;br /&gt;
 - A3&lt;br /&gt;
   - chroot&lt;br /&gt;
   - demos&lt;br /&gt;
 - T7&lt;br /&gt;
   - kernel modules&lt;br /&gt;
&lt;br /&gt;
fsck needs full paths?&lt;br /&gt;
 - well, it expects to be working on devices,&lt;br /&gt;
   so it wants you to be precise&lt;br /&gt;
 - a mess up can be catastrophic (rescue a filesystem can&lt;br /&gt;
   also mean erasing everything)&lt;br /&gt;
&lt;br /&gt;
Hard links vs symbolic links&lt;br /&gt;
 - hard link: name -&amp;gt; inode&lt;br /&gt;
 - symbolic link: name -&amp;gt; name&lt;br /&gt;
&lt;br /&gt;
most files are hard links of some kind&lt;br /&gt;
 - they refer to some kind of inode&lt;br /&gt;
&lt;br /&gt;
there is no delete file system call&lt;br /&gt;
 - we just unlink to remove hard links&lt;br /&gt;
 - inodes are reclaimed when their reference count is zero&lt;br /&gt;
&lt;br /&gt;
Hard links are more reliable than symbolic links&lt;br /&gt;
 - doesn&amp;#039;t matter if other hard links are deleted,&lt;br /&gt;
   if we have one it will refer to the right file contents&lt;br /&gt;
   (inode)&lt;br /&gt;
&lt;br /&gt;
So why symbolic links?&lt;br /&gt;
 - well, hard links are confined to one filesystem,&lt;br /&gt;
   symbolic links aren&amp;#039;t&lt;br /&gt;
&lt;br /&gt;
You can&amp;#039;t have broken hard links (unless the filesystem is corrupted)&lt;br /&gt;
&lt;br /&gt;
Broken symbolic links are easy, just delete or move what is pointed to&lt;br /&gt;
&lt;br /&gt;
You can have symbolic links to symbolic links, and they will normally be deferenced on open&lt;br /&gt;
 - up to a limit, I forget how many, varies from system to system, but at least 3 or 4.&lt;br /&gt;
&lt;br /&gt;
Note you can only hard link to files you own&lt;br /&gt;
 - you can make symbolic links to any file or directory&lt;br /&gt;
    - permissions are determined when it is accessed&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Device files are a kind of special file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In assignment 3, there are two new things relative to T5 and T6&lt;br /&gt;
 - busybox&lt;br /&gt;
 - chroot&lt;br /&gt;
&lt;br /&gt;
busybox: swiss army knife of command line UNIX&lt;br /&gt;
   - small versions of common utilities in one binary&lt;br /&gt;
     (statically linked of course)&lt;br /&gt;
   - great for embedded systems&lt;br /&gt;
&lt;br /&gt;
chroot: change where / is&lt;br /&gt;
 - runs a command with a new root directory&lt;br /&gt;
   - by default, runs your shell&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that this is a simple container, like what docker and snap use, except&lt;br /&gt;
 - no real confinement, as we have full access to /dev and /proc&lt;br /&gt;
 - so we can see all processes and all files (by doing the&lt;br /&gt;
   appropriate mounts)&lt;br /&gt;
&lt;br /&gt;
To get real confinement, you need namespaces (to limit access to devices and processes) and cgroups (to limit resources)&lt;br /&gt;
 - but even these aren&amp;#039;t enough&lt;br /&gt;
 - to see what is needed, look up bpfbox and BPFContain&lt;br /&gt;
   (work of William Findlay, one of my students)&lt;br /&gt;
&lt;br /&gt;
So note that the concept of / can vary between processes!&lt;br /&gt;
 - different processes can have different views of&lt;br /&gt;
   the filesystem hierarchy&lt;br /&gt;
&lt;br /&gt;
the environment outside of a process, all that we access&lt;br /&gt;
via system calls, is very dynamic and changeable&lt;br /&gt;
 - it is whatever the kernel wants it to be&lt;br /&gt;
&lt;br /&gt;
Code running inside a process is always limited, even if that process is running as root (euid=0)&lt;br /&gt;
 - can still segfault&lt;br /&gt;
 - must make system calls to access resources&lt;br /&gt;
&lt;br /&gt;
the kernel is the code on the system running outside of processes&lt;br /&gt;
 - it *implements* the process abstraction&lt;br /&gt;
&lt;br /&gt;
What code is in the kernel varies from OS to OS&lt;br /&gt;
 - some try to have as little as possible in it,&lt;br /&gt;
   those are &amp;quot;microkernels&amp;quot; or even &amp;quot;nanokernels&amp;quot;&lt;br /&gt;
    - they put everything they can into processes,&lt;br /&gt;
      rather than the kernel&lt;br /&gt;
 - but most mainstream OSs are &amp;quot;monolithic kernels&amp;quot;&lt;br /&gt;
    - lots of functionality inside the kernel&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What goes inside a kernel then?&lt;br /&gt;
 - process abstraction&lt;br /&gt;
 - memory &amp;amp; CPU management&lt;br /&gt;
 - most device drivers&lt;br /&gt;
 - filesystems&lt;br /&gt;
 - networking&lt;br /&gt;
 - graphics APIs (some)&lt;br /&gt;
&lt;br /&gt;
In microkernels, we put most of the above into processes&lt;br /&gt;
 - the memory and CPU management, process abstraction&lt;br /&gt;
   generally have to stay in the kernel&lt;br /&gt;
&lt;br /&gt;
Modern monolithic kernels: Linux, FreeBSD, Windows, MacOS&lt;br /&gt;
  (although MacOS and Windows started off as microkernels)&lt;br /&gt;
&lt;br /&gt;
Modern microkernels: QNX, L4, GNU Hurd&lt;br /&gt;
&lt;br /&gt;
To really understand kernels, you have to understand code privileges on the CPU&lt;br /&gt;
&lt;br /&gt;
Old (and embedded) CPUs will run code with one privilege level&lt;br /&gt;
 - all code can do anything&lt;br /&gt;
 - so an &amp;quot;operating system&amp;quot; here is just library code, say&lt;br /&gt;
   for accessing a disk drive&lt;br /&gt;
&lt;br /&gt;
But once we wanted to do real networking, this was a BAD idea&lt;br /&gt;
 - one misbehaving program could crash everything&lt;br /&gt;
 - and somebody always had to listen and deal with&lt;br /&gt;
   the network, even when other things were going on&lt;br /&gt;
&lt;br /&gt;
Basically, you need to have different privilege levels&lt;br /&gt;
to do concurrency properly&lt;br /&gt;
 - need to interrupt programs to do background tasks reliably&lt;br /&gt;
&lt;br /&gt;
The more privileged code is what&amp;#039;s running in the kernel,&lt;br /&gt;
less privileged is in processes&lt;br /&gt;
&lt;br /&gt;
CPUs have&lt;br /&gt;
 - supervisor mode: for kernel code&lt;br /&gt;
 - user mode: for processes (even ones running as root)&lt;br /&gt;
&lt;br /&gt;
(Actually, x86 processors have rings, with ring 0 for kernel code, ring 3 for user code.  Ring 1 and 2 are rarely used, came from a system called Multics.)&lt;br /&gt;
&lt;br /&gt;
By the way, anti-cheat software generally wants to run in the kernel&lt;br /&gt;
 - supervisor mode, ring 0&lt;br /&gt;
 - so they can see EVERYTHING on your system (and change anything)&lt;br /&gt;
&lt;br /&gt;
Device drivers generally run in the kernel,&lt;br /&gt;
but can run as processes (typically at a performance cost)&lt;br /&gt;
 - switching between user and supervisor mode is expensive&lt;br /&gt;
&lt;br /&gt;
Why do we have to execute a special CPU instruction to make system calls?&lt;br /&gt;
 - because the CPU has to switch from user mode to supervisor mode&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>