<?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_2026F_Lecture_7</id>
	<title>Operating Systems 2026F Lecture 7 - 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_2026F_Lecture_7"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2026F_Lecture_7&amp;action=history"/>
	<updated>2026-10-10T17:12:30Z</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_2026F_Lecture_7&amp;diff=25187&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lectures given on October 6th and 7th, 2026 are now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07a-20261006.mp4 Lecture 7A] * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07b-20261007.mp4 Lecture 7B]  ==Notes==  ===Lecture 7A===  &lt;pre&gt; Lecture 7A ----------  Tutorial 4!  Apps ------ Kernel  &lt;--- has more privileges ------- Hardware  Implemented on the CPU through...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2026F_Lecture_7&amp;diff=25187&amp;oldid=prev"/>
		<updated>2026-10-07T17:57:17Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lectures given on October 6th and 7th, 2026 are now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07a-20261006.mp4 Lecture 7A] * [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07b-20261007.mp4 Lecture 7B]  ==Notes==  ===Lecture 7A===  &amp;lt;pre&amp;gt; Lecture 7A ----------  Tutorial 4!  Apps ------ Kernel  &amp;lt;--- has more privileges ------- Hardware  Implemented on the CPU through...&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 lectures given on October 6th and 7th, 2026 are now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07a-20261006.mp4 Lecture 7A]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2026f/lectures/comp3000-2026f-lec07b-20261007.mp4 Lecture 7B]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===Lecture 7A===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 7A&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Tutorial 4!&lt;br /&gt;
&lt;br /&gt;
Apps&lt;br /&gt;
------&lt;br /&gt;
Kernel  &amp;lt;--- has more privileges&lt;br /&gt;
-------&lt;br /&gt;
Hardware&lt;br /&gt;
&lt;br /&gt;
Implemented on the CPU through different modes.&lt;br /&gt;
&lt;br /&gt;
UNIX-like systems expect there to be a supervisor mode and a user mode.&lt;br /&gt;
 - supervisor mode: can access everything&lt;br /&gt;
 - user mode: limited access&lt;br /&gt;
&lt;br /&gt;
processes run in user mode&lt;br /&gt;
the kernel runs in supervisor mode&lt;br /&gt;
&lt;br /&gt;
a &amp;quot;process&amp;quot; is an abstraction over sharing of user mode&lt;br /&gt;
&lt;br /&gt;
the kernel doesn&amp;#039;t share supervisor mode - that&amp;#039;s all that runs&lt;br /&gt;
&lt;br /&gt;
Linux&lt;br /&gt;
 - name of an implementation of a operating system kernel&lt;br /&gt;
 - designed to be basically compatible with POSIX&lt;br /&gt;
&lt;br /&gt;
POSIX&lt;br /&gt;
 - set of standards defining what a UNIX-like system is&lt;br /&gt;
&lt;br /&gt;
UNIX&lt;br /&gt;
 - operating system created by engineers at Bell Labs (AT&amp;amp;T) in the early 1970&amp;#039;s&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
AT&amp;amp;T had been ruled a monopoly so they had lots of rules about what they could and could not do&lt;br /&gt;
 - they weren&amp;#039;t allowed to compete in the commputer market&lt;br /&gt;
 - but their engineers made a nice OS&lt;br /&gt;
 - so, they basically gave away UNIX&lt;br /&gt;
   - very permissive licenses&lt;br /&gt;
   - adopted by a lot of universities, esp ones who were developing the Internet&lt;br /&gt;
&lt;br /&gt;
UNIX is a pun on MULTICS&lt;br /&gt;
&lt;br /&gt;
BSD UNIX - Berkeley variant of UNIX that was where a lot of Internet technologies were prototyped&lt;br /&gt;
&lt;br /&gt;
But then BSD UNIX got big, and so commercial UNIX became a thing in the 1980&amp;#039;s&lt;br /&gt;
 - on scientific workstations and other bigger machines&lt;br /&gt;
&lt;br /&gt;
But every company that made a UNIX workstation made their own proprietary version of UNIX&lt;br /&gt;
 - permissive license from AT&amp;amp;T plus Berkeley giving away their code&lt;br /&gt;
