<?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=Jean</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=Jean"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Jean"/>
	<updated>2026-05-12T21:32:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F:_Assignment_2&amp;diff=21133</id>
		<title>Operating Systems 2017F: Assignment 2</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F:_Assignment_2&amp;diff=21133"/>
		<updated>2017-10-18T02:44:10Z</updated>

		<summary type="html">&lt;p&gt;Jean: /* Questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This assignment is not yet finalized.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Please submit the answers to the following questions via CULearn by 11:55 PM on Thursday, October 26, 2017. There are ?? points in ?? questions.&lt;br /&gt;
&lt;br /&gt;
Submit your answers as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-assign2.txt&amp;quot; (where username is your MyCarletonOne username). The first four lines of this file should be &amp;quot;COMP 3000 Assignment 2&amp;quot;, your name, student number, and the date of submission. You may wish to format your answers in Markdown to improve their appearance.&lt;br /&gt;
&lt;br /&gt;
No other formats will be accepted. Submitting in another format will likely result in your assignment not being graded and you receiving no marks for this assignment. In particular do not submit an MS Word or OpenOffice file as your answers document!&lt;br /&gt;
&lt;br /&gt;
Don&#039;t forget to include what outside resources you used to complete each of your answers, including other students, man pages, and web resources. You do not need to list help from the instructor, TA, or information found in the textbook.&lt;br /&gt;
&lt;br /&gt;
==Questions==&lt;br /&gt;
&lt;br /&gt;
# [2] How could you modify 3000test.c so it can report on whether two device files are equal without actually accessing the underlying devices?  Specify the changes you would make to 3000test.c rather than doing this from scratch.&lt;br /&gt;
# [2] Does the MAP_SHARED flag on line 60 of 3000test.c (inside the call to mmap) make a significant difference in its execution?  Specifically, what happens when you remove it or changed it to MAP_PRIVATE?  Why?&lt;br /&gt;
# [1] Why does a different version of stat(), lstat(), exist that treats symbolic links differently?  Why isn&#039;t a different version needed for hard links?&lt;/div&gt;</summary>
		<author><name>Jean</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F:_Tutorial_4&amp;diff=21124</id>
		<title>Operating Systems 2017F: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F:_Tutorial_4&amp;diff=21124"/>
		<updated>2017-10-15T22:02:09Z</updated>

		<summary type="html">&lt;p&gt;Jean: /* 3000random.c */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This tutorial is not yet finalized.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will be experimenting with and extending [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut4/3000pc.c 3000pc.c] and [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut4/3000random.c 3000random.c] (both listed below).&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
&lt;br /&gt;
# Compile and run 3000pc.c.  Note that you&#039;ll need to add a &amp;quot;-pthread&amp;quot; option to your compile command.  First run it with a -1 for both delay intervals, then try other values.  When does the producer signal the consumer?  When does the consumer signal the producer?&lt;br /&gt;
# How can you output the random words to a file so that you only see the signal messages on the console?&lt;br /&gt;
# Modify the producer so that it never unlocks each entry (but does lock it).  What happens?&lt;br /&gt;
# Modify the consumer so that it never unlocks each entry (but does lock it).  What happens?&lt;br /&gt;
# What happens if you remove all entry locking/unlocking?  How does the behavior change?&lt;br /&gt;
# Remove the SIGUSR1 signal handler from the producer (so it uses the C library default signal handler).  How does the program behave?&lt;br /&gt;
# Remove the SIGUSR1 signal handler from the consumer (so it uses the C library default signal handler).  How does the program behave?&lt;br /&gt;
# Change the producer and consumer so they only sleep for 1000 nanoseconds (1 millisecond) rather than 1 second during each delay interval.  How does the behavior of the program change?&lt;br /&gt;
# Compile and run 3000random.c.  Note that it takes two arguments.  Where does this program get its random numbers from?&lt;br /&gt;
# Change 3000random.c to use /dev/random rather than /dev/urandom.  How does its performance change, especially when generating a large number of random numbers?&lt;br /&gt;
# Change 3000pc.c to use random numbers from /dev/urandom rather than using the standard library function random().  How does this change affect the relative speed of the producer and consumer processes?&lt;br /&gt;
# &#039;&#039;&#039;(Bonus)&#039;&#039;&#039; Modify 3000pc.c so it takes in an additional command line argument that is the filename of a word list.  This file should have one word per line.  The program should then use this read-in word list rather than the hard coded word list.  Pay attention to:&lt;br /&gt;
#* where you read the file (in the producer, consumer, or before the fork)&lt;br /&gt;
#* where and how you store the words in memory (the word list should be arbitrarily long, but the maximum length of a word can be fixed)&lt;br /&gt;
# &#039;&#039;&#039;(Bonus)&#039;&#039;&#039; Modify 3000pc.c so that it has multiple producers and consumers running concurrently, with the number of each specified on the command line.&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===3000pc.c===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
/* 3000pc.c */&lt;br /&gt;
/* producer-consumer example using signals, processes and mmap */&lt;br /&gt;
/* v1 Oct. 15, 2017 */&lt;br /&gt;
/* Licenced under the GPLv3, copyright Anil Somayaji */&lt;br /&gt;
/* You really shouldn&#039;t be incorporating parts of this in any other code,&lt;br /&gt;
   it is meant for teaching, not production */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/mman.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.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/wait.h&amp;gt;&lt;br /&gt;
