<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=R.samanfar</id>
	<title>Soma-notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=R.samanfar"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/R.samanfar"/>
	<updated>2026-04-05T17:00:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_19&amp;diff=22032</id>
		<title>Operating Systems 2018F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_19&amp;diff=22032"/>
		<updated>2018-11-23T08:50:11Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video for the lecture given on November 16, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec19-20181116.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
Linux source code links:&lt;br /&gt;
&lt;br /&gt;
* [https://elixir.bootlin.com/linux/v4.19.2/source/fs/read_write.c#L107 use of spin_lock() and spin_unlock()]&lt;br /&gt;
* [https://elixir.bootlin.com/linux/v4.19.2/source/include/linux/fs.h#L895 spinlock declaration]&lt;br /&gt;
* [https://elixir.bootlin.com/linux/v4.19.2/source/include/linux/spinlock.h#L321 spinlock init]&lt;br /&gt;
&lt;br /&gt;
== Question re Pages for Assignment ==&lt;br /&gt;
&lt;br /&gt;
*Pages are virtual&lt;br /&gt;
*Put into a frame which is physical memory &lt;br /&gt;
*when allocating memory: allocating frames &amp;amp; putting pages into these frames&lt;br /&gt;
*Page is a chunk of process memory&lt;br /&gt;
&lt;br /&gt;
==Remember Module from Tutorial 7 ==&lt;br /&gt;
&lt;br /&gt;
#What happens when more than one process is trying to write to dev/remember at same time?&lt;br /&gt;
#*Get race condition&lt;br /&gt;
#*Race condition located in &amp;lt;code&amp;gt;remember_write()&amp;lt;/code&amp;gt;&lt;br /&gt;
#*Condition is basically the whole function&lt;br /&gt;
#*Conflict in &amp;lt;code&amp;gt;free_saved_data()&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;init_saved_date()&amp;lt;/code&amp;gt;, and when writing to it.&lt;br /&gt;
#**Examples: freeing twice, first time will work but will try to free pages again, but nothing to free&lt;br /&gt;
&lt;br /&gt;
#How can we fix in order to allow for concurrency?&lt;br /&gt;
#*One solution: add locking mechanism, mutual exclusion to access data structures (lines 35-39 need to be locked)&lt;br /&gt;
#*Using sleep not a good idea&lt;br /&gt;
&lt;br /&gt;
#Simplest Solution: Prevent Crashing Kernel&lt;br /&gt;
#*Real problem for kernel crashing is freeing and allocating memory&lt;br /&gt;
#*Canâ€™t use mmap, which is user-space command, in the kernel&lt;br /&gt;
#*Why does &amp;lt;code&amp;gt;remember&amp;lt;/code&amp;gt; allocate data on every write?&lt;br /&gt;
#**Every time freeing memory, then initializing new, but its the same size&lt;br /&gt;
#**Why throw away? Just erase it, or replace with zeros&lt;br /&gt;
#*So, move allocation into &amp;lt;code&amp;gt;remember_init()&amp;lt;/code&amp;gt;&lt;br /&gt;
#*Move deallocation into the &amp;lt;code&amp;gt;remember_exit()&amp;lt;/code&amp;gt; (when kernel module unloaded)&lt;br /&gt;
#*Can still have problems, but avoids crashing!&lt;br /&gt;
#*From here we can then add locking mechanisms&lt;br /&gt;
&lt;br /&gt;
#Another Solution: Exclusivity&lt;br /&gt;
#*Make it exclusive&lt;br /&gt;
#*Only have concurrency problems with shared data&lt;br /&gt;
#*Make data exclusive to a process, or a user, etc.&lt;br /&gt;
#*If can avoid locks, should, because they can cause problems&lt;br /&gt;
#*Locks are error prone &lt;br /&gt;
&lt;br /&gt;
#Locks in Kernel Space&lt;br /&gt;
#*We have to rely on kernel based mechanism, can&#039;t rely on man page&lt;br /&gt;
#*There is Documentation online for kernel locking mechanism, but be careful, some info outdated&lt;br /&gt;
#*Multiple kinds of locking, canâ€™t just search lock in source code for &amp;quot;lock&amp;quot; because accessing primitive info&lt;br /&gt;
#*Need an example to follow &amp;amp; base code on&lt;br /&gt;
#* &#039;&#039;INODE&#039;&#039; uses &amp;lt;code&amp;gt;spinlock_t&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;rw_semaphore&amp;lt;/code&amp;gt;&lt;br /&gt;
	&lt;br /&gt;
## &amp;lt;code&amp;gt;spinlock.h&amp;lt;/code&amp;gt;&lt;br /&gt;
#*What does it do?&lt;br /&gt;
#*Similar to loop structure from &#039;&#039;&#039;Test 1&#039;&#039;&#039;&lt;br /&gt;
#*Creates a do-while loop to lock&lt;br /&gt;
#*A bunch of implementations, &amp;lt;code&amp;gt;spinlock_up.h&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
## Question: How do normal files handle locking?&lt;br /&gt;
#*Checks in &amp;lt;code&amp;gt;Fs.h&amp;lt;code&amp;gt; for struct inode&lt;br /&gt;
#*Uses &amp;lt;code&amp;gt;spin_lock&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Concurrent Remember Module&lt;br /&gt;
#*First: move allocation &amp;amp; deallocation to &amp;lt;code&amp;gt;remember_init()&amp;lt;/code&amp;gt; &amp;amp; &amp;lt;code&amp;gt;remember_exit()&amp;lt;/code&amp;gt;&lt;br /&gt;
#*Add: &amp;lt;code&amp;gt;static spinlock_t saved_data_lock&amp;lt;/code&amp;gt; to initialized structures (line 41)&lt;br /&gt;
#*In &amp;lt;code&amp;gt;init_saved_data()&amp;lt;/code&amp;gt;, add initialization of spinlock&lt;br /&gt;
#** &amp;lt;code&amp;gt;spin_lock_init(&amp;amp;saved_data_lock);&amp;lt;/code&amp;gt; (line 94)&lt;br /&gt;
#*In &amp;lt;code&amp;gt;remember_write()&amp;lt;/code&amp;gt;, add lock &amp;amp; unlock&lt;br /&gt;
#**&amp;lt;code&amp;gt;spin_lock(&amp;amp;saved_data_lock)&amp;lt;/code&amp;gt; (line 131)&lt;br /&gt;
#**&amp;lt;code&amp;gt;spin_unlock(&amp;amp;saved_data_lock)&amp;lt;/code&amp;gt; (line 134)&lt;br /&gt;
&lt;br /&gt;
##Do we need lock around read as well?&lt;br /&gt;
#*Yes, otherwise inconsistent data if someone reading while writing&lt;br /&gt;
#*In &amp;lt;code&amp;gt;remember_read()&amp;lt;/code&amp;gt;&lt;br /&gt;
#**&amp;lt;code&amp;gt;spin_lock(&amp;amp;saved_data_lock)&amp;lt;/code&amp;gt; (line 74)&lt;br /&gt;
#**&amp;lt;code&amp;gt;spin_unlock(&amp;amp;saved_data_lock)&amp;lt;/code&amp;gt; (line 77)&lt;br /&gt;
&lt;br /&gt;
##Now build module, but not load directly on device&lt;br /&gt;
#*Will it compile? It did!&lt;br /&gt;
#*Now test in SSH/VM&lt;br /&gt;
#**Uses rsync to copy file to vm, &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; &amp;amp; then loads modules into kernel&lt;br /&gt;
#*Test 1: &amp;lt;code&amp;gt;echo â€œhello thereâ€ &amp;gt; /dev/remember &amp;lt;/code&amp;gt;&lt;br /&gt;
#**&amp;lt;code&amp;gt;cat dev/remember&amp;lt;/code&amp;gt; Works properly, &amp;amp; prints out &#039;&#039;hello there&#039;&#039;&lt;br /&gt;
#*But we need to test concurrency&lt;br /&gt;
#*How?&lt;br /&gt;
#**Make child-parent program that just keeps writing with whatever is writen to the command line&lt;br /&gt;
#**From command line just keep adding &amp;amp; check with what have&lt;br /&gt;
#**Not a definitive test, but passible&lt;br /&gt;
&lt;br /&gt;
== Remember Write Test ==&lt;br /&gt;
#Version 1&lt;br /&gt;
#*Opens file, writes first argument from command line to file, seeks back to beginning, then loops&lt;br /&gt;
#*Need &amp;lt;code&amp;gt;seek&amp;lt;/code&amp;gt; to reset offset back to beginning, otherwise would keep writing same thing instead of writing over&lt;br /&gt;
#* Works, but printing result and new command line on same line&lt;br /&gt;
&lt;br /&gt;
#Version 2&lt;br /&gt;
#*Adds a new line char to end of &amp;lt;code&amp;gt;dev/remember&amp;lt;/code&amp;gt;&lt;br /&gt;
#*Works&lt;br /&gt;
&lt;br /&gt;
#Final Version&lt;br /&gt;
#*Counter &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; (line 21)&lt;br /&gt;
#**Used because otherwise printing out the same thing every time, no way of knowing if actually working properly&lt;br /&gt;
&lt;br /&gt;
#ERROR: Filled up log file&lt;br /&gt;
#*Clean out journal log&lt;br /&gt;
#**&amp;lt;code&amp;gt;sudo journalctl --flush --rotate&amp;lt;/code&amp;gt;&lt;br /&gt;
#**&amp;lt;code&amp;gt;sudo journalctl --vacuum-size=1M&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Remember-WriteTest on Remember Module&lt;br /&gt;
#*Run 3 processes in background&lt;br /&gt;
#* &amp;lt;code&amp;gt;./remember-writetest p1 &amp;amp;&amp;lt;/code&amp;gt;&lt;br /&gt;
#**works&lt;br /&gt;
#* &amp;lt;code&amp;gt;./remember-writetest p2 &amp;amp;&amp;lt;/code&amp;gt;&lt;br /&gt;
#**get segmentation fault&lt;br /&gt;
#* &amp;lt;code&amp;gt;./remember-writetest p3 &amp;amp;&amp;lt;/code&amp;gt;&lt;br /&gt;
#**process 1 killed&lt;br /&gt;
#*&amp;lt;code&amp;gt;cat /dev/remember&amp;lt;code&amp;gt;&lt;br /&gt;
#** works&lt;br /&gt;
#*So kernel not crashing, but still getting errors&lt;br /&gt;
#*Locking successful&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec19/remember-concurrent.zip Download remember-concurrent.zip]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===remember.c (concurrent version)===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=c line&amp;gt;&lt;br /&gt;
/* &lt;br /&gt;
  remember.c&lt;br /&gt;
&lt;br /&gt;
  remember module COMP 3000, Carleton University&lt;br /&gt;
  remembers what is written to it, returns in when read along with&lt;br /&gt;
  info about how it is stored&lt;br /&gt;
&lt;br /&gt;
  License: GPLv2 or later&lt;br /&gt;
  Author: Anil Somayaji&lt;br /&gt;
  November 3, 2018&lt;br /&gt;
&lt;br /&gt;
  device driver and module code derived from:&lt;br /&gt;
  https://appusajeev.wordpress.com/2011/06/18/writing-a-linux-character-device-driver/&lt;br /&gt;
  and&lt;br /&gt;
  http://pete.akeo.ie/2011/08/writing-linux-device-driver-for-kernels.html&lt;br /&gt;
*/&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;linux/module.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/fs.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/device.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/init.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/kernel.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/sched.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/uaccess.h&amp;gt;&lt;br /&gt;
#include &amp;lt;linux/mm.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define DEVICE_NAME &amp;quot;remember&amp;quot;&lt;br /&gt;
#define CLASS_NAME &amp;quot;comp3000&amp;quot;&lt;br /&gt;
&lt;br /&gt;
static struct class* remember_class = NULL;&lt;br /&gt;
static struct device* remember_device = NULL;&lt;br /&gt;
static int remember_major;&lt;br /&gt;
&lt;br /&gt;
static struct page *saved_data_page = NULL;&lt;br /&gt;
static char *saved_data = NULL;&lt;br /&gt;
static unsigned long saved_data_len = 0;&lt;br /&gt;
static int saved_data_max = PAGE_SIZE;&lt;br /&gt;
static int saved_data_order = 0;&lt;br /&gt;
&lt;br /&gt;
static spinlock_t saved_data_lock;&lt;br /&gt;
&lt;br /&gt;
static int remember_open(struct inode *the_inode, struct file *f)&lt;br /&gt;
{&lt;br /&gt;
        pr_info(&amp;quot;Remember: device opened\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static ssize_t remember_read(struct file *f, char *buf, size_t len, loff_t *offset)&lt;br /&gt;
{&lt;br /&gt;
        unsigned long n;&lt;br /&gt;
        char *error_msg = &amp;quot;Buffer too small.&amp;quot;;&lt;br /&gt;
        &lt;br /&gt;
        pr_info(&amp;quot;Remember: read started\n&amp;quot;);&lt;br /&gt;
        &lt;br /&gt;
        if (*offset &amp;gt; 0) {&lt;br /&gt;
                pr_info(&amp;quot;Remember: read non-zero offset, aborting\n&amp;quot;);&lt;br /&gt;
                return 0;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (len &amp;lt; saved_data_len) {&lt;br /&gt;
                pr_info(&amp;quot;Remember: read short buffer\n&amp;quot;);&lt;br /&gt;
                n = strlen(error_msg) + 1;  // Include terminating null byte&lt;br /&gt;
                if (n &amp;gt; len) {&lt;br /&gt;
                        n = len;&lt;br /&gt;
                }&lt;br /&gt;
                copy_to_user(buf, error_msg, n);&lt;br /&gt;
                &lt;br /&gt;
                return n;&lt;br /&gt;
        } else {&lt;br /&gt;
                pr_info(&amp;quot;Remember: read returning data, %ld bytes\n&amp;quot;,&lt;br /&gt;
                        saved_data_len);&lt;br /&gt;
                &lt;br /&gt;
                spin_lock(&amp;amp;saved_data_lock);&lt;br /&gt;
                copy_to_user(buf, saved_data, saved_data_len);&lt;br /&gt;
                *offset = saved_data_len;&lt;br /&gt;
                spin_unlock(&amp;amp;saved_data_lock);&lt;br /&gt;
&lt;br /&gt;
                return saved_data_len;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void init_saved_data(void)&lt;br /&gt;
{&lt;br /&gt;
        pr_info(&amp;quot;Remember: allocating data page&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        if (saved_data) {&lt;br /&gt;
                pr_err(&amp;quot;Remember: saved_data already initialized!&amp;quot;);&lt;br /&gt;
        } else {       &lt;br /&gt;
                saved_data_page = alloc_pages(GFP_KERNEL,&lt;br /&gt;
                                              saved_data_order);&lt;br /&gt;
                saved_data = (char *) page_address(saved_data_page);&lt;br /&gt;
                saved_data_len = 0;&lt;br /&gt;
                spin_lock_init(&amp;amp;saved_data_lock);&lt;br /&gt;
&lt;br /&gt;
                pr_info(&amp;quot;saved_data at kernel virtual address %lx&amp;quot;,&lt;br /&gt;
                        (unsigned long) saved_data);&lt;br /&gt;
                pr_info(&amp;quot;saved_data_page page struct at address %lx&amp;quot;,&lt;br /&gt;
                        (unsigned long) saved_data_page);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void free_saved_data(void)&lt;br /&gt;
{&lt;br /&gt;
        if (saved_data_page) {&lt;br /&gt;
                pr_info(&amp;quot;Remember: freeing old data page&amp;quot;);&lt;br /&gt;
                __free_pages(saved_data_page, saved_data_order);&lt;br /&gt;
                saved_data_page = NULL;&lt;br /&gt;
                saved_data = NULL;&lt;br /&gt;
                saved_data_len = 0;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static ssize_t remember_write(struct file *f, const char *buf, size_t len,&lt;br /&gt;
                           loff_t *offset)&lt;br /&gt;
{&lt;br /&gt;
        unsigned long result;&lt;br /&gt;
&lt;br /&gt;
        if (*offset &amp;gt; 0) {&lt;br /&gt;
                pr_info(&amp;quot;Remember: write nonzero offset, aborting&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
                return 0;&lt;br /&gt;
        }&lt;br /&gt;
                &lt;br /&gt;
        if (len &amp;gt; saved_data_max) {&lt;br /&gt;
                len = saved_data_max;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        pr_info(&amp;quot;Remember: write saving data, %ld bytes&amp;quot;, len);&lt;br /&gt;
&lt;br /&gt;
        spin_lock(&amp;amp;saved_data_lock);&lt;br /&gt;
        result = copy_from_user(saved_data, buf, len);&lt;br /&gt;
        saved_data_len = len;&lt;br /&gt;
        spin_unlock(&amp;amp;saved_data_lock);&lt;br /&gt;
&lt;br /&gt;
        *offset = len;&lt;br /&gt;
        &lt;br /&gt;
        return len;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int remember_release(struct inode *the_inode, struct file *f)&lt;br /&gt;
{        &lt;br /&gt;
        pr_info(&amp;quot;Remember: device closed\n&amp;quot;);&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static struct file_operations remember_fops = {&lt;br /&gt;
        .open = remember_open,&lt;br /&gt;
        .read = remember_read,&lt;br /&gt;
        .write = remember_write,&lt;br /&gt;
        .release = remember_release,&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
static char *remember_devnode(struct device *dev, umode_t *mode)&lt;br /&gt;
{&lt;br /&gt;
        if (mode)&lt;br /&gt;
                *mode = 0666;&lt;br /&gt;
        return NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static int __init remember_init(void)&lt;br /&gt;
{&lt;br /&gt;
        int retval;&lt;br /&gt;
  &lt;br /&gt;
        remember_major = register_chrdev(0, DEVICE_NAME, &amp;amp;remember_fops);&lt;br /&gt;
        if (remember_major &amp;lt; 0) {&lt;br /&gt;
                pr_err(&amp;quot;failed to register device: error %d\n&amp;quot;, remember_major);&lt;br /&gt;
                retval = remember_major;&lt;br /&gt;
                goto failed_chrdevreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        remember_class = class_create(THIS_MODULE, CLASS_NAME);&lt;br /&gt;
        if (IS_ERR(remember_class)) {&lt;br /&gt;
                pr_err(&amp;quot;Remember: failed to register device class &#039;%s&#039;\n&amp;quot;,&lt;br /&gt;
                       CLASS_NAME);&lt;br /&gt;
                retval = PTR_ERR(remember_class);&lt;br /&gt;
                goto failed_classreg;&lt;br /&gt;
        }&lt;br /&gt;
 &lt;br /&gt;
        remember_class-&amp;gt;devnode = remember_devnode;&lt;br /&gt;
&lt;br /&gt;
        remember_device = device_create(remember_class, NULL,&lt;br /&gt;
                                        MKDEV(remember_major, 0),&lt;br /&gt;
                                        NULL, DEVICE_NAME);&lt;br /&gt;
&lt;br /&gt;
        if (IS_ERR(remember_device)) {&lt;br /&gt;
                pr_err(&amp;quot;Remember: failed to create device &#039;%s&#039;\n&amp;quot;, DEVICE_NAME);&lt;br /&gt;
                retval = PTR_ERR(remember_device);&lt;br /&gt;
                goto failed_devreg;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        init_saved_data();&lt;br /&gt;
        &lt;br /&gt;
        pr_info(&amp;quot;Remember: device registered using major %d.\n&amp;quot;,&lt;br /&gt;
                remember_major);&lt;br /&gt;
        &lt;br /&gt;
        return 0;&lt;br /&gt;
        &lt;br /&gt;
 failed_devreg:&lt;br /&gt;
        class_unregister(remember_class);&lt;br /&gt;
        class_destroy(remember_class);&lt;br /&gt;
 failed_classreg:&lt;br /&gt;
        unregister_chrdev(remember_major, DEVICE_NAME);&lt;br /&gt;
 failed_chrdevreg:&lt;br /&gt;
        return -1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
static void __exit remember_exit(void)&lt;br /&gt;
{&lt;br /&gt;
        free_saved_data();&lt;br /&gt;
&lt;br /&gt;
        device_destroy(remember_class, MKDEV(remember_major, 0));&lt;br /&gt;
        class_unregister(remember_class);&lt;br /&gt;
        class_destroy(remember_class);&lt;br /&gt;
        unregister_chrdev(remember_major, &amp;quot;remember&amp;quot;);&lt;br /&gt;
        pr_info(&amp;quot;Unloading Remember module.\n&amp;quot;);&lt;br /&gt;
        return;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
module_init(remember_init);&lt;br /&gt;
module_exit(remember_exit);&lt;br /&gt;
&lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);&lt;br /&gt;
MODULE_AUTHOR(&amp;quot;Anil Somayaji &amp;lt;soma@scs.carleton.ca&amp;gt;&amp;quot;);&lt;br /&gt;
MODULE_DESCRIPTION(&amp;quot;A remember character device module&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===remember-writetest.c===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=c line&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFSIZE 8192&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
        int fd, result, count;&lt;br /&gt;
        int i = 0;&lt;br /&gt;
        char buf[BUFSIZE];&lt;br /&gt;
        &lt;br /&gt;
        while(1) {&lt;br /&gt;
                count = snprintf(buf, BUFSIZE, &amp;quot;%s: %d\n&amp;quot;, argv[1], i);&lt;br /&gt;
                fd = open(&amp;quot;/dev/remember&amp;quot;, O_WRONLY);&lt;br /&gt;
                result = write(fd, buf, count);&lt;br /&gt;
                close(fd);&lt;br /&gt;
                i++;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        /* will never run */&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_18&amp;diff=22031</id>
		<title>Operating Systems 2018F Lecture 18</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_18&amp;diff=22031"/>
		<updated>2018-11-23T08:48:03Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on November 14, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec18-20181114.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
What is dev/fuse&lt;br /&gt;
How did i do a mount&lt;br /&gt;
&lt;br /&gt;
Mount is a priveleged operation normally, it lets you shadow entire portions of the filesystem&lt;br /&gt;
&lt;br /&gt;
fusermount breaks under strace&lt;br /&gt;
&lt;br /&gt;
bin/fusermount is red because of the &#039;s&#039; permission bit.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is the &#039;s&#039; permission bit?&#039;&#039;&#039;&lt;br /&gt;
s stands for setuid in the owner position, and setgid in the group position.&lt;br /&gt;
It allows a program to run with privileges different from the process that did the execve&lt;br /&gt;
&lt;br /&gt;
Normally execve of a process will run as the user (the uid that is currently running)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;setuid&#039;&#039;&#039; gives it the privileges of root instead&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;getuid()&#039;&#039;&#039; is who ran the process&lt;br /&gt;
&#039;&#039;&#039;geteuid()&#039;&#039;&#039; is with what privelges is this process running&lt;br /&gt;
normally these are equal, but it changes when you run &#039;&#039;&#039;setuid&#039;&#039;&#039;&lt;br /&gt;
(same thing for gid)&lt;br /&gt;
&lt;br /&gt;
If you run memoryll as root, the mnt point and all the files under it are exclusive to root&lt;br /&gt;
One of the features of userspace mounting of filesystems, is that they are exclusive to the user that mounted them.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;getattr()&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;system calls&#039;&#039;&#039;&lt;br /&gt;
writev and read, its a way of using multiple buffers&lt;br /&gt;
mount - mounts dev/fuse and fd 3&lt;br /&gt;
===In Class===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 18&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
To Do&lt;br /&gt;
-----&lt;br /&gt;
  strace memoryll&lt;br /&gt;
  uid vs euid&lt;br /&gt;
  scheduling and __schedule&lt;br /&gt;
&lt;br /&gt;
Optional reading:&lt;br /&gt;
  https://utcc.utoronto.ca/~cks/space/blog/unix/RawTtyInputThenAndNow&lt;br /&gt;
&lt;br /&gt;
Scheduling&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
System calls =&amp;gt; enter supervisor mode (kernel) from user mode (processes)&lt;br /&gt;
&lt;br /&gt;
scheduler =&amp;gt; enter user mode (processes) from supervisor mode (kernel)&lt;br /&gt;
&lt;br /&gt;
Scheduling algorithms&lt;br /&gt;
&lt;br /&gt;
Challenges of scheduling&lt;br /&gt;
 - maximize use of resources (throughput)&lt;br /&gt;
 - minimize wait time (latency)&lt;br /&gt;
 - minimal computational complexity&lt;br /&gt;
    scheduling is pure overhead&lt;br /&gt;
 - make sure &amp;quot;important&amp;quot; things get done&lt;br /&gt;
    - obey user preferences&lt;br /&gt;
    - do important system things&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Classic scheduling&lt;br /&gt;
Batch scheduling&lt;br /&gt;
 - shortest job first&lt;br /&gt;
    - lowers latency for shorter jobs but isn&#039;t &amp;quot;fair&amp;quot;&lt;br /&gt;
 - first in, first out&lt;br /&gt;
    - fair, but can have bad consequences&lt;br /&gt;
&lt;br /&gt;
&amp;quot;time sharing&amp;quot; - preemptible scheduling&lt;br /&gt;
 - each process gets a &amp;quot;time slice&amp;quot;&lt;br /&gt;
 - when process is interupted, what to do next?&lt;br /&gt;
   key question&lt;br /&gt;
     - is it waiting for I/O?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_17&amp;diff=22030</id>
		<title>Operating Systems 2018F Lecture 17</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_17&amp;diff=22030"/>
		<updated>2018-11-23T08:47:36Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture on November 9, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec17-20181109.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
alloc pages -&amp;gt; frames -&amp;gt; page&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&#039;FUSE&#039;&#039;&#039;&#039; - filesystem in userspace&lt;br /&gt;
interface for userspace programs to export a filesystem to the LINUX kernel&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What is a filesystem from a kernel?&#039;&#039;&#039;&lt;br /&gt;
* A device file (character device, block device), depends on file operations.&lt;br /&gt;
* A filesystem is just this scaled up, it should not only include these file operations, but it should also include operations for directories, and mounting, unmounting.&lt;br /&gt;
If you can define those, you can make a filesystem&lt;br /&gt;
&lt;br /&gt;
FUSE makes a &amp;quot;special&amp;quot; filesystem that allows you to create other filesystems&lt;br /&gt;
&lt;br /&gt;
Filesystems are abstractions of file operations&lt;br /&gt;
Filesystems talk to rest of the kernel through a virtual filesystem interface&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Are all userspace filesystem in memory?&#039;&#039;&#039;&lt;br /&gt;
Standard ntfs implementation on most linux distributions, is written in userspace&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Microkernals vs monolithic kernal&#039;&#039;&#039;&lt;br /&gt;
microkernel: everything turns into a process&lt;br /&gt;
monolithic kernel: it&#039;s faster&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;memoryll.py&#039;&#039;&#039;&lt;br /&gt;
mounting dev/fuse&lt;br /&gt;
any file operation is going to this python program&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;remember.c&#039;&#039;&#039;&lt;br /&gt;
To increase storage, update:&lt;br /&gt;
saved_data_max&lt;br /&gt;
saved_data_order&lt;br /&gt;
&lt;br /&gt;
Debugging kernel code is difficult, but kernel can be watched while running&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Filesystems&lt;br /&gt;
&lt;br /&gt;
What is it?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Well, what&#039;s a device file?&lt;br /&gt;
 - struct file_operations which gives functions for file operations&lt;br /&gt;
   (read, write, etc)&lt;br /&gt;
&lt;br /&gt;
filesystems just take this idea further&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you access a file&lt;br /&gt;
 - process does a file-related system call&lt;br /&gt;
 - kernel calls generic system call function for requested operation&lt;br /&gt;
 - kernel calls filesystem-specific function for requested operation&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
 - process does a write system call on file on an ext4 filesystem&lt;br /&gt;
 -   kernel runs generic write syscall code&lt;br /&gt;
 -     kernel runs ext4 write code&lt;br /&gt;
&lt;br /&gt;
filesystems are abstractions of file and directory-related operations&lt;br /&gt;
 - allow many instantiations that we call filesystems&lt;br /&gt;
&lt;br /&gt;
filesystems talk to rest of the kernel through a virtual filesystem interface&lt;br /&gt;
 (VFS)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Sidebar:&lt;br /&gt;
Microkernels vs monolithic kernels&lt;br /&gt;
&lt;br /&gt;
Why microkernels&lt;br /&gt;
 - better security: if a service crashes, it is just a process&lt;br /&gt;
 - easier development: servers are just a process&lt;br /&gt;
&lt;br /&gt;
Why monolithic kernels&lt;br /&gt;
 - faster&lt;br /&gt;
 - you depend on it anyway, so security benefits are illusory&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22027</id>
		<title>Operating Systems 2018F Lecture 12</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22027"/>
		<updated>2018-11-21T20:41:03Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 17, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec12-20181017.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
Today: Kernel modules&lt;br /&gt;
&lt;br /&gt;
=== First, Anil&#039;s ssh setup: ===&lt;br /&gt;
&amp;lt;code&amp;gt;student@anil-vm:&amp;lt;/code&amp;gt; // openstack&lt;br /&gt;
* why is it named anil-vm? &lt;br /&gt;
** edit /etc/hosts and /etc/hostname&lt;br /&gt;
&amp;lt;code&amp;gt;anilclass@sutherland:&amp;lt;/code&amp;gt; // local machine&lt;br /&gt;
* edit /etc/hosts&lt;br /&gt;
** add the IP of your VM and give it name&lt;br /&gt;
** distributed DNS does this for URLs&lt;br /&gt;
* login without password&lt;br /&gt;
** ssh key pair, private and public&lt;br /&gt;
** files in ~/.ssh/&lt;br /&gt;
&lt;br /&gt;
Public keys?&lt;br /&gt;
* sharing won&#039;t compromise security&lt;br /&gt;
&lt;br /&gt;
Running X-windows programs on vm:&lt;br /&gt;
* &amp;lt;code&amp;gt;ssh -X student@anil-vm&amp;lt;/code&amp;gt; // works natively in linux&lt;br /&gt;
* on macOS, you can run X-server separately&lt;br /&gt;
* on Windows, use x2go&lt;br /&gt;
&lt;br /&gt;
== Whats a kernel module? ==&lt;br /&gt;
* kernel code, that you load, into the kernel&lt;br /&gt;
* same privileges as other kernel code&lt;br /&gt;
* dangerous! load kernel module = anything can happen&lt;br /&gt;
** only superuser (root) can load&lt;br /&gt;
* NOT a system call&lt;br /&gt;
&lt;br /&gt;
Kernel Oops:&lt;br /&gt;
* kernel catches the bad memory access&lt;br /&gt;
Kernel crash:&lt;br /&gt;
* didn&#039;t catch it&lt;br /&gt;
&lt;br /&gt;
Build kernel from scratch? Not usually - everything is in modules now&lt;br /&gt;
&lt;br /&gt;
What modules are running?&lt;br /&gt;
&amp;lt;code&amp;gt;lsmod&amp;lt;/code&amp;gt;&lt;br /&gt;
* gets info from &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt; is reading a kernel data structure&lt;br /&gt;
* &amp;lt;code&amp;gt;strace lsmod&amp;lt;/code&amp;gt;:&lt;br /&gt;
** shows that it starts with &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
** but then goes into &amp;lt;code&amp;gt;/sys/module/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; : human readable&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; : machine readable&lt;br /&gt;
** wouldn&#039;t find a list of modules here, but rather deep directory structure&lt;br /&gt;
&lt;br /&gt;
Where are kernel modules stored?&lt;br /&gt;
* &amp;lt;code&amp;gt;/lib/modules/&amp;lt;kernel version&amp;gt;/&amp;lt;/code&amp;gt;&lt;br /&gt;
* why so many kernel versions?&lt;br /&gt;
** ex. 4.15.0-33&lt;br /&gt;
*** 4.15.0 is version.&lt;br /&gt;
*** -33 = package release (patches etc)&lt;br /&gt;
&lt;br /&gt;
Why so many modules? Why not build them in?&lt;br /&gt;
* originally, everything was built in - now we basically never do that&lt;br /&gt;
** some may conflict&lt;br /&gt;
** many are unnecessary&lt;br /&gt;
** memory used by kernel is physically used - never virtual&lt;br /&gt;
*** so we minimize this by only loading necessary kernel modules&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.ko&amp;lt;/code&amp;gt;: kernel object&lt;br /&gt;
&amp;lt;code&amp;gt;.so&amp;lt;/code&amp;gt;: shared object (ex. C libraries)&lt;br /&gt;
&lt;br /&gt;
Where is kernel itself?&lt;br /&gt;
&amp;lt;code&amp;gt;/boot/vmlinuz-4.15.0-33-generic&amp;lt;/code&amp;gt;&lt;br /&gt;
* naming is traditional. &#039;z&#039; is for compressed.&lt;br /&gt;
* variants may have different suffix, ex. &#039;rt&#039; for realtime, instead of &#039;generic&#039;&lt;br /&gt;
* kernel is around 8mb&lt;br /&gt;
&lt;br /&gt;
== Review tutorial ==&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo insmod simple.ko&amp;lt;/code&amp;gt; // load kernel module&lt;br /&gt;
* &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; // shows that kernel is loaded&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo rmmod simple.ko&amp;lt;/code&amp;gt; // removes kernel module&lt;br /&gt;
&lt;br /&gt;
=== simple.c ===&lt;br /&gt;
* Why &amp;lt;code&amp;gt;#include &amp;lt;linux/ ...&amp;gt;&amp;lt;/code&amp;gt;?&lt;br /&gt;
* No headers that are familiar, ex. &amp;lt;code&amp;gt;stdlib&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
** You can&#039;t use these in kernel modules. Why?&lt;br /&gt;
*** You can&#039;t use any C library that makes a system call&lt;br /&gt;
** What if you wanted to &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** &amp;lt;code&amp;gt;printk()&amp;lt;/code&amp;gt; is a reimplementation, because&lt;br /&gt;
**** &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt; would &amp;quot;bottom out&amp;quot; by making a system call to write()&lt;br /&gt;
**** &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt; is used to generate logs&lt;br /&gt;
**** how does it do that?&lt;br /&gt;
***** keeps a buffer until they can be printed somewhere&lt;br /&gt;
***** bootup messages? produced by &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;&lt;br /&gt;
*** kernel has its own weird world of standard libraries&lt;br /&gt;
* Some special syntax around declaring init and exit functions..&lt;br /&gt;
* How does kernel actually load a module? (ie. through &amp;lt;code&amp;gt;module_init()&amp;lt;/code&amp;gt; call in simple.c)&lt;br /&gt;
** don&#039;t worry about it. always something you don&#039;t understand...&lt;br /&gt;
** and this is one of these things few people need to understand!&lt;br /&gt;
** you just needs to know how to use it.&lt;br /&gt;
* Why doesn&#039;t simple_exit return anything? Nobody cares what it returns!&lt;br /&gt;
** vs. if init failed... we would care&lt;br /&gt;
	&lt;br /&gt;
Rule of kernel programming: do as little as possible&lt;br /&gt;
* nicer to write in userspace&lt;br /&gt;
&lt;br /&gt;
=== ones.c ===&lt;br /&gt;
* kernel module that implements a device driver for &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** from linux kernels perspective.. same as any other device&lt;br /&gt;
** a module might be a device driver, but might not be&lt;br /&gt;
** and a driver might be baked into the kernel (not a module)&lt;br /&gt;
** but usually, device drivers are implemented as modules&lt;br /&gt;
* makes a character device: &amp;lt;code&amp;gt;register_chrdev()&amp;lt;/code&amp;gt;&lt;br /&gt;
** every device has a major and a minor number: the above function returns major number&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;strong&amp;gt;ones_fops { }&amp;lt;/strong&amp;gt;&amp;lt;/code&amp;gt;: important.  struct containing function pointers.&lt;br /&gt;
** we never call these functions in ones.c&lt;br /&gt;
** these implement the file operations on &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
*** after normal syscall dispatcher stuff, it will want to know HOW to open the device, read, etc&lt;br /&gt;
*** what if we wanted to do a write?&lt;br /&gt;
**** well, &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; is opened read-only. let&#039;s &amp;lt;code&amp;gt;chmod a+w /dev/ones&amp;lt;/code&amp;gt;.&lt;br /&gt;
**** &amp;lt;code&amp;gt;echo 5 &amp;gt; /dev/ones&amp;lt;/code&amp;gt;  // write error&lt;br /&gt;
**** we only have the operations that we&#039;ve implemented&lt;br /&gt;
** who calls them? &lt;br /&gt;
* &amp;lt;code&amp;gt;class_create()&amp;lt;/code&amp;gt; ?&lt;br /&gt;
** can&#039;t just create a device from the major number&lt;br /&gt;
** need a class first before running &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt;&lt;br /&gt;
** grouping of all devices that use the same driver&lt;br /&gt;
** see &amp;lt;code&amp;gt;/sys/class/comp3000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys/devices/virtual/comp3000/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** what&#039;s this about? metadata.&lt;br /&gt;
** thankfully we didn&#039;t have to create this ourself - &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt; took care of all that&lt;br /&gt;
* failed_devreg, etc:&lt;br /&gt;
** handling failures is really important in kernel programming.&lt;br /&gt;
** if something fails and you don&#039;t manually deregister / deallocate memory, it never gets &amp;quot;cleaned up&amp;quot;&lt;br /&gt;
*** stays in physical memory until you reboot&lt;br /&gt;
* How did we come up with this code, generally?&lt;br /&gt;
** no manpages&lt;br /&gt;
** the linux kernel source is the ultimate reference for how this works&lt;br /&gt;
** best way to figure it out is to look at existing device drivers, modify to your purpose, trial &amp;amp; error...&lt;br /&gt;
* &amp;lt;code&amp;gt;ones_read()&amp;lt;/code&amp;gt;:&lt;br /&gt;
** similar to &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; in userspace&lt;br /&gt;
** in userspace you take a file descriptor; in kernel you take a pointer to a file struct&lt;br /&gt;
** &amp;lt;code&amp;gt;buf, len&amp;lt;/code&amp;gt; just as in &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt;..&lt;br /&gt;
** offset? point to specific part of the file&lt;br /&gt;
** the file is always going to be &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; in this case (since it is a device driver)&lt;br /&gt;
** why &amp;lt;code&amp;gt;put_user(&#039;1&#039;, buf++)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;*buf++ = 1&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** The 1&#039;s are going out into userspace. This is what &amp;lt;code&amp;gt;put_user()&amp;lt;/code&amp;gt; is for.&lt;br /&gt;
&lt;br /&gt;
aside: &amp;lt;code&amp;gt;find . -name &amp;quot;ones&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* will find files named &amp;quot;ones&amp;quot; in current directory (.)&lt;br /&gt;
&lt;br /&gt;
Look at newgetpid.c&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22026</id>
		<title>Operating Systems 2018F Lecture 12</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22026"/>
		<updated>2018-11-21T20:40:34Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Today: Kernel modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 17, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec12-20181017.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{Please leave this line alone and write below (this is the coloured heading)}}&lt;br /&gt;
&lt;br /&gt;
Today: Kernel modules&lt;br /&gt;
&lt;br /&gt;
=== First, Anil&#039;s ssh setup: ===&lt;br /&gt;
&amp;lt;code&amp;gt;student@anil-vm:&amp;lt;/code&amp;gt; // openstack&lt;br /&gt;
* why is it named anil-vm? &lt;br /&gt;
** edit /etc/hosts and /etc/hostname&lt;br /&gt;
&amp;lt;code&amp;gt;anilclass@sutherland:&amp;lt;/code&amp;gt; // local machine&lt;br /&gt;
* edit /etc/hosts&lt;br /&gt;
** add the IP of your VM and give it name&lt;br /&gt;
** distributed DNS does this for URLs&lt;br /&gt;
* login without password&lt;br /&gt;
** ssh key pair, private and public&lt;br /&gt;
** files in ~/.ssh/&lt;br /&gt;
&lt;br /&gt;
Public keys?&lt;br /&gt;
* sharing won&#039;t compromise security&lt;br /&gt;
&lt;br /&gt;
Running X-windows programs on vm:&lt;br /&gt;
* &amp;lt;code&amp;gt;ssh -X student@anil-vm&amp;lt;/code&amp;gt; // works natively in linux&lt;br /&gt;
* on macOS, you can run X-server separately&lt;br /&gt;
* on Windows, use x2go&lt;br /&gt;
&lt;br /&gt;
== Whats a kernel module? ==&lt;br /&gt;
* kernel code, that you load, into the kernel&lt;br /&gt;
* same privileges as other kernel code&lt;br /&gt;
* dangerous! load kernel module = anything can happen&lt;br /&gt;
** only superuser (root) can load&lt;br /&gt;
* NOT a system call&lt;br /&gt;
&lt;br /&gt;
Kernel Oops:&lt;br /&gt;
* kernel catches the bad memory access&lt;br /&gt;
Kernel crash:&lt;br /&gt;
* didn&#039;t catch it&lt;br /&gt;
&lt;br /&gt;
Build kernel from scratch? Not usually - everything is in modules now&lt;br /&gt;
&lt;br /&gt;
What modules are running?&lt;br /&gt;
&amp;lt;code&amp;gt;lsmod&amp;lt;/code&amp;gt;&lt;br /&gt;
* gets info from &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt; is reading a kernel data structure&lt;br /&gt;
* &amp;lt;code&amp;gt;strace lsmod&amp;lt;/code&amp;gt;:&lt;br /&gt;
** shows that it starts with &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
** but then goes into &amp;lt;code&amp;gt;/sys/module/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; : human readable&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; : machine readable&lt;br /&gt;
** wouldn&#039;t find a list of modules here, but rather deep directory structure&lt;br /&gt;
&lt;br /&gt;
Where are kernel modules stored?&lt;br /&gt;
* &amp;lt;code&amp;gt;/lib/modules/&amp;lt;kernel version&amp;gt;/&amp;lt;/code&amp;gt;&lt;br /&gt;
* why so many kernel versions?&lt;br /&gt;
** ex. 4.15.0-33&lt;br /&gt;
*** 4.15.0 is version.&lt;br /&gt;
*** -33 = package release (patches etc)&lt;br /&gt;
&lt;br /&gt;
Why so many modules? Why not build them in?&lt;br /&gt;
* originally, everything was built in - now we basically never do that&lt;br /&gt;
** some may conflict&lt;br /&gt;
** many are unnecessary&lt;br /&gt;
** memory used by kernel is physically used - never virtual&lt;br /&gt;
*** so we minimize this by only loading necessary kernel modules&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.ko&amp;lt;/code&amp;gt;: kernel object&lt;br /&gt;
&amp;lt;code&amp;gt;.so&amp;lt;/code&amp;gt;: shared object (ex. C libraries)&lt;br /&gt;
&lt;br /&gt;
Where is kernel itself?&lt;br /&gt;
&amp;lt;code&amp;gt;/boot/vmlinuz-4.15.0-33-generic&amp;lt;/code&amp;gt;&lt;br /&gt;
* naming is traditional. &#039;z&#039; is for compressed.&lt;br /&gt;
* variants may have different suffix, ex. &#039;rt&#039; for realtime, instead of &#039;generic&#039;&lt;br /&gt;
* kernel is around 8mb&lt;br /&gt;
&lt;br /&gt;
== Review tutorial ==&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo insmod simple.ko&amp;lt;/code&amp;gt; // load kernel module&lt;br /&gt;
* &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; // shows that kernel is loaded&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo rmmod simple.ko&amp;lt;/code&amp;gt; // removes kernel module&lt;br /&gt;
&lt;br /&gt;
=== simple.c ===&lt;br /&gt;
* Why &amp;lt;code&amp;gt;#include &amp;lt;linux/ ...&amp;gt;&amp;lt;/code&amp;gt;?&lt;br /&gt;
* No headers that are familiar, ex. &amp;lt;code&amp;gt;stdlib&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
** You can&#039;t use these in kernel modules. Why?&lt;br /&gt;
*** You can&#039;t use any C library that makes a system call&lt;br /&gt;
** What if you wanted to &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** &amp;lt;code&amp;gt;printk()&amp;lt;/code&amp;gt; is a reimplementation, because&lt;br /&gt;
**** &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt; would &amp;quot;bottom out&amp;quot; by making a system call to write()&lt;br /&gt;
**** &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt; is used to generate logs&lt;br /&gt;
**** how does it do that?&lt;br /&gt;
***** keeps a buffer until they can be printed somewhere&lt;br /&gt;
***** bootup messages? produced by &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;&lt;br /&gt;
*** kernel has its own weird world of standard libraries&lt;br /&gt;
* Some special syntax around declaring init and exit functions..&lt;br /&gt;
* How does kernel actually load a module? (ie. through &amp;lt;code&amp;gt;module_init()&amp;lt;/code&amp;gt; call in simple.c)&lt;br /&gt;
** don&#039;t worry about it. always something you don&#039;t understand...&lt;br /&gt;
** and this is one of these things few people need to understand!&lt;br /&gt;
** you just needs to know how to use it.&lt;br /&gt;
* Why doesn&#039;t simple_exit return anything? Nobody cares what it returns!&lt;br /&gt;
** vs. if init failed... we would care&lt;br /&gt;
	&lt;br /&gt;
Rule of kernel programming: do as little as possible&lt;br /&gt;
* nicer to write in userspace&lt;br /&gt;
&lt;br /&gt;
=== ones.c ===&lt;br /&gt;
* kernel module that implements a device driver for &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** from linux kernels perspective.. same as any other device&lt;br /&gt;
** a module might be a device driver, but might not be&lt;br /&gt;
** and a driver might be baked into the kernel (not a module)&lt;br /&gt;
** but usually, device drivers are implemented as modules&lt;br /&gt;
* makes a character device: &amp;lt;code&amp;gt;register_chrdev()&amp;lt;/code&amp;gt;&lt;br /&gt;
** every device has a major and a minor number: the above function returns major number&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;strong&amp;gt;ones_fops { }&amp;lt;/strong&amp;gt;&amp;lt;/code&amp;gt;: important.  struct containing function pointers.&lt;br /&gt;
** we never call these functions in ones.c&lt;br /&gt;
** these implement the file operations on &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
*** after normal syscall dispatcher stuff, it will want to know HOW to open the device, read, etc&lt;br /&gt;
*** what if we wanted to do a write?&lt;br /&gt;
**** well, &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; is opened read-only. let&#039;s &amp;lt;code&amp;gt;chmod a+w /dev/ones&amp;lt;/code&amp;gt;.&lt;br /&gt;
**** &amp;lt;code&amp;gt;echo 5 &amp;gt; /dev/ones&amp;lt;/code&amp;gt;  // write error&lt;br /&gt;
**** we only have the operations that we&#039;ve implemented&lt;br /&gt;
** who calls them? &lt;br /&gt;
* &amp;lt;code&amp;gt;class_create()&amp;lt;/code&amp;gt; ?&lt;br /&gt;
** can&#039;t just create a device from the major number&lt;br /&gt;
** need a class first before running &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt;&lt;br /&gt;
** grouping of all devices that use the same driver&lt;br /&gt;
** see &amp;lt;code&amp;gt;/sys/class/comp3000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys/devices/virtual/comp3000/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** what&#039;s this about? metadata.&lt;br /&gt;
** thankfully we didn&#039;t have to create this ourself - &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt; took care of all that&lt;br /&gt;
* failed_devreg, etc:&lt;br /&gt;
** handling failures is really important in kernel programming.&lt;br /&gt;
** if something fails and you don&#039;t manually deregister / deallocate memory, it never gets &amp;quot;cleaned up&amp;quot;&lt;br /&gt;
*** stays in physical memory until you reboot&lt;br /&gt;
* How did we come up with this code, generally?&lt;br /&gt;
** no manpages&lt;br /&gt;
** the linux kernel source is the ultimate reference for how this works&lt;br /&gt;
** best way to figure it out is to look at existing device drivers, modify to your purpose, trial &amp;amp; error...&lt;br /&gt;
* &amp;lt;code&amp;gt;ones_read()&amp;lt;/code&amp;gt;:&lt;br /&gt;
** similar to &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; in userspace&lt;br /&gt;
** in userspace you take a file descriptor; in kernel you take a pointer to a file struct&lt;br /&gt;
** &amp;lt;code&amp;gt;buf, len&amp;lt;/code&amp;gt; just as in &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt;..&lt;br /&gt;
** offset? point to specific part of the file&lt;br /&gt;
** the file is always going to be &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; in this case (since it is a device driver)&lt;br /&gt;
** why &amp;lt;code&amp;gt;put_user(&#039;1&#039;, buf++)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;*buf++ = 1&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** The 1&#039;s are going out into userspace. This is what &amp;lt;code&amp;gt;put_user()&amp;lt;/code&amp;gt; is for.&lt;br /&gt;
&lt;br /&gt;
aside: &amp;lt;code&amp;gt;find . -name &amp;quot;ones&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* will find files named &amp;quot;ones&amp;quot; in current directory (.)&lt;br /&gt;
&lt;br /&gt;
Look at newgetpid.c&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22025</id>
		<title>Operating Systems 2018F Lecture 12</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_12&amp;diff=22025"/>
		<updated>2018-11-21T20:39:23Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 17, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec12-20181017.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
{{Please leave this line alone and write below (this is the coloured heading)}}&lt;br /&gt;
&lt;br /&gt;
== Today: Kernel modules ==&lt;br /&gt;
&lt;br /&gt;
=== First, Anil&#039;s ssh setup: ===&lt;br /&gt;
&amp;lt;code&amp;gt;student@anil-vm:&amp;lt;/code&amp;gt; // openstack&lt;br /&gt;
* why is it named anil-vm? &lt;br /&gt;
** edit /etc/hosts and /etc/hostname&lt;br /&gt;
&amp;lt;code&amp;gt;anilclass@sutherland:&amp;lt;/code&amp;gt; // local machine&lt;br /&gt;
* edit /etc/hosts&lt;br /&gt;
** add the IP of your VM and give it name&lt;br /&gt;
** distributed DNS does this for URLs&lt;br /&gt;
* login without password&lt;br /&gt;
** ssh key pair, private and public&lt;br /&gt;
** files in ~/.ssh/&lt;br /&gt;
&lt;br /&gt;
Public keys?&lt;br /&gt;
* sharing won&#039;t compromise security&lt;br /&gt;
&lt;br /&gt;
Running X-windows programs on vm:&lt;br /&gt;
* &amp;lt;code&amp;gt;ssh -X student@anil-vm&amp;lt;/code&amp;gt; // works natively in linux&lt;br /&gt;
* on macOS, you can run X-server separately&lt;br /&gt;
* on Windows, use x2go&lt;br /&gt;
&lt;br /&gt;
== Whats a kernel module? ==&lt;br /&gt;
* kernel code, that you load, into the kernel&lt;br /&gt;
* same privileges as other kernel code&lt;br /&gt;
* dangerous! load kernel module = anything can happen&lt;br /&gt;
** only superuser (root) can load&lt;br /&gt;
* NOT a system call&lt;br /&gt;
&lt;br /&gt;
Kernel Oops:&lt;br /&gt;
* kernel catches the bad memory access&lt;br /&gt;
Kernel crash:&lt;br /&gt;
* didn&#039;t catch it&lt;br /&gt;
&lt;br /&gt;
Build kernel from scratch? Not usually - everything is in modules now&lt;br /&gt;
&lt;br /&gt;
What modules are running?&lt;br /&gt;
&amp;lt;code&amp;gt;lsmod&amp;lt;/code&amp;gt;&lt;br /&gt;
* gets info from &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt; is reading a kernel data structure&lt;br /&gt;
* &amp;lt;code&amp;gt;strace lsmod&amp;lt;/code&amp;gt;:&lt;br /&gt;
** shows that it starts with &amp;lt;code&amp;gt;/proc/modules&amp;lt;/code&amp;gt;&lt;br /&gt;
** but then goes into &amp;lt;code&amp;gt;/sys/module/&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt; : human readable&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt; : machine readable&lt;br /&gt;
** wouldn&#039;t find a list of modules here, but rather deep directory structure&lt;br /&gt;
&lt;br /&gt;
Where are kernel modules stored?&lt;br /&gt;
* &amp;lt;code&amp;gt;/lib/modules/&amp;lt;kernel version&amp;gt;/&amp;lt;/code&amp;gt;&lt;br /&gt;
* why so many kernel versions?&lt;br /&gt;
** ex. 4.15.0-33&lt;br /&gt;
*** 4.15.0 is version.&lt;br /&gt;
*** -33 = package release (patches etc)&lt;br /&gt;
&lt;br /&gt;
Why so many modules? Why not build them in?&lt;br /&gt;
* originally, everything was built in - now we basically never do that&lt;br /&gt;
** some may conflict&lt;br /&gt;
** many are unnecessary&lt;br /&gt;
** memory used by kernel is physically used - never virtual&lt;br /&gt;
*** so we minimize this by only loading necessary kernel modules&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;.ko&amp;lt;/code&amp;gt;: kernel object&lt;br /&gt;
&amp;lt;code&amp;gt;.so&amp;lt;/code&amp;gt;: shared object (ex. C libraries)&lt;br /&gt;
&lt;br /&gt;
Where is kernel itself?&lt;br /&gt;
&amp;lt;code&amp;gt;/boot/vmlinuz-4.15.0-33-generic&amp;lt;/code&amp;gt;&lt;br /&gt;
* naming is traditional. &#039;z&#039; is for compressed.&lt;br /&gt;
* variants may have different suffix, ex. &#039;rt&#039; for realtime, instead of &#039;generic&#039;&lt;br /&gt;
* kernel is around 8mb&lt;br /&gt;
&lt;br /&gt;
== Review tutorial ==&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo insmod simple.ko&amp;lt;/code&amp;gt; // load kernel module&lt;br /&gt;
* &amp;lt;code&amp;gt;dmesg | tail&amp;lt;/code&amp;gt; // shows that kernel is loaded&lt;br /&gt;
* &amp;lt;code&amp;gt;sudo rmmod simple.ko&amp;lt;/code&amp;gt; // removes kernel module&lt;br /&gt;
&lt;br /&gt;
=== simple.c ===&lt;br /&gt;
* Why &amp;lt;code&amp;gt;#include &amp;lt;linux/ ...&amp;gt;&amp;lt;/code&amp;gt;?&lt;br /&gt;
* No headers that are familiar, ex. &amp;lt;code&amp;gt;stdlib&amp;lt;/code&amp;gt;, etc.&lt;br /&gt;
** You can&#039;t use these in kernel modules. Why?&lt;br /&gt;
*** You can&#039;t use any C library that makes a system call&lt;br /&gt;
** What if you wanted to &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** &amp;lt;code&amp;gt;printk()&amp;lt;/code&amp;gt; is a reimplementation, because&lt;br /&gt;
**** &amp;lt;code&amp;gt;printf&amp;lt;/code&amp;gt; would &amp;quot;bottom out&amp;quot; by making a system call to write()&lt;br /&gt;
**** &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt; is used to generate logs&lt;br /&gt;
**** how does it do that?&lt;br /&gt;
***** keeps a buffer until they can be printed somewhere&lt;br /&gt;
***** bootup messages? produced by &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;&lt;br /&gt;
*** kernel has its own weird world of standard libraries&lt;br /&gt;
* Some special syntax around declaring init and exit functions..&lt;br /&gt;
* How does kernel actually load a module? (ie. through &amp;lt;code&amp;gt;module_init()&amp;lt;/code&amp;gt; call in simple.c)&lt;br /&gt;
** don&#039;t worry about it. always something you don&#039;t understand...&lt;br /&gt;
** and this is one of these things few people need to understand!&lt;br /&gt;
** you just needs to know how to use it.&lt;br /&gt;
* Why doesn&#039;t simple_exit return anything? Nobody cares what it returns!&lt;br /&gt;
** vs. if init failed... we would care&lt;br /&gt;
	&lt;br /&gt;
Rule of kernel programming: do as little as possible&lt;br /&gt;
* nicer to write in userspace&lt;br /&gt;
&lt;br /&gt;
=== ones.c ===&lt;br /&gt;
* kernel module that implements a device driver for &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** from linux kernels perspective.. same as any other device&lt;br /&gt;
** a module might be a device driver, but might not be&lt;br /&gt;
** and a driver might be baked into the kernel (not a module)&lt;br /&gt;
** but usually, device drivers are implemented as modules&lt;br /&gt;
* makes a character device: &amp;lt;code&amp;gt;register_chrdev()&amp;lt;/code&amp;gt;&lt;br /&gt;
** every device has a major and a minor number: the above function returns major number&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;strong&amp;gt;ones_fops { }&amp;lt;/strong&amp;gt;&amp;lt;/code&amp;gt;: important.  struct containing function pointers.&lt;br /&gt;
** we never call these functions in ones.c&lt;br /&gt;
** these implement the file operations on &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
*** after normal syscall dispatcher stuff, it will want to know HOW to open the device, read, etc&lt;br /&gt;
*** what if we wanted to do a write?&lt;br /&gt;
**** well, &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; is opened read-only. let&#039;s &amp;lt;code&amp;gt;chmod a+w /dev/ones&amp;lt;/code&amp;gt;.&lt;br /&gt;
**** &amp;lt;code&amp;gt;echo 5 &amp;gt; /dev/ones&amp;lt;/code&amp;gt;  // write error&lt;br /&gt;
**** we only have the operations that we&#039;ve implemented&lt;br /&gt;
** who calls them? &lt;br /&gt;
* &amp;lt;code&amp;gt;class_create()&amp;lt;/code&amp;gt; ?&lt;br /&gt;
** can&#039;t just create a device from the major number&lt;br /&gt;
** need a class first before running &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt;&lt;br /&gt;
** grouping of all devices that use the same driver&lt;br /&gt;
** see &amp;lt;code&amp;gt;/sys/class/comp3000&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;/sys/devices/virtual/comp3000/ones&amp;lt;/code&amp;gt;&lt;br /&gt;
** what&#039;s this about? metadata.&lt;br /&gt;
** thankfully we didn&#039;t have to create this ourself - &amp;lt;code&amp;gt;device_create()&amp;lt;/code&amp;gt; took care of all that&lt;br /&gt;
* failed_devreg, etc:&lt;br /&gt;
** handling failures is really important in kernel programming.&lt;br /&gt;
** if something fails and you don&#039;t manually deregister / deallocate memory, it never gets &amp;quot;cleaned up&amp;quot;&lt;br /&gt;
*** stays in physical memory until you reboot&lt;br /&gt;
* How did we come up with this code, generally?&lt;br /&gt;
** no manpages&lt;br /&gt;
** the linux kernel source is the ultimate reference for how this works&lt;br /&gt;
** best way to figure it out is to look at existing device drivers, modify to your purpose, trial &amp;amp; error...&lt;br /&gt;
* &amp;lt;code&amp;gt;ones_read()&amp;lt;/code&amp;gt;:&lt;br /&gt;
** similar to &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; in userspace&lt;br /&gt;
** in userspace you take a file descriptor; in kernel you take a pointer to a file struct&lt;br /&gt;
** &amp;lt;code&amp;gt;buf, len&amp;lt;/code&amp;gt; just as in &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt;..&lt;br /&gt;
** offset? point to specific part of the file&lt;br /&gt;
** the file is always going to be &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt; in this case (since it is a device driver)&lt;br /&gt;
** why &amp;lt;code&amp;gt;put_user(&#039;1&#039;, buf++)&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;*buf++ = 1&amp;lt;/code&amp;gt;?&lt;br /&gt;
*** The 1&#039;s are going out into userspace. This is what &amp;lt;code&amp;gt;put_user()&amp;lt;/code&amp;gt; is for.&lt;br /&gt;
&lt;br /&gt;
aside: &amp;lt;code&amp;gt;find . -name &amp;quot;ones&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* will find files named &amp;quot;ones&amp;quot; in current directory (.)&lt;br /&gt;
&lt;br /&gt;
Look at newgetpid.c&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_11&amp;diff=22024</id>
		<title>Operating Systems 2018F Lecture 11</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_11&amp;diff=22024"/>
		<updated>2018-11-21T20:38:49Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 10, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec11-20181010.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
* Today:&lt;br /&gt;
** Discussing Assignment Solutions&lt;br /&gt;
&lt;br /&gt;
* From Assignment 2:&lt;br /&gt;
** The first two questions are related, however, the first question requires you make a hard link. A hard link means that both associations point to the same inodes. A hard link just creates a separate differently named association that accesses the same file. (Hard links only work within a single file system)&lt;br /&gt;
** The second question involves creating a symbolic link. Running lstat() returns the inode relating to the link instead of to the file.&lt;br /&gt;
** Question 3  statbuf has the user id and group id stored. The username and group name can be looked up via the password file using getgrgrid() and getpwuid().&lt;br /&gt;
** Question 4  Trying to write to the file produces a SEGFAULT. The reason for this is that you do not have access to write to the file as it is readonly. A SEGFAULT will be produced any time an attempt is made to access private memory. PROT_READ would allow you to have access however.&lt;br /&gt;
** Question 6  Placing an exit command within the if statement at line 215 will permanently stop the consumer.&lt;br /&gt;
** Question 7  malloc uses private memory  whereas mmap does not. Replacing mmap with malloc means the producer and consumer will be accessing separate memory and the consumer will never consume.&lt;br /&gt;
** Qestion 8  The kill signals are interrupting the sleep commands. Removing the kill signals means the sleeps will never be interrupted and there will be a delay every time.&lt;br /&gt;
** Question 9  You are not supposed to be able to predict the output of /dev/random. Technically you can if you can figure out the inputs. If the input was compromised then the random numbers could be compromised.&lt;br /&gt;
** Question 10  sem_wait() and sem_post() do not produce system calls. They do require special CPU instructions, but do not need to make system calls.&lt;br /&gt;
&lt;br /&gt;
* Why use goto?&lt;br /&gt;
** In C, there isnt built in error handling such as try catch, so goto can be used for error handling since they stay in method scope.&lt;br /&gt;
** Linux kernel code uses goto in this manner.&lt;br /&gt;
&lt;br /&gt;
* Assignment 1&lt;br /&gt;
** Question 1  When a process is run in the foreground the shell will wait for the program to terminate, but when a process is run in the background the shell will not wait. This means the default is to run background processes and extra information is required to monitor processes in the foreground.&lt;br /&gt;
** Question 2  Signals are not received by system calls.&lt;br /&gt;
** Question 4  Removing the wait() command will prevent the child processes from being properly terminated and so they will accumulate as zombie processes.&lt;br /&gt;
** Question 9  execve does not close file descriptors. If it did you couldnt have stdIn, stdError. The file descriptors for stdOut is 0, stdIn is 1, and stdError is 2. File descriptors are what are returned when a file is opened for the purposes of reading and writing to the file. Therefore, every open file will have a file descriptor.&lt;br /&gt;
** Question 10  An in-progress system call is interrupted upon receiving a signal. It can possibly be restarted later.&lt;br /&gt;
** Question 11  plist is doing an ls command on /proc. This specifically shows comm files which most other directories will not contain. Thus giving different directories to plist will not give much back.&lt;br /&gt;
** Question 12  Input the file through $echo FileToDirect &amp;gt; shell3000. Use dup2 to retrieve the file descriptor and then run it using execve.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21798</id>
		<title>Operating Systems 2018F Lecture 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21798"/>
		<updated>2018-10-02T00:00:33Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 26, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec08-20180928.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec08/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
*Things you can do with remote linux server:&lt;br /&gt;
** &#039;&#039;&#039;ssh&#039;&#039;&#039; into the server and use the command line&lt;br /&gt;
** using `x2goclient` can have remote desktop access &lt;br /&gt;
&lt;br /&gt;
*The “cloud” just means computer infrastructure. The “cloud” is really just someone else computer.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;scp&#039;&#039;&#039; : secure copy (remote file copy program)&lt;br /&gt;
&lt;br /&gt;
*Download `WinSCP` for remote file transfers on windows.&lt;br /&gt;
*On macOS or Linux use `scp`  for remote file transfer.&lt;br /&gt;
&lt;br /&gt;
*How do you do backups?&lt;br /&gt;
**&#039;&#039;&#039;rsync&#039;&#039;&#039;: a fast, versatile, remote (and local) file-copying tool&lt;br /&gt;
&lt;br /&gt;
[[File:Lec8-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Send a file or directory to an address:&lt;br /&gt;
&lt;br /&gt;
[[File:Lec8-2.png|none|800px]]&lt;br /&gt;
[[File:Lec8-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Writing an alias for &#039;&#039;&#039;rsync&#039;&#039;&#039; in &#039;&#039;&#039;~/.bashrc&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
[[File:Lec8-4.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039;, &#039;&#039;&#039;munmap&#039;&#039;&#039; - map or unmap files or devices into memory&lt;br /&gt;
&lt;br /&gt;
[[File:Lec8-5.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039; allows us to allocate memory to hold the contents of the file in a memory efficient way. It does this _lazily_ meaning that it only loads into memory what is being read, at the time that it is being read.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-4.png&amp;diff=21797</id>
		<title>File:Lec8-4.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-4.png&amp;diff=21797"/>
		<updated>2018-10-01T23:59:04Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: R.samanfar uploaded a new version of File:Lec8-4.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21796</id>
		<title>Operating Systems 2018F Lecture 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21796"/>
		<updated>2018-10-01T23:57:22Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 26, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec08-20180928.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec08/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
*Things you can do with remote linux server:&lt;br /&gt;
** &#039;&#039;&#039;ssh&#039;&#039;&#039; into the server and use the command line&lt;br /&gt;
** using `x2goclient` can have remote desktop access &lt;br /&gt;
&lt;br /&gt;
*The “cloud” just means computer infrastructure. The “cloud” is really just someone else computer.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;scp&#039;&#039;&#039; : secure copy (remote file copy program)&lt;br /&gt;
&lt;br /&gt;
*Download `WinSCP` for remote file transfers on windows.&lt;br /&gt;
*On macOS or Linux use `scp`  for remote file transfer.&lt;br /&gt;
&lt;br /&gt;
*How do you do backups?&lt;br /&gt;
**&#039;&#039;&#039;rsync&#039;&#039;&#039;: a fast, versatile, remote (and local) file-copying tool&lt;br /&gt;
[[File:Lec8-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
*Send a file or directory to an address:&lt;br /&gt;
[[File:Lec8-2.png|none|800px]]&lt;br /&gt;
[[File:Lec8-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
*Writing an alias for &#039;&#039;&#039;rsync&#039;&#039;&#039; in &#039;&#039;&#039;~/.bashrc&#039;&#039;&#039;:&lt;br /&gt;
[[File:Lec8-4.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039;, &#039;&#039;&#039;munmap&#039;&#039;&#039; - map or unmap files or devices into memory&lt;br /&gt;
&lt;br /&gt;
[[File:Lec8-5.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039; allows us to allocate memory to hold the contents of the file in a memory efficient way. It does this _lazily_ meaning that it only loads into memory what is being read, at the time that it is being read.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-5.png&amp;diff=21795</id>
		<title>File:Lec8-5.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-5.png&amp;diff=21795"/>
		<updated>2018-10-01T23:55:13Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-4.png&amp;diff=21794</id>
		<title>File:Lec8-4.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-4.png&amp;diff=21794"/>
		<updated>2018-10-01T23:55:00Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-3.png&amp;diff=21793</id>
		<title>File:Lec8-3.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-3.png&amp;diff=21793"/>
		<updated>2018-10-01T23:54:52Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-2.png&amp;diff=21792</id>
		<title>File:Lec8-2.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-2.png&amp;diff=21792"/>
		<updated>2018-10-01T23:54:44Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-1.png&amp;diff=21791</id>
		<title>File:Lec8-1.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec8-1.png&amp;diff=21791"/>
		<updated>2018-10-01T23:54:35Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21790</id>
		<title>Operating Systems 2018F Lecture 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_8&amp;diff=21790"/>
		<updated>2018-10-01T23:54:18Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 26, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec08-20180928.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec08/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
*Things you can do with remote linux server:&lt;br /&gt;
** &#039;&#039;&#039;ssh&#039;&#039;&#039; into the server and use the command line&lt;br /&gt;
** using `x2goclient` can have remote desktop access &lt;br /&gt;
&lt;br /&gt;
*The “cloud” just means computer infrastructure. The “cloud” is really just someone else computer.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;scp&#039;&#039;&#039; : secure copy (remote file copy program)&lt;br /&gt;
&lt;br /&gt;
*Download `WinSCP` for remote file transfers on windows.&lt;br /&gt;
*On macOS or Linux use `scp`  for remote file transfer.&lt;br /&gt;
&lt;br /&gt;
*How do you do backups?&lt;br /&gt;
**&#039;&#039;&#039;rsync&#039;&#039;&#039;: a fast, versatile, remote (and local) file-copying tool&lt;br /&gt;
*Send a file or directory to an address:&lt;br /&gt;
&lt;br /&gt;
*Writing an alias for &#039;&#039;&#039;rsync&#039;&#039;&#039; in &#039;&#039;&#039;~/.bashrc&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039;, &#039;&#039;&#039;munmap&#039;&#039;&#039; - map or unmap files or devices into memory&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;mmap&#039;&#039;&#039; allows us to allocate memory to hold the contents of the file in a memory efficient way. It does this _lazily_ meaning that it only loads into memory what is being read, at the time that it is being read.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_6&amp;diff=21789</id>
		<title>Operating Systems 2018F Lecture 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_6&amp;diff=21789"/>
		<updated>2018-10-01T23:36:19Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 21, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec06-20180921.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec06/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===Terminal Notes:===&lt;br /&gt;
&lt;br /&gt;
*ls -la &amp;amp;rarr;&lt;br /&gt;
 1st column:   read/write permissions. (r: read, w: write, x: execute)&lt;br /&gt;
 2nd column:   # of pointers to a file/directory.&lt;br /&gt;
 3rd column:   user (owner)&lt;br /&gt;
 4th column:   group &lt;br /&gt;
 5th column:   size of file/directory&lt;br /&gt;
 6th column:   date last modified&lt;br /&gt;
 Last column:  file/directory name&lt;br /&gt;
&lt;br /&gt;
*ls -lai &amp;amp;rarr;&lt;br /&gt;
 list the inodes as well (shows in first column)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*ln -s f1 f2 &amp;amp;rarr;&lt;br /&gt;
 Create symbolic link. f2 becomes a reference to f1. &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
 &#039;&#039;&#039;Note:&#039;&#039;&#039; f2 is refering to f1&#039;s name. NOT its inode. (f1 and f2 are the file/directory names)&lt;br /&gt;
If you remove f1 after creating the above link, it will break the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*ln f1 f3 &amp;amp;rarr;&lt;br /&gt;
 Create hard link. f3 becomes a reference to f1.&lt;br /&gt;
 &lt;br /&gt;
Note: The absence of the &#039;-s&#039; in the ln command causes the link to be to f1&#039;s inode. If you remove f1 after creating the above link, it will NOT break the link.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*More Information on Symbolic Links and Inode&#039;s:		&lt;br /&gt;
**A symbolic link that refers to a file that doesn&#039;t exist is broken. You have to recreate the target to fix it.&lt;br /&gt;
**Symbolic link can link to a file OR a directory. &lt;br /&gt;
**They can also point to filesystems.&lt;br /&gt;
**Inode #s are only unique to the specific filesystem they belong to.&lt;br /&gt;
 &#039;&#039;&#039;Example:&#039;&#039;&#039; For a given file in your user directory... a file with an identical inode can exist in the virtual filesystem (/proc).&lt;br /&gt;
*Information on removing files:&lt;br /&gt;
**rm in Unix does not necessarily remove the file. It only removes the name and space. &lt;br /&gt;
**The inode is only reclaimed when there are no references remaining for the file.&lt;br /&gt;
*Information on finding inodes:&lt;br /&gt;
**Only the kernel can give us information about a file name&#039;s associated inode. Therefore, we must make a system call.  (i.e. lstat, fstat, etc..)&lt;br /&gt;
**ls -l &amp;amp;rarr; the &#039;-l&#039; option does a &#039;stat&#039; system call on the directory to also provide file info such as name, size, etc..&lt;br /&gt;
 &lt;br /&gt;
 &#039;&#039;&#039;Note:&#039;&#039;&#039; lsat will return information about a link if a symbolic link exists, rather than the file that is being linked to. Fsat will not do this. Fsat will give information about the linked file.&lt;br /&gt;
*Information on Filesystems:&lt;br /&gt;
**Linux supports many filesystems, whereas windows does not.&lt;br /&gt;
**df . &amp;amp;rarr; tells you the location of the filesystem of the current directory you are in.&lt;br /&gt;
===Lecture Notes===&lt;br /&gt;
*inode&lt;br /&gt;
**key data structure in UNIX-like filesystems&lt;br /&gt;
&lt;br /&gt;
*Files have two parts&lt;br /&gt;
**file inode (metadata)&lt;br /&gt;
**file data&lt;br /&gt;
*Directories associate file names with inodes (specifically, inode numbers)&lt;br /&gt;
&lt;br /&gt;
*file metadata in an inode&lt;br /&gt;
**owner&lt;br /&gt;
**group&lt;br /&gt;
**size&lt;br /&gt;
**permissions&lt;br /&gt;
**pointers to data blocks (in some format)&lt;br /&gt;
&lt;br /&gt;
*Where are filesystems stored?&lt;br /&gt;
**persistent arrays&lt;br /&gt;
**array entries are &amp;quot;blocks&amp;quot;&lt;br /&gt;
**4K traditionally, but can be bigger or smaller&lt;br /&gt;
&lt;br /&gt;
*To access, kernel gives device a block number, gets back block contents.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_5&amp;diff=21788</id>
		<title>Operating Systems 2018F Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_5&amp;diff=21788"/>
		<updated>2018-10-01T23:14:01Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 19, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec05-20180919.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec05/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===Notes on Tutorial 2===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Q6:&#039;&#039;&#039; Make the shell output &amp;quot;Ouch!&amp;quot; when you send it a SIGUSR1 signal.&lt;br /&gt;
*To test, send a signal to a process&lt;br /&gt;
*Use kill command &lt;br /&gt;
**kill -&amp;lt;SIGNALNAME&amp;gt; &amp;lt;PID&amp;gt; &lt;br /&gt;
**ex: kill -USR1 4094&lt;br /&gt;
&#039;&#039;&#039;Q8:&#039;&#039;&#039;  Replace the use of find_env() with getenv(). How do their interfaces differ?&lt;br /&gt;
*How are the parameters/arguments different&lt;br /&gt;
*Look at man pages for getenv() &lt;br /&gt;
*Different number of arguments &lt;br /&gt;
*Why does getenv() not need the environment to be passed in&lt;br /&gt;
** It has it already &lt;br /&gt;
**#man pages, see also, environ  is user environment global variable defined by standard library&lt;br /&gt;
**#Longer answer: we got the environment variable from main as an argument (*envp[])&lt;br /&gt;
&#039;&#039;&#039;Q9:&#039;&#039;&#039; Use putenv() to implement LASTCOMMAND from Tutorial 1.&lt;br /&gt;
*putenv() handles variables for you &lt;br /&gt;
*Allows you to define environment variables and add it&lt;br /&gt;
*Only changes for current process &lt;br /&gt;
**To change for another process, fork and use execve &lt;br /&gt;
===Notes on Assignment 1 ===&lt;br /&gt;
*Not finalized = “not completely debugged”&lt;br /&gt;
*Due Sept 26th 2:30pm&lt;br /&gt;
*Based on tutorials &lt;br /&gt;
*Question 9 looking at man page for execve can get an answer- not what he’s talking about, he wants experimental evidence &lt;br /&gt;
*Solutions will be posted and discussed in class Sept 26th&lt;br /&gt;
===Class Notes===&lt;br /&gt;
&lt;br /&gt;
*Signals:&lt;br /&gt;
**is a message sent to a process&lt;br /&gt;
**some can be blocked until unblocked&lt;br /&gt;
**SIGKILL and SIGSTOP cannot be caught, blocked or ignored &lt;br /&gt;
**Handlers respond to specific signals&lt;br /&gt;
***Interrupts what’s currently happening&lt;br /&gt;
***Can cause jumps that happen randomly in your program&lt;br /&gt;
***You don’t know the state of the program when a signal handler executes &lt;br /&gt;
***Kernel calls a function&lt;br /&gt;
***Don’t try to handle a signal in a signal handler, generally block them in a handler &lt;br /&gt;
***If you don’t define a signal handler, there is a default handler that will run&lt;br /&gt;
**No signal handler for SIGKILL or SIGSTOP &lt;br /&gt;
**Can run strace on kill signal&lt;br /&gt;
***Does kill system call &lt;br /&gt;
***Takes a process id and a signal&lt;br /&gt;
*I/O redirection:&lt;br /&gt;
**changing which file things get written to &lt;br /&gt;
**ls &amp;gt; foo.txt&lt;br /&gt;
***foo.txt contains the contents that ls outputted &lt;br /&gt;
***&#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; send output to foo.txt &lt;br /&gt;
***ls does not know about redirection &lt;br /&gt;
***ls should send it is output to foo.txt&lt;br /&gt;
***ls without redirection is already outputting to a file (standard output- file descriptor 1)&lt;br /&gt;
****standard out sends information to a file &lt;br /&gt;
****fprintf – goes to file descriptor 2&lt;br /&gt;
****printf – goes to file descriptor 1&lt;br /&gt;
**ps aux&lt;br /&gt;
***shows you what’s running and what terminal it is connected to (tty2, ?, pts/0)&lt;br /&gt;
****pts/0 – sudo terminal &lt;br /&gt;
****tty1 – used to run log in &lt;br /&gt;
***terminal usually referred to as tty (teletype, screen and keyboard, connects to another computer)&lt;br /&gt;
*File descriptors&lt;br /&gt;
**a number associated with an open file &lt;br /&gt;
**each process has its own file descriptor&lt;br /&gt;
**first file opened is assigned file descriptor 0 &lt;br /&gt;
**stored on the kernel &lt;br /&gt;
**by default in linux there are file descriptors for every program&lt;br /&gt;
**the shell makes sure that file descriptors 0,1,2 are open and are going somewhere valid&lt;br /&gt;
===Useful Commands/examples===&lt;br /&gt;
&lt;br /&gt;
*envp – came from main, can be changed by putenv &lt;br /&gt;
*ls /proc&lt;br /&gt;
**Tells you information on all the running processes&lt;br /&gt;
**Can cd into a process id directory &lt;br /&gt;
***fd – file descriptor directory &lt;br /&gt;
***ex: /proc/1973/fd&lt;br /&gt;
**echo $TERM &lt;br /&gt;
**tells you what terminal you are using  &lt;br /&gt;
**TERM is an environment variable &lt;br /&gt;
*cd /dev&lt;br /&gt;
**can see all of the special files &lt;br /&gt;
**b – block devices&lt;br /&gt;
**c – character devices &lt;br /&gt;
*echo hello &amp;gt; 0     &lt;br /&gt;
*echo hello &amp;gt; 1&lt;br /&gt;
**run in one terminal, can write to file displayed in another terminal &lt;br /&gt;
**numbers correspond to different terminals being used &lt;br /&gt;
**if you have permission you can write to them (other users would not be allowed)&lt;br /&gt;
*echo hello &amp;gt; test1&lt;br /&gt;
**to the shell, please open the file test1 for writing, open it on file descriptor 1, the process will then do an execve of echo&lt;br /&gt;
**cat test -&amp;gt; results in “hello” &lt;br /&gt;
*cat 333shell.c | sort&lt;br /&gt;
**vertical bar is a pipe&lt;br /&gt;
**whatever is written by cat will be read by sort &lt;br /&gt;
**pairing of file descriptors &lt;br /&gt;
**sorted all the lines of the program &lt;br /&gt;
*pstree&lt;br /&gt;
**displays the tree of all running processes&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_5&amp;diff=21787</id>
		<title>Operating Systems 2018F Lecture 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_5&amp;diff=21787"/>
		<updated>2018-10-01T23:12:33Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 19, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec05-20180919.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec05/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
===Notes on Tutorial 2===&lt;br /&gt;
&#039;&#039;&#039;Q6:&#039;&#039;&#039; Make the shell output &amp;quot;Ouch!&amp;quot; when you send it a SIGUSR1 signal.&lt;br /&gt;
*To test, send a signal to a process&lt;br /&gt;
*Use kill command &lt;br /&gt;
**kill -&amp;lt;SIGNALNAME&amp;gt; &amp;lt;PID&amp;gt; &lt;br /&gt;
**ex: kill -USR1 4094&lt;br /&gt;
&#039;&#039;&#039;Q8:&#039;&#039;&#039;  Replace the use of find_env() with getenv(). How do their interfaces differ?&lt;br /&gt;
*How are the parameters/arguments different&lt;br /&gt;
*Look at man pages for getenv() &lt;br /&gt;
*Different number of arguments &lt;br /&gt;
*Why does getenv() not need the environment to be passed in&lt;br /&gt;
** It has it already &lt;br /&gt;
**#man pages, see also, environ  is user environment global variable defined by standard library&lt;br /&gt;
**#Longer answer: we got the environment variable from main as an argument (*envp[])&lt;br /&gt;
&#039;&#039;&#039;Q9:&#039;&#039;&#039; Use putenv() to implement LASTCOMMAND from Tutorial 1.&lt;br /&gt;
*putenv() handles variables for you &lt;br /&gt;
*Allows you to define environment variables and add it&lt;br /&gt;
*Only changes for current process &lt;br /&gt;
**To change for another process, fork and use execve &lt;br /&gt;
===Notes on Assignment 1 ===&lt;br /&gt;
*Not finalized = “not completely debugged”&lt;br /&gt;
*Due Sept 26th 2:30pm&lt;br /&gt;
*Based on tutorials &lt;br /&gt;
*Question 9 looking at man page for execve can get an answer- not what he’s talking about, he wants experimental evidence &lt;br /&gt;
*Solutions will be posted and discussed in class Sept 26th&lt;br /&gt;
===Class Notes===&lt;br /&gt;
*Signals:&lt;br /&gt;
**is a message sent to a process&lt;br /&gt;
**some can be blocked until unblocked&lt;br /&gt;
**SIGKILL and SIGSTOP cannot be caught, blocked or ignored &lt;br /&gt;
**Handlers respond to specific signals&lt;br /&gt;
***Interrupts what’s currently happening&lt;br /&gt;
***Can cause jumps that happen randomly in your program&lt;br /&gt;
***You don’t know the state of the program when a signal handler executes &lt;br /&gt;
***Kernel calls a function&lt;br /&gt;
***Don’t try to handle a signal in a signal handler, generally block them in a handler &lt;br /&gt;
***If you don’t define a signal handler, there is a default handler that will run&lt;br /&gt;
**No signal handler for SIGKILL or SIGSTOP &lt;br /&gt;
**Can run strace on kill signal&lt;br /&gt;
***Does kill system call &lt;br /&gt;
***Takes a process id and a signal&lt;br /&gt;
*I/O redirection:&lt;br /&gt;
**changing which file things get written to &lt;br /&gt;
**ls &amp;gt; foo.txt&lt;br /&gt;
***foo.txt contains the contents that ls outputted &lt;br /&gt;
***&#039;&#039;&#039;&amp;gt;&#039;&#039;&#039; send output to foo.txt &lt;br /&gt;
***ls does not know about redirection &lt;br /&gt;
***ls should send it is output to foo.txt&lt;br /&gt;
***ls without redirection is already outputting to a file (standard output- file descriptor 1)&lt;br /&gt;
****standard out sends information to a file &lt;br /&gt;
****fprintf – goes to file descriptor 2&lt;br /&gt;
****printf – goes to file descriptor 1&lt;br /&gt;
**ps aux&lt;br /&gt;
***shows you what’s running and what terminal it is connected to (tty2, ?, pts/0)&lt;br /&gt;
****pts/0 – sudo terminal &lt;br /&gt;
****tty1 – used to run log in &lt;br /&gt;
***terminal usually referred to as tty (teletype, screen and keyboard, connects to another computer)&lt;br /&gt;
*File descriptors&lt;br /&gt;
**a number associated with an open file &lt;br /&gt;
**each process has its own file descriptor&lt;br /&gt;
**first file opened is assigned file descriptor 0 &lt;br /&gt;
**stored on the kernel &lt;br /&gt;
**by default in linux there are file descriptors for every program&lt;br /&gt;
**the shell makes sure that file descriptors 0,1,2 are open and are going somewhere valid&lt;br /&gt;
===Useful Commands/examples===&lt;br /&gt;
*envp – came from main, can be changed by putenv &lt;br /&gt;
*ls /proc&lt;br /&gt;
**Tells you information on all the running processes&lt;br /&gt;
**Can cd into a process id directory &lt;br /&gt;
***fd – file descriptor directory &lt;br /&gt;
***ex: /proc/1973/fd&lt;br /&gt;
**echo $TERM &lt;br /&gt;
**tells you what terminal you are using  &lt;br /&gt;
**TERM is an environment variable &lt;br /&gt;
*cd /dev&lt;br /&gt;
**can see all of the special files &lt;br /&gt;
**b – block devices&lt;br /&gt;
**c – character devices &lt;br /&gt;
*echo hello &amp;gt; 0     &lt;br /&gt;
*echo hello &amp;gt; 1&lt;br /&gt;
**run in one terminal, can write to file displayed in another terminal &lt;br /&gt;
**numbers correspond to different terminals being used &lt;br /&gt;
**if you have permission you can write to them (other users would not be allowed)&lt;br /&gt;
*echo hello &amp;gt; test1&lt;br /&gt;
**to the shell, please open the file test1 for writing, open it on file descriptor 1, the process will then do an execve of echo&lt;br /&gt;
**cat test -&amp;gt; results in “hello” &lt;br /&gt;
*cat 333shell.c | sort&lt;br /&gt;
**vertical bar is a pipe&lt;br /&gt;
**whatever is written by cat will be read by sort &lt;br /&gt;
**pairing of file descriptors &lt;br /&gt;
**sorted all the lines of the program &lt;br /&gt;
*pstree&lt;br /&gt;
**displays the tree of all running processes&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21786</id>
		<title>Operating Systems 2018F Lecture 3</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21786"/>
		<updated>2018-10-01T22:51:26Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 12, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec03-20180912.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec03/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
*Sources of confusion from Tutorial 1: &lt;br /&gt;
**Where is good assembly documentation?&lt;br /&gt;
***Probably in books&lt;br /&gt;
***Online&lt;br /&gt;
***(Not expected to learn assembly)&lt;br /&gt;
**Local variables&lt;br /&gt;
**Environment variables&lt;br /&gt;
**gcc arguments&lt;br /&gt;
*The –O2 argument for gcc is for choosing an optimization level (namely, level 2)&lt;br /&gt;
===Linking===&lt;br /&gt;
*A file that is statically linked does not have any library calls&lt;br /&gt;
*What is linking?&lt;br /&gt;
**Taking object files and putting them together to make a full binary, particularly resolving symbolic references between object files.&lt;br /&gt;
*Static linking is the old way. Dynamic linking is how we do things today.&lt;br /&gt;
*nm command for showing symbols&lt;br /&gt;
===System and Function Calls===&lt;br /&gt;
*What is a system call in assembly? What is a function call in assembly?&lt;br /&gt;
*(Time: 9:00) Looking at hello.c&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[]) {&lt;br /&gt;
         printf(&amp;quot;Hello world!\n&amp;quot;);&lt;br /&gt;
         return 0;&lt;br /&gt;
 }&lt;br /&gt;
*Professor enters the command: gcc –S –O2 hello.c, which generates the assembly file hello.s . The –S option for gcc does not tell it to do more work, it tells it to do less work.&lt;br /&gt;
&lt;br /&gt;
*(Time: 12:05) Looking at the assembly file of hello.c&lt;br /&gt;
[[File:Lec3-1.png|none|800px]]&lt;br /&gt;
**All of the things with dot (.) in front of them are declarations (instructions to the assembler) and are not actual operations.&lt;br /&gt;
**Looking at the line that has a function call to puts. Since we are not using much of the fancy functionality of printf (the function we actually called), a modern compiler environment does optimization which involves changing code and swapping a fancy function like printf with a simpler function like puts to print what we want to the screen.&lt;br /&gt;
**The name for the string (i.e. “Hello world!”) is .LC0&lt;br /&gt;
**Compilation is a black box&lt;br /&gt;
**The call operation in assembly is for calling functions. The puts that we see is a function call.&lt;br /&gt;
**System calls are fundamentally different from function calls. They are different in a way&lt;br /&gt;
*such that they cannot be created in standard C.&lt;br /&gt;
**We can create a system call in only two ways:&lt;br /&gt;
***putting inline assembly in standard C code.&lt;br /&gt;
***use a compiler specific operation that tells it to generate code for the system call.&lt;br /&gt;
*Professor writes the following commands on the terminal:&lt;br /&gt;
**gcc –static –O2 hello.c –o hello&lt;br /&gt;
**strace ./hello à strace gives you the system calls that a running program makes.&lt;br /&gt;
**(Time: 26:25) The write system call is the system call that actually did the work that we intended to do.&lt;br /&gt;
**So, the puts function somehow made a write system call which is what produced the text output to the console.&lt;br /&gt;
*What is a function call? The following happens when you call a function:&lt;br /&gt;
**Save arguments (to registers or the stack)&lt;br /&gt;
**Call function&lt;br /&gt;
***Saves (pushes) current instruction pointer onto call stack&lt;br /&gt;
***Changes instruction pointer to the location of the beginning of the function&lt;br /&gt;
***... Function runs...&lt;br /&gt;
***on function return, pops instruction pointer from the stack, restoring the old function pointer.&lt;br /&gt;
*Everything is based on pointers to code&lt;br /&gt;
*&#039;&#039;&#039;(Time: 35:00)&#039;&#039;&#039; The nm command tells us, in the first column of its output, where things are located.&lt;br /&gt;
**If you look at an object file with nm, before it has been linked, you will see that all addresses are zero. This means that we do not know where they are in memory.&lt;br /&gt;
**In contrast, when we look at a compiled program we can see symbols at specific addresses in memory.&lt;br /&gt;
**Are these addresses unique to this program? In other words, is any particular address, in the program symbol table listed, unique across all programs running on my computer?&lt;br /&gt;
***No!&lt;br /&gt;
***This means that you could have a function located in the same memory location in completely different processes.&lt;br /&gt;
***Pointers in a process are &#039;&#039;&#039;local&#039;&#039;&#039;&lt;br /&gt;
***Addresses only have meaning in the context of the process&lt;br /&gt;
***Every process has a completely different namespace&lt;br /&gt;
*Address space – name space for pointers.&lt;br /&gt;
*(Time : 39:00) What is a System Call?&lt;br /&gt;
**It is an invocation of kernel code.&lt;br /&gt;
**The kernel is the code that defines the system. It is what implements the processes. It implements the namespaces that make separate processes.&lt;br /&gt;
**A system call entails calling code that is not necessarily in your address space.&lt;br /&gt;
**A system call entails calling code with higher privileges.&lt;br /&gt;
***Running in supervisor mode, not user mode&lt;br /&gt;
**How can I call privileged code safely? (code that runs in supervisor mode)&lt;br /&gt;
***Restrict the entry points to privileged code&lt;br /&gt;
****Can’t call arbitrary routines.&lt;br /&gt;
***Entry point should check whether operation is allowed.&lt;br /&gt;
***In the kernel, this is what the system call dispatcher does&lt;br /&gt;
**System Call Dispatcher&lt;br /&gt;
***Process requests system call (write)&lt;br /&gt;
***CPU switches to supervisor mode, runs system call dispatcher&lt;br /&gt;
***Dispatcher decides if system call is allowed&lt;br /&gt;
***System call code (write) is invoked&lt;br /&gt;
**CPU switches into supervisor mode using special instructions&lt;br /&gt;
***“software interrupts”&lt;br /&gt;
***“upcall” &amp;amp;rarr; How do I call the kernel&lt;br /&gt;
**The C library has function wrappers around standard system calls.&lt;br /&gt;
**When we say that we are making a ‘system call’ from C, we normally mean that we are making a function call, whose function is a wrapper around the system call we intended to call.&lt;br /&gt;
**Professor enters the following commands:&lt;br /&gt;
***gcc –O2 hello.c –o hello&lt;br /&gt;
***ltrace ./hello&lt;br /&gt;
***ltrace tells you about functions that are called. After this command, we see that ltrace says that there is a puts function.&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***After this command, we can see lots of system calls. We can identify the write system call at the end.&lt;br /&gt;
***gcc –O2 –static hello.c –o hello&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***When linking statically, we can see that we get a lot less system calls.&lt;br /&gt;
*At the function call level, you call code inside your process.&lt;br /&gt;
*At the system call level, you call code outside your process. System calls are more expensive than function calls.&lt;br /&gt;
*We have not seen any assembly of a system call yet.&lt;br /&gt;
===Walking through CSimpleShell.c===&lt;br /&gt;
*&#039;&#039;&#039;(Time: 1:00:13)&#039;&#039;&#039; Looking at csimpleshell.c&lt;br /&gt;
[[File:Lec3-2.png|none|800px]]&lt;br /&gt;
*We have an infinite loop in which we do:&lt;br /&gt;
**Print ‘$’ sign, for printing a prompt&lt;br /&gt;
**fgets is for reading an input&lt;br /&gt;
**parse_args &amp;amp;rarr; parses arguments, converts a single string into an array of strings&lt;br /&gt;
***takes the buffer of the input from the user&lt;br /&gt;
***takes in args which is an array of ARR_SIZE (which is 1&amp;lt;&amp;lt;16 &amp;amp;rarr; means 1 right shifted 16 bits i.e. 2^(16)).&lt;br /&gt;
***Takes in nargs which is the number of arguments&lt;br /&gt;
If there are no args (nargs == 0), then we continue (i.e. go to the next iteration of&lt;br /&gt;
the loop).&lt;br /&gt;
**If the first argument == “exit”, then call the exit function&lt;br /&gt;
**Otherwise, we fork with the function fork( )&lt;br /&gt;
**If the pid is not 0, then the current process is the parent process. It prints that it is waiting for the child , waits, and then prints that the child is done.&lt;br /&gt;
**If the pid is 0, the current process is the child process. The child process calls execvp which is like execve, except that you don’t need to supply the environment variables (it just needs the arguments).&lt;br /&gt;
**If execvp fails, the puts function below it will be called to indicate an error on the terminal and we exit with exit(127&lt;br /&gt;
*We can run external programs with execve&lt;br /&gt;
*Every process has its own namespace, memory, address space. How then, do you pass variables from one to the other?&lt;br /&gt;
*Where is a username stored? Is a system call required to get the value of username?&lt;br /&gt;
**Username information is inside the process. It is in the address space. A system call is not required to get the value of username.&lt;br /&gt;
**Professor prints the environment variables.&lt;br /&gt;
**When you load a program binary you give execve:&lt;br /&gt;
*#The binary&lt;br /&gt;
*#The command line arguments&lt;br /&gt;
*#Environment variables&lt;br /&gt;
**Environment variables are available as an argument to main. They are variables that are in your process that the kernel happens to put there when you start.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec3-2.png&amp;diff=21785</id>
		<title>File:Lec3-2.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec3-2.png&amp;diff=21785"/>
		<updated>2018-10-01T22:50:11Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec3-1.png&amp;diff=21784</id>
		<title>File:Lec3-1.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec3-1.png&amp;diff=21784"/>
		<updated>2018-10-01T22:50:02Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21783</id>
		<title>Operating Systems 2018F Lecture 3</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21783"/>
		<updated>2018-10-01T22:49:38Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 12, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec03-20180912.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec03/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
*Sources of confusion from Tutorial 1: &lt;br /&gt;
**Where is good assembly documentation?&lt;br /&gt;
***Probably in books&lt;br /&gt;
***Online&lt;br /&gt;
***(Not expected to learn assembly)&lt;br /&gt;
**Local variables&lt;br /&gt;
**Environment variables&lt;br /&gt;
**gcc arguments&lt;br /&gt;
*The –O2 argument for gcc is for choosing an optimization level (namely, level 2)&lt;br /&gt;
===Linking===&lt;br /&gt;
*A file that is statically linked does not have any library calls&lt;br /&gt;
*What is linking?&lt;br /&gt;
**Taking object files and putting them together to make a full binary, particularly resolving symbolic references between object files.&lt;br /&gt;
*Static linking is the old way. Dynamic linking is how we do things today.&lt;br /&gt;
*nm command for showing symbols&lt;br /&gt;
===System and Function Calls===&lt;br /&gt;
*What is a system call in assembly? What is a function call in assembly?&lt;br /&gt;
*(Time: 9:00) Looking at hello.c&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[]) {&lt;br /&gt;
         printf(&amp;quot;Hello world!\n&amp;quot;);&lt;br /&gt;
         return 0;&lt;br /&gt;
 }&lt;br /&gt;
*Professor enters the command: gcc –S –O2 hello.c, which generates the assembly file hello.s . The –S option for gcc does not tell it to do more work, it tells it to do less work.&lt;br /&gt;
&lt;br /&gt;
*(Time: 12:05) Looking at the assembly file of hello.c&lt;br /&gt;
**All of the things with dot (.) in front of them are declarations (instructions to the assembler) and are not actual operations.&lt;br /&gt;
**Looking at the line that has a function call to puts. Since we are not using much of the fancy functionality of printf (the function we actually called), a modern compiler environment does optimization which involves changing code and swapping a fancy function like printf with a simpler function like puts to print what we want to the screen.&lt;br /&gt;
**The name for the string (i.e. “Hello world!”) is .LC0&lt;br /&gt;
**Compilation is a black box&lt;br /&gt;
**The call operation in assembly is for calling functions. The puts that we see is a function call.&lt;br /&gt;
**System calls are fundamentally different from function calls. They are different in a way&lt;br /&gt;
*such that they cannot be created in standard C.&lt;br /&gt;
**We can create a system call in only two ways:&lt;br /&gt;
***putting inline assembly in standard C code.&lt;br /&gt;
***use a compiler specific operation that tells it to generate code for the system call.&lt;br /&gt;
*Professor writes the following commands on the terminal:&lt;br /&gt;
**gcc –static –O2 hello.c –o hello&lt;br /&gt;
**strace ./hello à strace gives you the system calls that a running program makes.&lt;br /&gt;
**(Time: 26:25) The write system call is the system call that actually did the work that we intended to do.&lt;br /&gt;
**So, the puts function somehow made a write system call which is what produced the text output to the console.&lt;br /&gt;
*What is a function call? The following happens when you call a function:&lt;br /&gt;
**Save arguments (to registers or the stack)&lt;br /&gt;
**Call function&lt;br /&gt;
***Saves (pushes) current instruction pointer onto call stack&lt;br /&gt;
***Changes instruction pointer to the location of the beginning of the function&lt;br /&gt;
***... Function runs...&lt;br /&gt;
***on function return, pops instruction pointer from the stack, restoring the old function pointer.&lt;br /&gt;
*Everything is based on pointers to code&lt;br /&gt;
*&#039;&#039;&#039;(Time: 35:00)&#039;&#039;&#039; The nm command tells us, in the first column of its output, where things are located.&lt;br /&gt;
**If you look at an object file with nm, before it has been linked, you will see that all addresses are zero. This means that we do not know where they are in memory.&lt;br /&gt;
**In contrast, when we look at a compiled program we can see symbols at specific addresses in memory.&lt;br /&gt;
**Are these addresses unique to this program? In other words, is any particular address, in the program symbol table listed, unique across all programs running on my computer?&lt;br /&gt;
***No!&lt;br /&gt;
***This means that you could have a function located in the same memory location in completely different processes.&lt;br /&gt;
***Pointers in a process are &#039;&#039;&#039;local&#039;&#039;&#039;&lt;br /&gt;
***Addresses only have meaning in the context of the process&lt;br /&gt;
***Every process has a completely different namespace&lt;br /&gt;
*Address space – name space for pointers.&lt;br /&gt;
*(Time : 39:00) What is a System Call?&lt;br /&gt;
**It is an invocation of kernel code.&lt;br /&gt;
**The kernel is the code that defines the system. It is what implements the processes. It implements the namespaces that make separate processes.&lt;br /&gt;
**A system call entails calling code that is not necessarily in your address space.&lt;br /&gt;
**A system call entails calling code with higher privileges.&lt;br /&gt;
***Running in supervisor mode, not user mode&lt;br /&gt;
**How can I call privileged code safely? (code that runs in supervisor mode)&lt;br /&gt;
***Restrict the entry points to privileged code&lt;br /&gt;
****Can’t call arbitrary routines.&lt;br /&gt;
***Entry point should check whether operation is allowed.&lt;br /&gt;
***In the kernel, this is what the system call dispatcher does&lt;br /&gt;
**System Call Dispatcher&lt;br /&gt;
***Process requests system call (write)&lt;br /&gt;
***CPU switches to supervisor mode, runs system call dispatcher&lt;br /&gt;
***Dispatcher decides if system call is allowed&lt;br /&gt;
***System call code (write) is invoked&lt;br /&gt;
**CPU switches into supervisor mode using special instructions&lt;br /&gt;
***“software interrupts”&lt;br /&gt;
***“upcall” &amp;amp;rarr; How do I call the kernel&lt;br /&gt;
**The C library has function wrappers around standard system calls.&lt;br /&gt;
**When we say that we are making a ‘system call’ from C, we normally mean that we are making a function call, whose function is a wrapper around the system call we intended to call.&lt;br /&gt;
**Professor enters the following commands:&lt;br /&gt;
***gcc –O2 hello.c –o hello&lt;br /&gt;
***ltrace ./hello&lt;br /&gt;
***ltrace tells you about functions that are called. After this command, we see that ltrace says that there is a puts function.&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***After this command, we can see lots of system calls. We can identify the write system call at the end.&lt;br /&gt;
***gcc –O2 –static hello.c –o hello&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***When linking statically, we can see that we get a lot less system calls.&lt;br /&gt;
*At the function call level, you call code inside your process.&lt;br /&gt;
*At the system call level, you call code outside your process. System calls are more expensive than function calls.&lt;br /&gt;
*We have not seen any assembly of a system call yet.&lt;br /&gt;
===Walking through CSimpleShell.c===&lt;br /&gt;
*&#039;&#039;&#039;(Time: 1:00:13)&#039;&#039;&#039; Looking at csimpleshell.c&lt;br /&gt;
*We have an infinite loop in which we do:&lt;br /&gt;
**Print ‘$’ sign, for printing a prompt&lt;br /&gt;
**fgets is for reading an input&lt;br /&gt;
**parse_args &amp;amp;rarr; parses arguments, converts a single string into an array of strings&lt;br /&gt;
***takes the buffer of the input from the user&lt;br /&gt;
***takes in args which is an array of ARR_SIZE (which is 1&amp;lt;&amp;lt;16 &amp;amp;rarr; means 1 right shifted 16 bits i.e. 2^(16)).&lt;br /&gt;
***Takes in nargs which is the number of arguments&lt;br /&gt;
If there are no args (nargs == 0), then we continue (i.e. go to the next iteration of&lt;br /&gt;
the loop).&lt;br /&gt;
**If the first argument == “exit”, then call the exit function&lt;br /&gt;
**Otherwise, we fork with the function fork( )&lt;br /&gt;
**If the pid is not 0, then the current process is the parent process. It prints that it is waiting for the child , waits, and then prints that the child is done.&lt;br /&gt;
**If the pid is 0, the current process is the child process. The child process calls execvp which is like execve, except that you don’t need to supply the environment variables (it just needs the arguments).&lt;br /&gt;
**If execvp fails, the puts function below it will be called to indicate an error on the terminal and we exit with exit(127&lt;br /&gt;
*We can run external programs with execve&lt;br /&gt;
*Every process has its own namespace, memory, address space. How then, do you pass variables from one to the other?&lt;br /&gt;
*Where is a username stored? Is a system call required to get the value of username?&lt;br /&gt;
**Username information is inside the process. It is in the address space. A system call is not required to get the value of username.&lt;br /&gt;
**Professor prints the environment variables.&lt;br /&gt;
**When you load a program binary you give execve:&lt;br /&gt;
*#The binary&lt;br /&gt;
*#The command line arguments&lt;br /&gt;
*#Environment variables&lt;br /&gt;
**Environment variables are available as an argument to main. They are variables that are in your process that the kernel happens to put there when you start.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21782</id>
		<title>Operating Systems 2018F Lecture 3</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_3&amp;diff=21782"/>
		<updated>2018-10-01T22:39:50Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 12, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec03-20180912.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec03/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
*Sources of confusion from Tutorial 1: &lt;br /&gt;
**Where is good assembly documentation?&lt;br /&gt;
***Probably in books&lt;br /&gt;
***Online&lt;br /&gt;
***(Not expected to learn assembly)&lt;br /&gt;
**Local variables&lt;br /&gt;
**Environment variables&lt;br /&gt;
**gcc arguments&lt;br /&gt;
*The –O2 argument for gcc is for choosing an optimization level (namely, level 2)&lt;br /&gt;
===Linking===&lt;br /&gt;
*A file that is statically linked does not have any library calls&lt;br /&gt;
*What is linking?&lt;br /&gt;
**Taking object files and putting them together to make a full binary, particularly resolving symbolic references between object files.&lt;br /&gt;
*Static linking is the old way. Dynamic linking is how we do things today.&lt;br /&gt;
*nm command for showing symbols&lt;br /&gt;
===System and Function Calls===&lt;br /&gt;
*What is a system call in assembly? What is a function call in assembly?&lt;br /&gt;
*(Time: 9:00) Looking at hello.c&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[]) {&lt;br /&gt;
         printf(&amp;quot;Hello world!\n&amp;quot;);&lt;br /&gt;
         return 0;&lt;br /&gt;
 }&lt;br /&gt;
*Professor enters the command: gcc –S –O2 hello.c, which generates the assembly file hello.s . The –S option for gcc does not tell it to do more work, it tells it to do less work.&lt;br /&gt;
&lt;br /&gt;
*(Time: 12:05) Looking at the assembly file of hello.c&lt;br /&gt;
**All of the things with dot (.) in front of them are declarations (instructions to the assembler) and are not actual operations.&lt;br /&gt;
**Looking at the line that has a function call to puts. Since we are not using much of the fancy functionality of printf (the function we actually called), a modern compiler environment does optimization which involves changing code and swapping a fancy function like printf with a simpler function like puts to print what we want to the screen.&lt;br /&gt;
**The name for the string (i.e. “Hello world!”) is .LC0&lt;br /&gt;
**Compilation is a black box&lt;br /&gt;
**The call operation in assembly is for calling functions. The puts that we see is a function call.&lt;br /&gt;
**System calls are fundamentally different from function calls. They are different in a way&lt;br /&gt;
*such that they cannot be created in standard C.&lt;br /&gt;
**We can create a system call in only two ways:&lt;br /&gt;
***putting inline assembly in standard C code.&lt;br /&gt;
***use a compiler specific operation that tells it to generate code for the system call.&lt;br /&gt;
*Professor writes the following commands on the terminal:&lt;br /&gt;
**gcc –static –O2 hello.c –o hello&lt;br /&gt;
**strace ./hello à strace gives you the system calls that a running program makes.&lt;br /&gt;
**(Time: 26:25) The write system call is the system call that actually did the work that we intended to do.&lt;br /&gt;
**So, the puts function somehow made a write system call which is what produced the text output to the console.&lt;br /&gt;
*What is a function call? The following happens when you call a function:&lt;br /&gt;
**Save arguments (to registers or the stack)&lt;br /&gt;
**Call function&lt;br /&gt;
***Saves (pushes) current instruction pointer onto call stack&lt;br /&gt;
***Changes instruction pointer to the location of the beginning of the function&lt;br /&gt;
***... Function runs...&lt;br /&gt;
***on function return, pops instruction pointer from the stack, restoring the old function pointer.&lt;br /&gt;
*Everything is based on pointers to code&lt;br /&gt;
*&#039;&#039;&#039;(Time: 35:00)&#039;&#039;&#039; The nm command tells us, in the first column of its output, where things are located.&lt;br /&gt;
**If you look at an object file with nm, before it has been linked, you will see that all addresses are zero. This means that we do not know where they are in memory.&lt;br /&gt;
**In contrast, when we look at a compiled program we can see symbols at specific addresses in memory.&lt;br /&gt;
**Are these addresses unique to this program? In other words, is any particular address, in the program symbol table listed, unique across all programs running on my computer?&lt;br /&gt;
***No!&lt;br /&gt;
***This means that you could have a function located in the same memory location in completely different processes.&lt;br /&gt;
***Pointers in a process are &#039;&#039;&#039;local&#039;&#039;&#039;&lt;br /&gt;
***Addresses only have meaning in the context of the process&lt;br /&gt;
***Every process has a completely different namespace&lt;br /&gt;
*Address space – name space for pointers.&lt;br /&gt;
*(Time : 39:00) What is a System Call?&lt;br /&gt;
**It is an invocation of kernel code.&lt;br /&gt;
**The kernel is the code that defines the system. It is what implements the processes. It implements the namespaces that make separate processes.&lt;br /&gt;
**A system call entails calling code that is not necessarily in your address space.&lt;br /&gt;
**A system call entails calling code with higher privileges.&lt;br /&gt;
***Running in supervisor mode, not user mode&lt;br /&gt;
**How can I call privileged code safely? (code that runs in supervisor mode)&lt;br /&gt;
***Restrict the entry points to privileged code&lt;br /&gt;
****Can’t call arbitrary routines.&lt;br /&gt;
***Entry point should check whether operation is allowed.&lt;br /&gt;
***In the kernel, this is what the system call dispatcher does&lt;br /&gt;
**System Call Dispatcher&lt;br /&gt;
***Process requests system call (write)&lt;br /&gt;
***CPU switches to supervisor mode, runs system call dispatcher&lt;br /&gt;
***Dispatcher decides if system call is allowed&lt;br /&gt;
***System call code (write) is invoked&lt;br /&gt;
**CPU switches into supervisor mode using special instructions&lt;br /&gt;
***“software interrupts”&lt;br /&gt;
***“upcall” &amp;amp;rarr; How do I call the kernel&lt;br /&gt;
**The C library has function wrappers around standard system calls.&lt;br /&gt;
**When we say that we are making a ‘system call’ from C, we normally mean that we are making a function call, whose function is a wrapper around the system call we intended to call.&lt;br /&gt;
**Professor enters the following commands:&lt;br /&gt;
***gcc –O2 hello.c –o hello&lt;br /&gt;
***ltrace ./hello&lt;br /&gt;
***ltrace tells you about functions that are called. After this command, we see that ltrace says that there is a puts function.&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***After this command, we can see lots of system calls. We can identify the write system call at the end.&lt;br /&gt;
***gcc –O2 –static hello.c –o hello&lt;br /&gt;
***strace ./hello&lt;br /&gt;
***When linking statically, we can see that we get a lot less system calls.&lt;br /&gt;
*At the function call level, you call code inside your process.&lt;br /&gt;
*At the system call level, you call code outside your process. System calls are more expensive than function calls.&lt;br /&gt;
*We have not seen any assembly of a system call yet.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_2&amp;diff=21748</id>
		<title>Operating Systems 2018F Lecture 2</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_2&amp;diff=21748"/>
		<updated>2018-09-19T17:09:21Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 7, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec02-20180907.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec02/ here].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&#039;&#039;&#039;Where do processes come from?&#039;&#039;&#039;&lt;br /&gt;
* Can be visualized as a tree hierarchy&lt;br /&gt;
* Every process has a parent and a child&lt;br /&gt;
* In windows one process specifies the executable of another&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Orthogonal Design in API&#039;s: Unix Principle&#039;&#039;&#039;&lt;br /&gt;
* Only one way of doing an operation&lt;br /&gt;
* Complex operations are made by simple ones&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Process Duplication&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Cases for making a new process:&lt;br /&gt;
* Run a new program&lt;br /&gt;
* Duplicate an existing process&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Why would you think of duplicating a process?&#039;&#039;&#039;&lt;br /&gt;
* It&#039;s not the same as running a process a second time&lt;br /&gt;
** Variables and state are carried over&lt;br /&gt;
* The duplicate becomes the child and the original is the parent&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Process Duplication and Unix&#039;&#039;&#039;&lt;br /&gt;
* Useful operation for concurrency&lt;br /&gt;
* Simple interface&lt;br /&gt;
* Can be combined with other operations to run programs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Shell&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
*These commands make up an important part of the unix shell:&lt;br /&gt;
**Fork: The action to duplicate a process&lt;br /&gt;
**Execve: Replaces the process running with something else  &lt;br /&gt;
* Most operations you perform are done by forking the current process and execve to run the commands binary&lt;br /&gt;
* If you don&#039;t want to `fork` you can write `exec` in front of your command.&lt;br /&gt;
*The result is your shell morphing into a command. Once your command ends, your terminal will close&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Finding documentation from the shell&#039;&#039;&#039;&lt;br /&gt;
*$ man &#039;name of command here&#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Running LS from another program&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
_Execve is a suicide call_&lt;br /&gt;
*in C:&lt;br /&gt;
**argv and envp are params given to main&lt;br /&gt;
&lt;br /&gt;
 execve(&amp;quot;bin/ls&amp;quot;, argv, evnp);&lt;br /&gt;
 printf(&amp;quot;Hello&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
*printf will not run since program morphs into ls&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*What if we want hello to print?&lt;br /&gt;
**If you just throw `fork()` in you will lose track of which process is the parent and both duplicates will do the same thing&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Fork: The two faced method&#039;&#039;&#039;&lt;br /&gt;
* Based on the return value you can identify the parent process:&lt;br /&gt;
* Fork returns the PID of the child to the parent&lt;br /&gt;
* Fork returns 0 to the child&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*In the following scenario, the main process terminates before `ls` runs resulting in the terminal re printing its prompt before `ls` outputs&lt;br /&gt;
**C code example:&lt;br /&gt;
 PID = fork();&lt;br /&gt;
 &lt;br /&gt;
 if(!PID){&lt;br /&gt;
     execve(&amp;quot;bin/ls&amp;quot;,argv,envp);&lt;br /&gt;
 }&lt;br /&gt;
 else{&lt;br /&gt;
     printf(&amp;quot;done&amp;quot;);&lt;br /&gt;
     return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*In order to avoid this we need to add a `wait()` so that the parent process waits for its child to terminate before it does.&lt;br /&gt;
**Cxample C code:&lt;br /&gt;
&lt;br /&gt;
 PID = fork();&lt;br /&gt;
 if(!PID){&lt;br /&gt;
    execve(&amp;quot;bin/ls&amp;quot;,argv,envp);&lt;br /&gt;
 }&lt;br /&gt;
 else{&lt;br /&gt;
     wait(NULL)&lt;br /&gt;
     printf(&amp;quot;done&amp;quot;);&lt;br /&gt;
     return(0);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What happens to a child process when a parent dies?&#039;&#039;&#039;&lt;br /&gt;
* Another process becomes the parent&lt;br /&gt;
&lt;br /&gt;
*Some process status code examples:&lt;br /&gt;
  S = Sleeping&lt;br /&gt;
  Z = Zombie (A process that died but is still there)&lt;br /&gt;
&lt;br /&gt;
*If nobody waits for a process that dies it becomes a zombie&lt;br /&gt;
**&amp;quot;If you have a kid, wait for it to die&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What is kill?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Clicking X on a window is how we normally invoke the kill command.&lt;br /&gt;
** This triggers a signal which is something used for processes to communicate between each other&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* `$ man 7 signal` is the command that shows the list of signals&lt;br /&gt;
&lt;br /&gt;
examples:&lt;br /&gt;
  `kill -STOP *PID*`&lt;br /&gt;
  `kill -CONT *PID*`&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Some processes can handle signals differently thanks to signal handlers&lt;br /&gt;
&lt;br /&gt;
 `$ kill -9` can avoid signal handlers and kill mercilessly&lt;br /&gt;
&lt;br /&gt;
*The `wait()` method responds to `sigchild` which gets the signal of a child dying&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;About `int main` parameters: &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* char* argv[] is an array of strings&lt;br /&gt;
**Each string comes from input separated by whitespace when entering a command&lt;br /&gt;
&lt;br /&gt;
 argc:&lt;br /&gt;
   Count of how many strings are in argv&lt;br /&gt;
 &lt;br /&gt;
 envp:&lt;br /&gt;
   evironment variables(state) was passed in&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21747</id>
		<title>Operating Systems 2018F Lecture 1</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21747"/>
		<updated>2018-09-19T16:22:11Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 5, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec01-20180905.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec01/ here].&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
===Introduction===&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
*High performance&lt;br /&gt;
*Minimize overhead&lt;br /&gt;
*protection between applications&lt;br /&gt;
*Isolating processes&lt;br /&gt;
*Reliability(runs nonstop)&lt;br /&gt;
*Energy efficient&lt;br /&gt;
*Secure&lt;br /&gt;
*Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21736</id>
		<title>Operating Systems 2018F Lecture 1</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21736"/>
		<updated>2018-09-12T17:59:18Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Lecture-2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 5, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec01-20180905.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec01/ here].&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
===Introduction===&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21735</id>
		<title>Operating Systems 2018F Lecture 1</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21735"/>
		<updated>2018-09-12T17:59:09Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 5, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec01-20180905.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec01/ here].&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
===Introduction===&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;Being revised!&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21734</id>
		<title>Operating Systems 2018F Lecture 1</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F_Lecture_1&amp;diff=21734"/>
		<updated>2018-09-12T17:58:44Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 5, 2018 [https://homeostasis.scs.carleton.ca/~soma/os-2018f/lectures/comp3000-2018f-lec01-20180905.m4a is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Code and files from the lecture (captured as they were at the end) are available [https://homeostasis.scs.carleton.ca/~soma/os-2018f/code/lec01/ here].&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
===Introduction===&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;Being revised!&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21733</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21733"/>
		<updated>2018-09-12T17:58:03Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Course Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21732</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21732"/>
		<updated>2018-09-12T08:01:04Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Lecture-2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 === &lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;Being revised!&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21731</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21731"/>
		<updated>2018-09-12T08:00:43Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Lecture-2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 === &lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;Comming Soon!&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21730</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21730"/>
		<updated>2018-09-12T08:00:10Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Course Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 === &lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21729</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21729"/>
		<updated>2018-09-12T07:58:43Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Course Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
&lt;br /&gt;
=== Lecture-1 ===&lt;br /&gt;
&lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21728</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21728"/>
		<updated>2018-09-12T07:57:36Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Course Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 ===&lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&#039;&#039;&#039;&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21727</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21727"/>
		<updated>2018-09-12T07:55:26Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Course Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
&amp;lt;center&amp;gt;=== Lecture-1 ===&amp;lt;/center&amp;gt;&lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21726</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21726"/>
		<updated>2018-09-12T07:54:56Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* Lecture-1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 ===&lt;br /&gt;
====Introduction====&lt;br /&gt;
&#039;&#039;&#039;why is an operating system important?&#039;&#039;&#039;&lt;br /&gt;
*Only certain programs run on certain operating systems&lt;br /&gt;
*Customization&lt;br /&gt;
*Interface&lt;br /&gt;
We program at different levels of abstraction&lt;br /&gt;
*Abstraction - make system easy to use, divide program into smaller understandable&lt;br /&gt;
pieces&lt;br /&gt;
*most portable - the web&lt;br /&gt;
**works on almost all operating systems&lt;br /&gt;
*the web browser is an operating system (eg: chromebook)&lt;br /&gt;
&#039;&#039;&#039;How do programs run at the same time?&#039;&#039;&#039;&lt;br /&gt;
*Originally, one program used to control the whole system, now for example there are&lt;br /&gt;
around 270 threads running at once on a laptop&lt;br /&gt;
*A program executes instructions → ​ &#039;&#039;&#039;the processor fetches an instruction from&lt;br /&gt;
memory, decodes it and executes it&#039;&#039;&#039;&lt;br /&gt;
*Similar to a political system: Authoritarian dictatorship&lt;br /&gt;
*Virtualizing the CPU: illusion that a single CPU has a large number of smaller virtual&lt;br /&gt;
CPUs.&lt;br /&gt;
*Policy: to determine which program runs first&lt;br /&gt;
&#039;&#039;&#039;Operating systems&#039;&#039;&#039;&lt;br /&gt;
*body of software to determine which programs to run, allow programs to share memory,&lt;br /&gt;
enabling programs to interact with devices&lt;br /&gt;
*the OS takes a physical resource (such as the processor, or memory, or a disk) and&lt;br /&gt;
transforms it into a more general, powerful, and easy-to-use virtual form of itself&lt;br /&gt;
*AKA virtual machine&lt;br /&gt;
*provides some interfaces (APIs) that you can call (system calls that are available to&lt;br /&gt;
applications to run programs, access memory and devices, and other related actions,&lt;br /&gt;
aka standard library)&lt;br /&gt;
*Resource manager - give programs resources based on priorities&lt;br /&gt;
&#039;&#039;&#039;Goals:&#039;&#039;&#039;&lt;br /&gt;
**High performance&lt;br /&gt;
**Minimize overhead&lt;br /&gt;
**protection between applications&lt;br /&gt;
**Isolating processes&lt;br /&gt;
**Reliability(runs nonstop)&lt;br /&gt;
**Energy efficient&lt;br /&gt;
**Secure&lt;br /&gt;
**Mobility&lt;br /&gt;
Unix&lt;br /&gt;
*Has variants - linux, minux&lt;br /&gt;
*Programmed in C&lt;br /&gt;
Windows&lt;br /&gt;
*VMS&lt;br /&gt;
*Microsoft bought a team to build an operating system&lt;br /&gt;
====Hello World - Sample Program====&lt;br /&gt;
C programs start with &#039;&#039;&#039;main function&#039;&#039;&#039;&lt;br /&gt;
[[File:Lec1-1.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
Compile and Run:&lt;br /&gt;
[[File:Lec1-2.png|none|800px]]&lt;br /&gt;
Two different ways to compile:&lt;br /&gt;
*One does more work and it is smaller&lt;br /&gt;
*One does less work and it is larger&lt;br /&gt;
[[File:lec1-3.png|none|800px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;How many lines of code are running in a system?&#039;&#039;&#039;&lt;br /&gt;
* 100 million lines of code!&lt;br /&gt;
&#039;&#039;&#039;Questions to ask:&#039;&#039;&#039;&lt;br /&gt;
#Who calls main?&lt;br /&gt;
#Where do the arguments come from?&lt;br /&gt;
#Who&#039;s taking the return value?&lt;br /&gt;
#Who defines headers? Where do they come from?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Mental Model&#039;&#039;&#039;&lt;br /&gt;
*Don’t need to know exactly what happens&lt;br /&gt;
*Know the strategy to figure it out&lt;br /&gt;
*Know when to ask the questions&lt;br /&gt;
*Know when it matters&lt;br /&gt;
*OS → the code that runs under the application&lt;br /&gt;
&#039;&#039;&#039;Who is in charge?&#039;&#039;&#039;&lt;br /&gt;
*the​ &#039;&#039;&#039;first program&#039;&#039;&#039;​ that runs on the system is in charge&lt;br /&gt;
**may delegate its powers to others&lt;br /&gt;
*make sure it only obeys your commands (self preservation)&lt;br /&gt;
**eg: if you get a command from someone else, ask me first&lt;br /&gt;
**add a level of abstraction: authorization&lt;br /&gt;
**downside: labour intensive (time consuming to approve every command)&lt;br /&gt;
*create rules to determine when authorization is needed&lt;br /&gt;
**when does the OS need to get involved&lt;br /&gt;
**this is costly, so leave instructions behind so that is can make decisions&lt;br /&gt;
**&#039;&#039;&#039;take charge of dangerous operations&#039;&#039;&#039;&lt;br /&gt;
&#039;&#039;&#039;Cpu modes:&#039;&#039;&#039;&lt;br /&gt;
*&#039;&#039;&#039;Supervisor mode&#039;&#039;&#039;: access to all hardware resources&lt;br /&gt;
*&#039;&#039;&#039;User mode&#039;&#039;&#039;: access to limited resources, as defined by code running in supervisor mode&lt;br /&gt;
&#039;&#039;&#039;Definitions:&#039;&#039;&#039;&lt;br /&gt;
*Kernel: code that runs in supervisor mode (If your code runs in supervisor mode, you are&lt;br /&gt;
in the kernel.)&lt;br /&gt;
*Process: “running program” (Processes run in user mode)&lt;br /&gt;
*System call: process making a request of the kernel (costly)&lt;br /&gt;
*portable: able to work on different operating systems, a program that can run in many&lt;br /&gt;
different environments.&lt;br /&gt;
&#039;&#039;&#039;APIs&#039;&#039;&#039;&lt;br /&gt;
*an application programming interface (API) is a set of subroutine definitions,&lt;br /&gt;
communication protocols, and tools for building software&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Memory&#039;&#039;&#039;&lt;br /&gt;
*read - address to access data stored there&lt;br /&gt;
*write - address and data to be stored there&lt;br /&gt;
*virtualizing memory - each process accesses its own private virtual address space&lt;br /&gt;
**The OS maps this memory to the physical memory on the machine&lt;br /&gt;
&#039;&#039;&#039;Concurrency&#039;&#039;&#039;&lt;br /&gt;
*working on many things at once in the same program&lt;br /&gt;
*multi-threaded programs&lt;br /&gt;
**thread: a function running within the same memory space as other functions&lt;br /&gt;
*race conditions&lt;br /&gt;
&#039;&#039;&#039;Presistence&#039;&#039;&#039;&lt;br /&gt;
*how do we not lose data&lt;br /&gt;
*volatile - when the system crashes, the data in this memory is lost (DRAM)&lt;br /&gt;
*hard drive - long term store&lt;br /&gt;
*solid state drive - alternative for hard drive&lt;br /&gt;
*file system - manages disk storage&lt;br /&gt;
*handling system crashes&lt;br /&gt;
**journaling or copy-on-write&lt;br /&gt;
&amp;lt;center&amp;gt;&#039;&#039;&#039;END OF LECTURE 1&amp;lt;/center&amp;gt;&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-3.png&amp;diff=21725</id>
		<title>File:Lec1-3.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-3.png&amp;diff=21725"/>
		<updated>2018-09-12T07:20:06Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-2.png&amp;diff=21724</id>
		<title>File:Lec1-2.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-2.png&amp;diff=21724"/>
		<updated>2018-09-12T07:19:55Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-1.png&amp;diff=21723</id>
		<title>File:Lec1-1.png</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=File:Lec1-1.png&amp;diff=21723"/>
		<updated>2018-09-12T07:19:33Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21722</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21722"/>
		<updated>2018-09-12T01:14:53Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 ===&lt;br /&gt;
----&lt;br /&gt;
=== Lecture-2===&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21721</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21721"/>
		<updated>2018-09-12T01:14:18Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;br /&gt;
== Course Notes ==&lt;br /&gt;
=== Lecture-1 ===&lt;br /&gt;
----&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21715</id>
		<title>Notetaking for Operating Systems (Fall 2018)</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Notetaking_for_Operating_Systems_(Fall_2018)&amp;diff=21715"/>
		<updated>2018-09-10T00:24:28Z</updated>

		<summary type="html">&lt;p&gt;R.samanfar: /* How to contribute */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Extra credit is available for students who contribute lecture notes to the class wiki. You can earn up to an additive 4% bonus to your final grade by contributing notes and improving existing notes.&lt;br /&gt;
&lt;br /&gt;
==How to contribute==&lt;br /&gt;
&lt;br /&gt;
Contact Reza (RezaSamanfar at cmail.carleton.ca) and sign up for a day you&#039;d like to take notes for.  Normally only one student can sign up for a day.  Sign ups are first come, first serve; however, priority will be given to students who previously have not taken notes.&lt;br /&gt;
&lt;br /&gt;
After the lecture, email your notes to Reza with the subject formatted like &amp;quot;COMP3000-lecture1&amp;quot; (preferably mediawiki formatted).  He may request changes from you.  Once the notes are in an acceptable format, they will be posted to the class wiki.&lt;br /&gt;
&lt;br /&gt;
==What to contribute==&lt;br /&gt;
* Bullet point summaries of topics covered in class&lt;br /&gt;
* Code samples from class plus comments or extra explanation&lt;br /&gt;
* Time marks to important points in lecture audio/videos&lt;br /&gt;
* Links to reliable supplementary information (e.g. page numbers in &#039;&#039;Operating Systems: Three Easy Pieces&#039;&#039;)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: read up on how Mediawiki formatting works before editing, and use the &#039;&#039;Show Preview&#039;&#039; button before saving your edits.&lt;br /&gt;
&lt;br /&gt;
==How do I get my bonus marks?==&lt;br /&gt;
&lt;br /&gt;
If you make significant contributions that do not need to be edited or improved, you will get roughly 1% per lecture. Large contributions that need some small edits will get you somewhere between 0.5% and 1% bonus. Good smaller edits and contributions will get you around 0.5%. Things like fixing typos and formatting are appreciated but are not worth any extra marks. Bonus marks are granted at Reza&#039;s discretion and will show up in CuLearn.&lt;br /&gt;
&lt;br /&gt;
If you&#039;re not sure if something is appropriate to be added to the wiki, or you have a question about the bonus marks, ask Reza.&lt;/div&gt;</summary>
		<author><name>R.samanfar</name></author>
	</entry>
</feed>