&lt;br /&gt;
These variations got to be such a pain that there came an effort to standardize what a &amp;quot;UNIX-like&amp;quot; system should be&lt;br /&gt;
 - this resulted in POSIX&lt;br /&gt;
&lt;br /&gt;
UNIX is trademarked&lt;br /&gt;
 - not everyone can call their OS UNIX&lt;br /&gt;
&lt;br /&gt;
In the early 1990&amp;#039;s two things happened&lt;br /&gt;
 - The web arrived (1992-1993)&lt;br /&gt;
 - CPUs capable of UNIX became available in PCs&lt;br /&gt;
   - 80386 starting in 1985&lt;br /&gt;
   - 80486 starting in 1989&lt;br /&gt;
&lt;br /&gt;
So a commercial UNIX could have taken over&lt;br /&gt;
 - Microsoft actually sold XENIX for PCs&lt;br /&gt;
&lt;br /&gt;
But really a version of BSD UNIX should have been available for PCs around then and should have been the foundation of the modern Internet&lt;br /&gt;
 - was open source and battle tested&lt;br /&gt;
&lt;br /&gt;
What happened?&lt;br /&gt;
&lt;br /&gt;
AT&amp;amp;T got greedy&lt;br /&gt;
 - was free of antitrust concerns&lt;br /&gt;
 - and UNIX had become valuable&lt;br /&gt;
 - so they went and sued the people who were making BSD UNIX&lt;br /&gt;
&lt;br /&gt;
Linux is the product of three things&lt;br /&gt;
 - AT&amp;amp;T&amp;#039;s lawsuits&lt;br /&gt;
 - the GNU project not making a kernel&lt;br /&gt;
 - a finnish CS undergrad hacking around&lt;br /&gt;
&lt;br /&gt;
The GNU project&lt;br /&gt;
 - project of the Free Software Foundation&lt;br /&gt;
 - stands for GNU&amp;#039;s not UNIX&lt;br /&gt;
 - FSF people (led by Richard Stallman) got tired of proprietary UNIX&lt;br /&gt;
   - wanted THE CODE so they could make their own changes and share&lt;br /&gt;
     them&lt;br /&gt;
   - so they decided to make their own version of a UNIX-like system&lt;br /&gt;
&lt;br /&gt;
 - gcc instead of cc&lt;br /&gt;
 - bash instead of sh&lt;br /&gt;
 - bison instead of lex&lt;br /&gt;
&lt;br /&gt;
All under the GPL&lt;br /&gt;
&lt;br /&gt;
GPL - GNU General Public License&lt;br /&gt;
 - if you distribute, you have to share the source code with binaries&lt;br /&gt;
 - source code should be distributable under same terms&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GNU project did this for essentially all of userspace of a UNIX system by the early 1990&amp;#039;s. But it couldn&amp;#039;t run on bare hardware because they didn&amp;#039;t have a kernel.&lt;br /&gt;
 - GNU Herd was stalled&lt;br /&gt;
&lt;br /&gt;
And then Linus Torvalds came along&lt;br /&gt;
 - got people on the Internet collaborating on making a kernel&lt;br /&gt;
&lt;br /&gt;
People say GNU/Linux because it is the Linux kernel with a GNU userland&lt;br /&gt;
 - but nowadays that isn&amp;#039;t always true (e.g., busybox)&lt;br /&gt;
&lt;br /&gt;
Linux distribution: Linux kernel + some userspace code&lt;br /&gt;
&lt;br /&gt;
So with UNIX, you have code running in supervisor mode (kernelspace) and in user mode (userspace)&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;re now focused on userspace, will talk about kernelspace more after the midterm&lt;br /&gt;
&lt;br /&gt;
So when a process wants to do something with files, it must make system calls&lt;br /&gt;
 - system call is a request to the kernel&lt;br /&gt;
 - kernel can say yes or no&lt;br /&gt;
&lt;br /&gt;
On what basis does the kernel say yes or no?&lt;br /&gt;
&lt;br /&gt;
Wooclap code: AFAGNUX&lt;br /&gt;
&lt;br /&gt;
First, it depends on which process and which file&lt;br /&gt;
&lt;br /&gt;
Some processes can access everything&lt;br /&gt;
Some have limited access&lt;br /&gt;
&lt;br /&gt;
What mainly determines access is the user who owns the process&lt;br /&gt;
 - i.e., the uid associated with the owner field of the process&lt;br /&gt;