#include &amp;lt;semaphore.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;time.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define QUEUESIZE 32&lt;br /&gt;
#define WORDSIZE 16&lt;br /&gt;
&lt;br /&gt;
const int wordlist_size = 27;&lt;br /&gt;
const char *wordlist[] = {&lt;br /&gt;
        &amp;quot;Alpha&amp;quot;,&lt;br /&gt;
        &amp;quot;Bravo&amp;quot;,&lt;br /&gt;
        &amp;quot;Charlie&amp;quot;,&lt;br /&gt;
        &amp;quot;Delta&amp;quot;,&lt;br /&gt;
        &amp;quot;Echo&amp;quot;,&lt;br /&gt;
        &amp;quot;Foxtrot&amp;quot;,&lt;br /&gt;
        &amp;quot;Golf&amp;quot;,&lt;br /&gt;
        &amp;quot;Hotel&amp;quot;,&lt;br /&gt;
        &amp;quot;India&amp;quot;,&lt;br /&gt;
        &amp;quot;Juliet&amp;quot;,&lt;br /&gt;
        &amp;quot;Kilo&amp;quot;,&lt;br /&gt;
        &amp;quot;Lima&amp;quot;,&lt;br /&gt;
        &amp;quot;Mike&amp;quot;,&lt;br /&gt;
        &amp;quot;November&amp;quot;,&lt;br /&gt;
        &amp;quot;Oscar&amp;quot;,&lt;br /&gt;
        &amp;quot;Papa&amp;quot;,&lt;br /&gt;
        &amp;quot;Quebec&amp;quot;,&lt;br /&gt;
        &amp;quot;Romeo&amp;quot;,&lt;br /&gt;
        &amp;quot;Sierra&amp;quot;,&lt;br /&gt;
        &amp;quot;Tango&amp;quot;,&lt;br /&gt;
        &amp;quot;Uniform&amp;quot;,&lt;br /&gt;
        &amp;quot;Victor&amp;quot;,&lt;br /&gt;
        &amp;quot;Whiskey&amp;quot;,&lt;br /&gt;
        &amp;quot;X-ray&amp;quot;,&lt;br /&gt;
        &amp;quot;Yankee&amp;quot;,&lt;br /&gt;
        &amp;quot;Zulu&amp;quot;,&lt;br /&gt;
        &amp;quot;Dash&amp;quot;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
typedef struct entry {&lt;br /&gt;
        char word[WORDSIZE];&lt;br /&gt;
        sem_t lock;&lt;br /&gt;
} entry;&lt;br /&gt;
&lt;br /&gt;
typedef struct shared {&lt;br /&gt;
        int prod_waiting;&lt;br /&gt;
        int con_waiting;&lt;br /&gt;
        entry queue[QUEUESIZE];&lt;br /&gt;
        int last_produced;&lt;br /&gt;
        int last_consumed;&lt;br /&gt;
        pid_t prod_pid;&lt;br /&gt;
        pid_t con_pid;&lt;br /&gt;
        int prod_count;&lt;br /&gt;
        int con_count;&lt;br /&gt;
} shared;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void report_error(char *error)&lt;br /&gt;
{&lt;br /&gt;
        fprintf(stderr, &amp;quot;Error: %s\n&amp;quot;, error);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void usage_exit(char *progname)&lt;br /&gt;
{&lt;br /&gt;
        fprintf(stderr,&lt;br /&gt;
                &amp;quot;Usage: %s &amp;lt;event count&amp;gt; &amp;lt;prod delay int&amp;gt; &amp;lt;con delay int&amp;gt;\n&amp;quot;,&lt;br /&gt;
                progname);&lt;br /&gt;
        exit(-1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void producer_handler(int the_signal)&lt;br /&gt;
{&lt;br /&gt;
        if (the_signal == SIGUSR1) {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Producer received SIGUSR1.\n&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
&lt;br /&gt;
        } else {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Producer: No handler for for signal %d?!\n&amp;quot;,&lt;br /&gt;
                        the_signal);&lt;br /&gt;
                return;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void consumer_handler(int the_signal)&lt;br /&gt;
{&lt;br /&gt;
        if (the_signal == SIGUSR1) {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Consumer received SIGUSR1.\n&amp;quot;);&lt;br /&gt;
                return;&lt;br /&gt;
        } else {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Consumer: No handler for for signal %d?!\n&amp;quot;,&lt;br /&gt;
                        the_signal);&lt;br /&gt;
                return;&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void pick_word(char *word)&lt;br /&gt;
{&lt;br /&gt;
        int pick;&lt;br /&gt;
&lt;br /&gt;
        pick = random() % wordlist_size;&lt;br /&gt;
&lt;br /&gt;
        strcpy(word, wordlist[pick]);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void wait_for_producer(shared *s)&lt;br /&gt;
{&lt;br /&gt;
        struct timespec delay;&lt;br /&gt;
        &lt;br /&gt;
        delay.tv_sec = 100;&lt;br /&gt;
        delay.tv_nsec = 0;&lt;br /&gt;
&lt;br /&gt;
        s-&amp;gt;con_waiting = 1;&lt;br /&gt;
        &lt;br /&gt;
        while (s-&amp;gt;con_waiting) {&lt;br /&gt;
                nanosleep(&amp;amp;delay, NULL);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void wait_for_consumer(shared *s)&lt;br /&gt;
{&lt;br /&gt;
        struct timespec delay;&lt;br /&gt;
        &lt;br /&gt;
        delay.tv_sec = 100;&lt;br /&gt;
        delay.tv_nsec = 0;&lt;br /&gt;
&lt;br /&gt;
        s-&amp;gt;prod_waiting = 1;&lt;br /&gt;
        &lt;br /&gt;
        while (s-&amp;gt;prod_waiting) {&lt;br /&gt;
                nanosleep(&amp;amp;delay, NULL);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void wakeup_consumer(shared *s)&lt;br /&gt;
{&lt;br /&gt;
        if (s-&amp;gt;con_waiting) {&lt;br /&gt;
                s-&amp;gt;con_waiting = 0;&lt;br /&gt;
                kill(s-&amp;gt;con_pid, SIGUSR1);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void wakeup_producer(shared *s)&lt;br /&gt;
{&lt;br /&gt;
        if (s-&amp;gt;prod_waiting) {&lt;br /&gt;
                s-&amp;gt;prod_waiting = 0;&lt;br /&gt;
                kill(s-&amp;gt;prod_pid, SIGUSR1);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void output_word(int c, char *w)&lt;br /&gt;
{&lt;br /&gt;
        printf(&amp;quot;Word %d: %s\n&amp;quot;, c, w);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int queue_word(char *word, shared *s)&lt;br /&gt;
{&lt;br /&gt;
        entry *e;&lt;br /&gt;
        int current, retval;&lt;br /&gt;
        &lt;br /&gt;
        current = (s-&amp;gt;last_produced + 1) % QUEUESIZE;&lt;br /&gt;
&lt;br /&gt;
        e = &amp;amp;s-&amp;gt;queue[current];&lt;br /&gt;
&lt;br /&gt;
        sem_wait(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
&lt;br /&gt;
        if (e-&amp;gt;word[0] != &#039;\0&#039;) {&lt;br /&gt;
                /* consumer hasn&#039;t consumed this entry yet */&lt;br /&gt;
                sem_post(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
                wait_for_consumer(s);&lt;br /&gt;
                sem_wait(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (e-&amp;gt;word[0] != &#039;\0&#039;) {&lt;br /&gt;
                fprintf(stderr, &amp;quot;ERROR: No room for producer after waiting!\n&amp;quot;);&lt;br /&gt;
                retval = -1;&lt;br /&gt;
                goto done;&lt;br /&gt;
        } else {&lt;br /&gt;
                strncpy(e-&amp;gt;word, word, WORDSIZE);&lt;br /&gt;
                s-&amp;gt;last_produced = current;&lt;br /&gt;
                s-&amp;gt;prod_count++;&lt;br /&gt;
                wakeup_consumer(s);&lt;br /&gt;
                retval = 0;&lt;br /&gt;
                goto done;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
 done:&lt;br /&gt;
        sem_post(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
        return retval;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int get_next_word(char *word, shared *s)&lt;br /&gt;
{&lt;br /&gt;
        entry *e;&lt;br /&gt;
        int current, retval;&lt;br /&gt;
&lt;br /&gt;
        current = (s-&amp;gt;last_consumed + 1) % QUEUESIZE;&lt;br /&gt;
&lt;br /&gt;
        e = &amp;amp;s-&amp;gt;queue[current];&lt;br /&gt;
        &lt;br /&gt;
        sem_wait(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
&lt;br /&gt;
        if (e-&amp;gt;word[0] == &#039;\0&#039;) {&lt;br /&gt;
                /* producer hasn&#039;t filled in this entry yet */&lt;br /&gt;
                sem_post(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
                wait_for_producer(s);&lt;br /&gt;
                sem_wait(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (e-&amp;gt;word[0] == &#039;\0&#039;) {&lt;br /&gt;
                fprintf(stderr, &amp;quot;ERROR: Nothing for consumer after waiting!\n&amp;quot;);&lt;br /&gt;
                retval = -1;&lt;br /&gt;
                goto done;&lt;br /&gt;
        } else {&lt;br /&gt;
                strncpy(word, e-&amp;gt;word, WORDSIZE);&lt;br /&gt;
                e-&amp;gt;word[0] = &#039;\0&#039;;&lt;br /&gt;
                s-&amp;gt;last_consumed = current;&lt;br /&gt;
                s-&amp;gt;con_count++;&lt;br /&gt;
                wakeup_producer(s);&lt;br /&gt;
                retval = 0;&lt;br /&gt;
                goto done;&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
 done:&lt;br /&gt;
        sem_post(&amp;amp;e-&amp;gt;lock);&lt;br /&gt;
        return retval;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void producer(shared *s, int event_count, int producer_delay_interval)&lt;br /&gt;
{&lt;br /&gt;
        char word[WORDSIZE];&lt;br /&gt;
        int i;&lt;br /&gt;
        struct sigaction signal_handler_struct;&lt;br /&gt;
 &lt;br /&gt;
        memset (&amp;amp;signal_handler_struct, 0, sizeof(signal_handler_struct));&lt;br /&gt;
        signal_handler_struct.sa_handler = producer_handler;&lt;br /&gt;
&lt;br /&gt;
        if (sigaction(SIGUSR1, &amp;amp;signal_handler_struct, NULL)) {&lt;br /&gt;
            fprintf(stderr, &amp;quot;Producer couldn&#039;t register SIGUSR1 handler.\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        for (i=0; i &amp;lt; event_count; i++) {        &lt;br /&gt;
                pick_word(word);&lt;br /&gt;
                queue_word(word, s);&lt;br /&gt;
                if (producer_delay_interval &amp;gt; 0) {&lt;br /&gt;
                        if (i % producer_delay_interval == 0) {&lt;br /&gt;
                                sleep(1);&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Producer finished.\n&amp;quot;);&lt;br /&gt;
        exit(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void consumer(shared *s, int event_count, int consumer_delay_interval)&lt;br /&gt;
{&lt;br /&gt;
        char word[WORDSIZE];&lt;br /&gt;
        int i;&lt;br /&gt;
        struct sigaction signal_handler_struct;&lt;br /&gt;
 &lt;br /&gt;
        memset (&amp;amp;signal_handler_struct, 0, sizeof(signal_handler_struct));&lt;br /&gt;
        signal_handler_struct.sa_handler = consumer_handler;&lt;br /&gt;
&lt;br /&gt;
        if (sigaction(SIGUSR1, &amp;amp;signal_handler_struct, NULL)) {&lt;br /&gt;
            fprintf(stderr, &amp;quot;Consumer couldn&#039;t register SIGUSR1 handler.\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        for (i=0; i &amp;lt; event_count; i++) {        &lt;br /&gt;
                get_next_word(word, s);&lt;br /&gt;
                output_word(s-&amp;gt;con_count, word);&lt;br /&gt;
                if (consumer_delay_interval &amp;gt; 0) {&lt;br /&gt;
                        if (i % consumer_delay_interval == 0) {&lt;br /&gt;
                                sleep(1);&lt;br /&gt;
                        }&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Consumer finished.\n&amp;quot;);&lt;br /&gt;
        exit(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void init_shared(shared *s)&lt;br /&gt;
{&lt;br /&gt;
        int i;&lt;br /&gt;
        &lt;br /&gt;
        s-&amp;gt;con_waiting = 0;&lt;br /&gt;
        s-&amp;gt;last_consumed = -1;&lt;br /&gt;
&lt;br /&gt;
        s-&amp;gt;prod_waiting = 0;&lt;br /&gt;
        s-&amp;gt;last_produced = -1;&lt;br /&gt;
        &lt;br /&gt;
        s-&amp;gt;prod_pid = -1;&lt;br /&gt;
        s-&amp;gt;con_pid = -1;&lt;br /&gt;
&lt;br /&gt;
        s-&amp;gt;prod_count = 0;&lt;br /&gt;
        s-&amp;gt;con_count = 0;&lt;br /&gt;
                &lt;br /&gt;
        for (i=0; i&amp;lt;QUEUESIZE; i++) {&lt;br /&gt;
                s-&amp;gt;queue[i].word[0] = &#039;\0&#039;;&lt;br /&gt;
                /* semaphore is shared between processes,&lt;br /&gt;
                   and initial value is 1 (unlocked) */&lt;br /&gt;
                sem_init(&amp;amp;s-&amp;gt;queue[i].lock, 1, 1); &lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
        int pid, count, prod_interval, con_interval;&lt;br /&gt;
        &lt;br /&gt;
        shared *s;&lt;br /&gt;
&lt;br /&gt;
        srandom(42);&lt;br /&gt;
        &lt;br /&gt;
        if (argc &amp;lt; 4) {&lt;br /&gt;
                if (argc &amp;lt; 1) {&lt;br /&gt;
                        report_error(&amp;quot;no command line&amp;quot;);&lt;br /&gt;
                        usage_exit(argv[0]);&lt;br /&gt;
                } else {&lt;br /&gt;
                        report_error(&amp;quot;Not enough arguments&amp;quot;);&lt;br /&gt;
                        usage_exit(argv[0]);&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        count = atoi(argv[1]);&lt;br /&gt;
        prod_interval = atoi(argv[2]);&lt;br /&gt;
        con_interval = atoi(argv[3]);&lt;br /&gt;
&lt;br /&gt;
        s = (shared *) mmap(NULL, sizeof(shared),&lt;br /&gt;
                             PROT_READ|PROT_WRITE,&lt;br /&gt;
                             MAP_SHARED|MAP_ANONYMOUS, -1, 0);&lt;br /&gt;
        &lt;br /&gt;
        if (s == MAP_FAILED) {&lt;br /&gt;
                report_error(strerror(errno));&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        init_shared(s);&lt;br /&gt;
        &lt;br /&gt;
        pid = fork();&lt;br /&gt;
&lt;br /&gt;
        if (pid) {&lt;br /&gt;
                /* producer */&lt;br /&gt;
                s-&amp;gt;prod_pid = getpid();&lt;br /&gt;
                producer(s, count, prod_interval);&lt;br /&gt;
        } else {&lt;br /&gt;
                /* consumer */&lt;br /&gt;
                s-&amp;gt;con_pid = getpid();&lt;br /&gt;
                consumer(s, count, con_interval);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        /* This line should never be reached */&lt;br /&gt;
        return -1;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===3000random.c===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
/* 3000random.c */&lt;br /&gt;
/* prints out random numbers obtained from system /dev/urandom */&lt;br /&gt;
/* (This is much, much better than using rand() or random())! */&lt;br /&gt;
/* v1 Oct. 15, 2017 */&lt;br /&gt;
/* Licenced under the GPLv3, copyright Anil Somayaji */&lt;br /&gt;
/* You really shouldn&#039;t be incorporating parts of this in any other code,&lt;br /&gt;
   it is meant for teaching, not production */&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BUFSIZE 1024&lt;br /&gt;
&lt;br /&gt;
typedef struct rand_state {&lt;br /&gt;
        unsigned long buffer[BUFSIZE];&lt;br /&gt;
        int current;&lt;br /&gt;
        int fd;&lt;br /&gt;
} rand_state;&lt;br /&gt;
&lt;br /&gt;
void fill_rand_buffer(rand_state *r)&lt;br /&gt;
{&lt;br /&gt;
        ssize_t count;&lt;br /&gt;
&lt;br /&gt;
        count = read(r-&amp;gt;fd, (void *) &amp;amp;r-&amp;gt;buffer,&lt;br /&gt;
                     BUFSIZE * sizeof(unsigned long));&lt;br /&gt;
&lt;br /&gt;
        if (count &amp;gt; sizeof(unsigned long)) {&lt;br /&gt;
                r-&amp;gt;current = count % sizeof(unsigned long);&lt;br /&gt;
        } else {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Couldn&#039;t fill random buffer.\n&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void system_rand_init(rand_state *r)&lt;br /&gt;
{&lt;br /&gt;
        r-&amp;gt;fd = open(&amp;quot;/dev/urandom&amp;quot;, O_RDONLY);&lt;br /&gt;
&lt;br /&gt;
        fill_rand_buffer(r);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
long system_rand(long max, rand_state *r)&lt;br /&gt;
{        &lt;br /&gt;
        unsigned long val;&lt;br /&gt;
&lt;br /&gt;
        if (r-&amp;gt;current &amp;lt; 0) {&lt;br /&gt;
                fill_rand_buffer(r);                &lt;br /&gt;
                if (r-&amp;gt;current &amp;lt; 0) {&lt;br /&gt;
                        /* fill_rand_buffer should have already&lt;br /&gt;
                           reported an error */&lt;br /&gt;
                        return 0;&lt;br /&gt;
                }&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        val = r-&amp;gt;buffer[r-&amp;gt;current];&lt;br /&gt;
        r-&amp;gt;current--;&lt;br /&gt;
        return val % max;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
        int count, i;&lt;br /&gt;
        long max, x;&lt;br /&gt;
        rand_state r;&lt;br /&gt;
&lt;br /&gt;
        if (argc != 3) {&lt;br /&gt;
                fprintf(stderr, &amp;quot;Usage: %s &amp;lt;count&amp;gt; &amp;lt;max&amp;gt;\n&amp;quot;, argv[0]);&lt;br /&gt;
                exit(-1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        count = atoi(argv[1]);&lt;br /&gt;
        max = atol(argv[2]);&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;count = %d, max = %ld\n&amp;quot;, count, max);&lt;br /&gt;
        &lt;br /&gt;
        system_rand_init(&amp;amp;r);&lt;br /&gt;
        &lt;br /&gt;
        for (i = 0; i &amp;lt; count; i++) {&lt;br /&gt;
                x = system_rand(max, &amp;amp;r);&lt;br /&gt;
                printf(&amp;quot;%ld\n&amp;quot;, x);&lt;br /&gt;
        }&lt;br /&gt;
        &lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jean</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_(Fall_2017)_Course_Outline&amp;diff=21008</id>
		<title>Operating Systems (Fall 2017) Course Outline</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_(Fall_2017)_Course_Outline&amp;diff=21008"/>
		<updated>2017-09-18T14:46:22Z</updated>

		<summary type="html">&lt;p&gt;Jean: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Course Information==&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Course Number:&#039;&#039;&#039; COMP 3000&lt;br /&gt;
*&#039;&#039;&#039;Term:&#039;&#039;&#039; Fall 2017&lt;br /&gt;
*&#039;&#039;&#039;Title:&#039;&#039;&#039; Operating Systems&lt;br /&gt;
*&#039;&#039;&#039;Institution:&#039;&#039;&#039; Carleton University, School of Computer Science&lt;br /&gt;
*&#039;&#039;&#039;Instructor:&#039;&#039;&#039; [http://people.scs.carleton.ca/~soma Anil Somayaji] (anil.somayaji at carleton.ca): Mon., Wed. 2:30-3:30 PM in HP 5137&lt;br /&gt;
*&#039;&#039;&#039;Teaching Assistants:&#039;&#039;&#039; (office hours in TBD)&amp;lt;br&amp;gt;Jean-Elie Jean-Gilles (jeaneliejeangilles at cmail.carleton.ca): Tuesday and Thursday 2:30-3:30 PM&amp;lt;br&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Lectures:&#039;&#039;&#039; Tues. and Thurs. 1:05-2:25 PM in AT 102&lt;br /&gt;
*&#039;&#039;&#039;Tutorials (in HP 4155):&#039;&#039;&#039;&amp;lt;br&amp;gt;Monday 11:35-12:55 PM&amp;lt;br&amp;gt;Monday 1:05-2:25 PM&amp;lt;br&amp;gt;Wednesday 8:35-9:55 AM&lt;br /&gt;
*&#039;&#039;&#039;Course Website&#039;&#039;&#039;: http://homeostasis.scs.carleton.ca/wiki/index.php/Operating_Systems_%28Fall_2017%29&lt;br /&gt;
&lt;br /&gt;
==Official Course Description==&lt;br /&gt;
&lt;br /&gt;
Operating system implementation course stressing fundamental issues in design and how they relate to modern computer architectures. Assignments involve the modification and extension of a multitasking operating system.&lt;br /&gt;
&lt;br /&gt;
==Learning Outcomes==&lt;br /&gt;
&lt;br /&gt;
By the end of this course, students should:&lt;br /&gt;
* be able to write C code that uses low-level Linux services and should be able to implement simple Linux kernel extensions (modules),&lt;br /&gt;
* have a strong conceptual model of how an operating system works that allows them to determine the relative role of application and operating system code when debugging software, and&lt;br /&gt;
* understand the basic use and architecture of virtual-machine based cloud architectures.&lt;br /&gt;
&lt;br /&gt;
Note that in order to achieve these objectives students should have come into this course with a strong background in C programming and general application development.&lt;br /&gt;
&lt;br /&gt;
==Grading==&lt;br /&gt;
&lt;br /&gt;
The marking scheme for this course is:&lt;br /&gt;
&lt;br /&gt;
* 20% for tutorial participation&lt;br /&gt;
* 20% for the assignments&lt;br /&gt;
* 25% for the midterm on November 2 (Thursday) during class&lt;br /&gt;
* 35% for the final exam (date TBA)&lt;br /&gt;
&lt;br /&gt;
I also calculate grades using alternative marking schemes at the end of the semester, assigning the highest grade for each student from any of the marking schemes.  Thus your final grade may be higher than might be suggested by strict following of the above scheme.&lt;br /&gt;
&lt;br /&gt;
==Communication==&lt;br /&gt;
&lt;br /&gt;
This wiki page is the canonical source of information on this course.  Please refer to it for updates.  When significant changes are made to this document it will be either announced in lecture and/or posted in the course discussion forum.&lt;br /&gt;
&lt;br /&gt;
Course discussions will be on [https://culearn.carleton.ca cuLearn].  While you may discuss assignments there, do not post outright answers to them.  You may post in either the Questions and Answers forum or the General Discussion forum.&lt;br /&gt;
&lt;br /&gt;
You may get an account on class wiki so you can edit content there.  Email Prof. Somayaji to get one with your preferred username and email address to which a password should be sent.  (Note this is not a requirement.)&lt;br /&gt;
&lt;br /&gt;
==Collaboration==&lt;br /&gt;
&lt;br /&gt;
Collaboration on all work is allowed except for the two tests. Collaboration, however, should be clearly acknowledged.&lt;br /&gt;
&lt;br /&gt;
For assignments, while you may get help from others and even collaboratively solve technical problems, the code and answers submitted should all be your own work.  For example, you may not divide an assignment into parts, give a part to another student or anyone else to solve, and then submit that work as your own.  You have to have participated in the creation of every part of your submitted work.  An easy way to make sure this happens is never share files regarding coursework or copy and paste answers into email.  Instead, meet together to work on an assignment and then separate to write up your solutions.&lt;br /&gt;
&lt;br /&gt;
The final project may be a group project, but again there it should be clearly documented what contribution was made by each group member.&lt;br /&gt;
&lt;br /&gt;
Similarity between submitted assignments and projects that has not been appropriately documented will be treated as plagiarism - the same as copying on a midterm or a final - and will be submitted to the Dean for disciplinary action.&lt;br /&gt;
&lt;br /&gt;
==Course Notes/Multimedia==&lt;br /&gt;
&lt;br /&gt;
Audio and sometimes video from lectures will be available via the [[Operating Systems (Fall 2017)|lecture pages on the main course website]].  These same pages will also contain notes.&lt;br /&gt;
&lt;br /&gt;
Do not rely upon the lectures and notes to cover all material related to this class.  You are expected to keep up with the assigned textbook readings and material covered in the tutorials.&lt;br /&gt;
&lt;br /&gt;
==Required Textbooks==&lt;br /&gt;
&lt;br /&gt;
The course will be using the textbook [http://pages.cs.wisc.edu/~remzi/OSTEP/ Operating Systems: Three Easy Pieces].  The chapters of this textbook are available for free online; you can also buy a full epub, PDF, or paper copy if you wish.&lt;br /&gt;
&lt;br /&gt;
Individual chapters will be linked with the lectures associated with them.  You should plan on reading the assigned chapters &#039;&#039;&#039;before&#039;&#039;&#039; coming to class, as the material in lectures will be easier to understand then.  The lectures are designed to supplement the textbook, not replace them.&lt;br /&gt;
&lt;br /&gt;
==Course Software==&lt;br /&gt;
&lt;br /&gt;
In this course we will primarily working with [http://www.lubuntu.net/ Lubuntu], a low-resource variant of [http://www.ubuntu.com/ Ubuntu] Linux distribution.  You may use other Linux distributions in the tutorials to complete the assigned work; there will be differences, however, in some aspects (such as installing software), particularly if you use a distribution not based on Ubuntu or Debian.&lt;br /&gt;
&lt;br /&gt;
==University Policies &amp;amp; Resources==&lt;br /&gt;
&lt;br /&gt;
===Undergraduate Academic Advisor===&lt;br /&gt;
&lt;br /&gt;
The undergraduate advisor for the School of Computer Science is available in Room&lt;br /&gt;
5302C HP, by telephone at 520-2600, ext. 4364 or by email at&lt;br /&gt;
undergraduate_advisor@scs.carleton.ca. The advisor can assist with information about&lt;br /&gt;
prerequisites and preclusions, course substitutions/equivalencies, understanding your&lt;br /&gt;
academic audit and the remaining requirements for graduation. The undergraduate&lt;br /&gt;
advisor will also refer students to appropriate resources such as the Science Student&lt;br /&gt;
Success Centre, Learning Support Services and the Writing Tutorial Services.&lt;br /&gt;
&lt;br /&gt;
===Student Academic Integrity Policy===&lt;br /&gt;
&lt;br /&gt;
Every student should be familiar with the Carleton University student academic integrity policy. A student found in violation of academic integrity standards may be awarded penalties which range from a reprimand to receiving a grade of F in the course or even being expelled from the program or University. Some examples of offences are: plagiarism and unauthorized co-operation or collaboration. Information on this policy may be found in the Undergraduate Calendar.&lt;br /&gt;
&lt;br /&gt;
===Plagiarism===&lt;br /&gt;
&lt;br /&gt;
As defined by Senate, &amp;quot;plagiarism is presenting, whether intentional or not, the ideas, expression of ideas or work of others as one&#039;s own&amp;quot;. Such reported offences will be reviewed by the office of the Dean of Science.&lt;br /&gt;
&lt;br /&gt;
===Unauthorized Co-operation or Collaboration===&lt;br /&gt;
&lt;br /&gt;
Senate policy states that &amp;quot;to ensure fairness and equity in assessment of term work, students shall not co-operate or collaborate in the completion of an academic assignment, in whole or in part, when the instructor has indicated that the assignment is to be completed on an individual basis&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Please see above for the specific collaboration policy for this course.&lt;br /&gt;
&lt;br /&gt;
===Academic Accommodations for Students with Disabilities===&lt;br /&gt;
&lt;br /&gt;
The Paul Menton Centre for Students with Disabilities (PMC) provides services to students with Learning Disabilities (LD), psychiatric/mental health disabilities, Attention Deficit Hyperactivity Disorder (ADHD), Autism Spectrum Disorders (ASD), chronic medical conditions, and impairments in mobility, hearing, and vision. If you have a disability requiring academic accommodations in this course, please contact PMC at 613-520-6608 or pmc@carleton.ca for a formal evaluation. If you are already registered with the PMC, contact your PMC coordinator to send me your Letter of Accommodation at the beginning of the term, and no later than two weeks before the first in-class scheduled test or exam requiring accommodation (if applicable). After requesting accommodation from PMC, meet with me to ensure accommodation arrangements are made. Please consult the PMC website for the deadline to request accommodations for the formally-scheduled exam (if applicable) at https://www.carleton.ca/pmc/new-and-current-students/dates-and-deadlines&lt;br /&gt;
&lt;br /&gt;
===Religious Obligation===&lt;br /&gt;
&lt;br /&gt;
Write to the instructor with any requests for academic accommodation during the first two weeks of class, or as soon as possible after the need for accommodation is known to exist. For more details visit the Equity Services website: https://www.carleton.ca/equity/&lt;br /&gt;
&lt;br /&gt;
===Pregnancy Obligation===&lt;br /&gt;
&lt;br /&gt;
Write to the instructor with any requests for academic accommodation during the first two weeks of class, or as soon as possible after the need for accommodation is known to exist. For more details visit the Equity Services website: https://www.carleton.ca/equity/&lt;br /&gt;
&lt;br /&gt;
===Medical Certificate===&lt;br /&gt;
&lt;br /&gt;
The following is a link to the official medical certificate accepted by Carleton University for the deferral of final examinations or assignments in undergraduate courses. To access the form, please go to https://www.carleton.ca/registrar/forms&lt;/div&gt;</summary>
		<author><name>Jean</name></author>
	</entry>
</feed>