&lt;br /&gt;
Files on UNIX have an associated uid and gid (user and group)&lt;br /&gt;
And permissions associated with these.&lt;br /&gt;
&lt;br /&gt;
three groups of read, write, execute bits&lt;br /&gt;
 - yes or no for each&lt;br /&gt;
plus a few other bits&lt;br /&gt;
&lt;br /&gt;
The rwx are for:&lt;br /&gt;
 - the user&lt;br /&gt;
 - the group&lt;br /&gt;
 - other (everyone else)&lt;br /&gt;
&lt;br /&gt;
To read a file, you need read access&lt;br /&gt;
 - first check to see if uid of process equals uid of file&lt;br /&gt;
    - and user read bit enabled&lt;br /&gt;
 - then check gid of process equals gid of file&lt;br /&gt;
    - and group read bit enabled&lt;br /&gt;
 - then check if other read bit enabled&lt;br /&gt;
&lt;br /&gt;
But what about directories?&lt;br /&gt;
 - marked by a &amp;quot;d&amp;quot; bit&lt;br /&gt;
&lt;br /&gt;
When you run ls, you&amp;#039;re reading the contents of the current directory&lt;br /&gt;
 - represented by &amp;quot;.&amp;quot;&lt;br /&gt;
 - &amp;quot;..&amp;quot; is the parent directory&lt;br /&gt;
&lt;br /&gt;
To be able to list&lt;br /&gt;
&lt;br /&gt;
What&amp;#039;s really happening is that the contents of a file is represented as an inode&lt;br /&gt;
 - inodes are numbered per filesystem&lt;br /&gt;
&lt;br /&gt;
A directory is just a mapping of names to inodes&lt;br /&gt;
&lt;br /&gt;
With r permission, you can read the mappings of names to inodes in a directory&lt;br /&gt;
&lt;br /&gt;
With x permission, you can get the inode associated with a name&lt;br /&gt;
&lt;br /&gt;
file permissions are actually inode permission in UNIX&lt;br /&gt;
&lt;br /&gt;
hard links are just name to inode associations&lt;br /&gt;
 (what directories mostly contain)&lt;br /&gt;
&lt;br /&gt;
symbolic links are name to name associations&lt;br /&gt;
&lt;br /&gt;
So what&amp;#039;s special about root (uid=0)?&lt;br /&gt;
 - the kernel treats those processes as being allowed to do almost anything&lt;br /&gt;
&lt;br /&gt;
When you use sudo, you are saying &amp;quot;superuser (root) do this&amp;quot;&lt;br /&gt;
 - better than logging in as root, because it is clear what is being done with elevated privileges&lt;br /&gt;
&lt;br /&gt;
If you just want to be root, run &amp;quot;su&amp;quot; - but you need the root password.&lt;br /&gt;
&lt;br /&gt;
Alternately, run &amp;quot;sudo -i&amp;quot; to login as root if your user has sudo privileges.&lt;br /&gt;
&lt;br /&gt;
setuid bit&lt;br /&gt;
 - goes with the executable bit on a file, but separate&lt;br /&gt;
&lt;br /&gt;
when a process execve&amp;#039;s a program with the setuid bit, the *euid* of the process changes to that of the program file&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Lecture 7B===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 7B&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Wooclap 1: OEHHFJX&lt;br /&gt;
Be sure to be logged in!&lt;br /&gt;
&lt;br /&gt;
Today is Tutorial 4, plus some history&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Applications (processes)&lt;br /&gt;
-------&lt;br /&gt;
Kernel&lt;br /&gt;
--------&lt;br /&gt;
Hardware&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
kernel and applications take turns on the CPU&lt;br /&gt;
 - key difference is their privilege levels&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So the kernel runs in &amp;quot;supervisor mode&amp;quot;, while&lt;br /&gt;
processes run in &amp;quot;user mode&amp;quot; on the CPU&lt;br /&gt;
 - full access in supervisor mode&lt;br /&gt;
 - limited access in user mode&lt;br /&gt;
&lt;br /&gt;
the process abstraction is a way to multiplex user mode&lt;br /&gt;
&lt;br /&gt;
System calls are how code in user mode invokes code in supervisor mode, i.e., how processes call the kernel&lt;br /&gt;
 - special mechanism because function calls don&amp;#039;t work&lt;br /&gt;
&lt;br /&gt;
So what are permissions for?&lt;br /&gt;
 - tells the kernel what privileges different processes should have, i.e., what resources it should be given access to&lt;br /&gt;
&lt;br /&gt;
We mainly see permissions associated with two things:&lt;br /&gt;
 - processes&lt;br /&gt;
 - files&lt;br /&gt;
&lt;br /&gt;
So when a process accesses a file, the kernel decides whether it is allowed or not based on the permission model&lt;br /&gt;
&lt;br /&gt;
Permissions are generally in some sort of access control matrix&lt;br /&gt;
 - rows are entities&lt;br /&gt;
 - columns are specific permissions&lt;br /&gt;
UNIX uses a simplified access control model for efficiency and usability&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;ve been saying UNIX, Linux, UNIX-like...why?&lt;br /&gt;
&lt;br /&gt;
UNIX is a trademark of AT&amp;amp;T&lt;br /&gt;
 - because it came out of Bell Labs in the early 1970&amp;#039;s&lt;br /&gt;
 - wasn&amp;#039;t really a product at first because was&lt;br /&gt;
   just made by a few engineers for their own use&lt;br /&gt;
 - and AT&amp;amp;T wasn&amp;#039;t allowed to commercialize it really&lt;br /&gt;
    - they were under antitrust restrictions&lt;br /&gt;
 - so they almost gave it away&lt;br /&gt;
    - very open license terms for whomever wanted it&lt;br /&gt;
&lt;br /&gt;
When researchers wanted to create the Internet in the late 1970&amp;#039;s, they mostly built upon UNIX&lt;br /&gt;
 - researchers at Berkeley modified it to make BSD UNIX&lt;br /&gt;
&lt;br /&gt;
So to get on the Internet people wanted to run BSD UNIX, and so it spread&lt;br /&gt;
 - first as itself&lt;br /&gt;
 - then in commercial form from workstation vendors in the 1980&amp;#039;s (e.g., Sun Microsystems)&lt;br /&gt;
&lt;br /&gt;
Because of the licensing terms, workstation manufacturers all could make proprietary versions of UNIX&lt;br /&gt;
 - based on generally available code but with lots of proprietary modifications/additions&lt;br /&gt;
&lt;br /&gt;
Got so bad there was an effort to standardize what &amp;quot;UNIX&amp;quot; should be&lt;br /&gt;
 - resulted in the POSIX standards&lt;br /&gt;
&lt;br /&gt;
So UNIX should have been the basis of the web starting in the early 1990&amp;#039;s, but a few things happened&lt;br /&gt;
 - PCs got powerful enough to run UNIX&lt;br /&gt;
   - Intel 80386 in 1985, 80486 in 1989&lt;br /&gt;
 - there were commercial versions of UNIX for PCs&lt;br /&gt;
   - Microsoft made XENIX&lt;br /&gt;
&lt;br /&gt;
Rather than proprietary UNIX, why couldn&amp;#039;t PCs run a variant of BSD UNIX?&lt;br /&gt;
 - it was still around, had its own variants&lt;br /&gt;
 - but AT&amp;amp;T decided to sue the creators of BSD UNIX&lt;br /&gt;
&lt;br /&gt;
Another piece was the GNU Project&lt;br /&gt;
 - from the Free Software Foundation&lt;br /&gt;
 - HATED proprietary UNIX, so decided to make their own&lt;br /&gt;
&lt;br /&gt;
Started with the foundations&lt;br /&gt;
 - gcc instead of cc&lt;br /&gt;
 - bash rather than sh&lt;br /&gt;
 - bison rather than lex&lt;br /&gt;
&lt;br /&gt;
By the early 1990&amp;#039;s, GNU had implementations of everything in core UNIX...except for the kernel&lt;br /&gt;
 - there was the GNU Herd, but it was VERY delayed&lt;br /&gt;
&lt;br /&gt;
This is where a Finnish CS undergrad steps in&lt;br /&gt;
 - Linus Torvalds posted his own hacked together kernel&lt;br /&gt;
 - with the help of others, he&lt;br /&gt;
   combined it with GNU userland, and now had a&lt;br /&gt;
   UNIX-like system that came to be known as Linux&lt;br /&gt;
&lt;br /&gt;
Strictly speaking, Linux is just the kernel&lt;br /&gt;
 - to get a full UNIX-like system, need to add userspace&lt;br /&gt;
 - Linux + userspace =&amp;gt; Linux distribution&lt;br /&gt;
 - people call Linux GNU/Linux because GNU project code&lt;br /&gt;
   is often part of a Linux distribution&lt;br /&gt;
   - but not always! (e.g., busybox)&lt;br /&gt;
&lt;br /&gt;
One factor in the success of Linux is its license&lt;br /&gt;
 - GNU GPL (General Public License)&lt;br /&gt;
&lt;br /&gt;
&amp;quot;copyleft&amp;quot; license&lt;br /&gt;
 - based on copyright to subvert copyright&lt;br /&gt;
 - says you can distribute code as you like, BUT&lt;br /&gt;
   - you have to give source with binary code&lt;br /&gt;
   - can&amp;#039;t add restrictions&lt;br /&gt;
&lt;br /&gt;
Android has effectively circumvented the GPL of Linux&lt;br /&gt;
 - VERY irritating&lt;br /&gt;
&lt;br /&gt;
Back to permissions&lt;br /&gt;
&lt;br /&gt;
every process has a user and a group&lt;br /&gt;
every file has a user, a group, and permissions&lt;br /&gt;
&lt;br /&gt;
The permissions are&lt;br /&gt;
 - read&lt;br /&gt;
 - write&lt;br /&gt;
 - execute&lt;br /&gt;
And are there for&lt;br /&gt;
 - user&lt;br /&gt;
 - group&lt;br /&gt;
 - other (everyone else)&lt;br /&gt;
plus a few more bits we will discuss&lt;br /&gt;
&lt;br /&gt;
execute for regular files means they can be run as programs&lt;br /&gt;
 - when you compile a program the compiler makes its&lt;br /&gt;
   output executable&lt;br /&gt;
&lt;br /&gt;
Other bits:&lt;br /&gt;
 d: marks a file as a directory&lt;br /&gt;
    - maps filenames to file contents (inodes)&lt;br /&gt;
&lt;br /&gt;
What do permissions mean on a directory?&lt;br /&gt;
 - read lets you list the names in a directory&lt;br /&gt;
 - execute lets you resolve a name to its associated value (i.e., inode)&lt;br /&gt;
&lt;br /&gt;
If a directory is executable but not readable, you can access the contents of files in that directory, but you can&amp;#039;t get a list of files in the directory (try it out!)&lt;br /&gt;
&lt;br /&gt;
But this whole permission model begs a question -&lt;br /&gt;
how do we get around it?&lt;br /&gt;
 - how do we get the right permissions in the first place?&lt;br /&gt;
&lt;br /&gt;
One user is very special in UNIX: root (uid=0)&lt;br /&gt;
 - is allowed to do basically anything by the kernel&lt;br /&gt;
&lt;br /&gt;
So when you first log in, that process is running as root so it can then &amp;quot;become&amp;quot; any user it wants to&lt;br /&gt;
 - called dropping privileges&lt;br /&gt;
&lt;br /&gt;
But then what about sudo?&lt;br /&gt;
 - goes the wrong way, from a less privileged process&lt;br /&gt;
   to one with root capabilities&lt;br /&gt;
 - &amp;quot;superuser (root) do&amp;quot;&lt;br /&gt;
&lt;br /&gt;
s in ls means that the executable and the setuid bit are both set&lt;br /&gt;
 - if just setuid and not executable, you get S&lt;br /&gt;
   (almost never what you want)&lt;br /&gt;
&lt;br /&gt;
With the setuid bit set, the effective uid of a process becomes that of the executable file&lt;br /&gt;
&lt;br /&gt;
The kernel uses the effective uid to decide what is and isn&amp;#039;t allowed&lt;br /&gt;
 - normally uid=euid&lt;br /&gt;
 - but setuid messes with it&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>