<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2018F%3A_Tutorial_1</id>
	<title>Operating Systems 2018F: Tutorial 1 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2018F%3A_Tutorial_1"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F:_Tutorial_1&amp;action=history"/>
	<updated>2026-06-02T20:27:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F:_Tutorial_1&amp;diff=21716&amp;oldid=prev</id>
		<title>Soma at 01:45, 10 September 2018</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F:_Tutorial_1&amp;diff=21716&amp;oldid=prev"/>
		<updated>2018-09-10T01:45:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 01:45, 10 September 2018&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;This tutorial is not yet finalized.&#039;&#039;&#039;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In this tutorial you will be learning about 1) the difference between system calls, function calls, and library calls and 2) how processes are created.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;In this tutorial you will be learning about 1) the difference between system calls, function calls, and library calls and 2) how processes are created.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Getting started==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;==Getting started==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To do the following exercises, bring up a terminal on a system running Linux, preferably Ubuntu Linux 18.04.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;To do the following exercises, bring up a terminal on a system running Linux, preferably Ubuntu Linux 18.04&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;.  In the SCS labs, run the COMP24XX virtual machine in VirtualBox.  (Log in as user student, password student.)  If you wish to use this VM from your own laptop, you can [http://download.scs.carleton.ca/virtualimages/COMPXXXX-ubuntu-18.04-minimal-desktop.ova download it] and import the appliance into [https://www.virtualbox.org/ VirtualBox].  Note that the import may generate an error or two regarding network interfaces; if you just delete everything but the first interface it should work fine&lt;/ins&gt;.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;For further help, please talk to the TAs in your lab.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;For further help, please talk to the TAs in your lab.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F:_Tutorial_1&amp;diff=21699&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;&#039;&#039;&#039;This tutorial is not yet finalized.&#039;&#039;&#039;  In this tutorial you will be learning about 1) the difference between system calls, function calls, and library calls and 2) how pro...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2018F:_Tutorial_1&amp;diff=21699&amp;oldid=prev"/>
		<updated>2018-09-05T18:10:45Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;This tutorial is not yet finalized.&amp;#039;&amp;#039;&amp;#039;  In this tutorial you will be learning about 1) the difference between system calls, function calls, and library calls and 2) how pro...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;This tutorial is not yet finalized.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
In this tutorial you will be learning about 1) the difference between system calls, function calls, and library calls and 2) how processes are created.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
To do the following exercises, bring up a terminal on a system running Linux, preferably Ubuntu Linux 18.04.&lt;br /&gt;
&lt;br /&gt;
For further help, please talk to the TAs in your lab.&lt;br /&gt;
&lt;br /&gt;
==Function calls, library calls, and system calls==&lt;br /&gt;
&lt;br /&gt;
For [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut1/hello.c hello.c], [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut1/syscall-hello.c syscall-hello.c], and later [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut1/csimpleshell.c csimpleshell.c] (after you&amp;#039;ve done the part below on csimpleshell) do the following (substituting the appropriate source file for prog.c):&lt;br /&gt;
# Compile the program prog.c using &amp;lt;tt&amp;gt;gcc -O2 prog.c -o prog-dyn&amp;lt;/tt&amp;gt; and run prog-dyn.  What does it do?&lt;br /&gt;
# Statically compile and optimize prog.c by running &amp;lt;tt&amp;gt;gcc -O2 -static prog.c -o prog-static&amp;lt;/tt&amp;gt;.  How does the size compare with &amp;lt;tt&amp;gt;prog&amp;lt;/tt&amp;gt;?&lt;br /&gt;
# See what system calls prog-static produces by running &amp;lt;tt&amp;gt;strace -o syscalls-static.log ./prog-static&amp;lt;/tt&amp;gt;.  Do the same for &amp;lt;tt&amp;gt;prog-dyn&amp;lt;/tt&amp;gt;.  Which version generates more system calls?&lt;br /&gt;
# See what library calls prog-static produces by running &amp;lt;tt&amp;gt;ltrace -o library-static.log ./prog-static&amp;lt;/tt&amp;gt;.  Do the same for &amp;lt;tt&amp;gt;prog-dyn&amp;lt;/tt&amp;gt;.  Which version generates more library calls?  (If ltrace isn&amp;#039;t installed, run &amp;lt;tt&amp;gt;sudo apt-get install ltrace&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# Using the &amp;lt;tt&amp;gt;nm&amp;lt;/tt&amp;gt; command, see what symbols are defined in prog-static and prog-dyn.&lt;br /&gt;
# Run the command &amp;lt;tt&amp;gt;gcc -c -O2 prog.c&amp;lt;/tt&amp;gt; to produce an object file.  What file was produced?  What symbols does it define?&lt;br /&gt;
# Look at the assembly code of the program by running &amp;lt;tt&amp;gt;gcc -S -O2 prog.c&amp;lt;/tt&amp;gt;.  What file was produced?  Identify the following:&lt;br /&gt;
#* A function call&lt;br /&gt;
#* A system call (if any)&lt;br /&gt;
#* A global/static variable (if any)&lt;br /&gt;
#* A local variable&lt;br /&gt;
# Disassemble the object file using &amp;lt;tt&amp;gt;objdump -d&amp;lt;/tt&amp;gt;.  How does this disassembly compare with the output from gcc -S?&lt;br /&gt;
# Examine the headers of object file, dynamically linked executable, and the statically linked executable using &amp;lt;tt&amp;gt;objdump -h&amp;lt;/tt&amp;gt;&lt;br /&gt;
# Examine the contents of object file, dynamically linked executable, and the statically linked executable using &amp;lt;tt&amp;gt;objdump -s&amp;lt;/tt&amp;gt;&lt;br /&gt;
# Re-run all of the previous gcc commands adding the &amp;quot;-v&amp;quot; flag.  What is all of that output?&lt;br /&gt;
# (optional) Look up the documentation for each of the system calls made by the static versions of the programs.  You may need to append a 2 or 3 to the manpage invocation, e.g. &amp;quot;man 2 write&amp;quot; gets you the write system call documentation.&lt;br /&gt;
&lt;br /&gt;
==Creating processes, running executables==&lt;br /&gt;
&lt;br /&gt;
For this part you will be playing with and modifying [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut1/csimpleshell.c csimpleshell.c] by [https://web.archive.org/web/20170223203852/http://rik0.altervista.org/snippets/csimpleshell.html Enrico Franchi].  The source is also listed below.&lt;br /&gt;
&lt;br /&gt;
# In csimpleshell, change the prompt to be the current user (e.g., &amp;quot;student $&amp;quot;), as reported by the USER environment variable.&lt;br /&gt;
# Make csimpleshell not call &amp;lt;tt&amp;gt;wait()&amp;lt;/tt&amp;gt; on the command if there is an &amp;amp; as the last argument to a command; instead, just return another prompt.  Can you see the zombies that are now produced?&lt;br /&gt;
# Change the &amp;lt;tt&amp;gt;execvp()&amp;lt;/tt&amp;gt; call to [http://pubs.opengroup.org/onlinepubs/9699919799/functions/execve.html execve()].  Where do you get the extra argument?  (NOTE: When you switch to execve() you will have to specify the full path to commands, e.g. /bin/ls not ls.)&lt;br /&gt;
# Add an environment variable called LASTCOMMAND that contains the last command that was executed by csimpleshell.  This environment variable should be passed on to each new program that is run.  How can you check that your code works?&lt;br /&gt;
# Use [http://pubs.opengroup.org/onlinepubs/9699919799/functions/sigaction.html sigaction()] and [http://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html waitpid()] to create a signal handler for SIGCHLD that prevents the creation of zombies for background commands.&lt;br /&gt;
# (Advanced) Implement I/O redirection for STDIN (&amp;lt;) and STDOUT (&amp;gt;).  Do the same for arbitrary file descriptors (e.g., 2&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
===hello.c===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Hello world!\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===syscall-hello.c===&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/syscall.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
char *buf = &amp;quot;Hello world!\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv) {&lt;br /&gt;
        size_t result;&lt;br /&gt;
&lt;br /&gt;
        /* &amp;quot;man 2 write&amp;quot; to see arguments to write syscall */&lt;br /&gt;
        result = syscall(SYS_write, 1, buf, 13);&lt;br /&gt;
&lt;br /&gt;
        return (int) result;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===csimpleshell.c===&lt;br /&gt;
&amp;lt;source line lang=&amp;quot;C&amp;quot;&amp;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;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;errno.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#define BUFFER_SIZE 1&amp;lt;&amp;lt;16&lt;br /&gt;
#define ARR_SIZE 1&amp;lt;&amp;lt;16&lt;br /&gt;
&lt;br /&gt;
void parse_args(char *buffer, char** args, &lt;br /&gt;
                size_t args_size, size_t *nargs)&lt;br /&gt;
{&lt;br /&gt;
    char *buf_args[args_size]; /* You need C99 */&lt;br /&gt;
    char **cp;&lt;br /&gt;
    char *wbuf;&lt;br /&gt;
    size_t i, j;&lt;br /&gt;
    &lt;br /&gt;
    wbuf=buffer;&lt;br /&gt;
    buf_args[0]=buffer; &lt;br /&gt;
    args[0] =buffer;&lt;br /&gt;
    &lt;br /&gt;
    for(cp=buf_args; (*cp=strsep(&amp;amp;wbuf, &amp;quot; \n\t&amp;quot;)) != NULL ;){&lt;br /&gt;
        if ((*cp != &amp;#039;\0&amp;#039;) &amp;amp;&amp;amp; (++cp &amp;gt;= &amp;amp;buf_args[args_size]))&lt;br /&gt;
            break;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    for (j=i=0; buf_args[i]!=NULL; i++){&lt;br /&gt;
        if(strlen(buf_args[i])&amp;gt;0)&lt;br /&gt;
            args[j++]=buf_args[i];&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    *nargs=j;&lt;br /&gt;
    args[j]=NULL;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[], char *envp[]){&lt;br /&gt;
    char buffer[BUFFER_SIZE];&lt;br /&gt;
    char *args[ARR_SIZE];&lt;br /&gt;
&lt;br /&gt;
    int *ret_status;&lt;br /&gt;
    size_t nargs;&lt;br /&gt;
    pid_t pid;&lt;br /&gt;
    &lt;br /&gt;
    while(1){&lt;br /&gt;
        printf(&amp;quot;$ &amp;quot;);&lt;br /&gt;
        fgets(buffer, BUFFER_SIZE, stdin);&lt;br /&gt;
        parse_args(buffer, args, ARR_SIZE, &amp;amp;nargs); &lt;br /&gt;
&lt;br /&gt;
        if (nargs==0) continue;&lt;br /&gt;
        if (!strcmp(args[0], &amp;quot;exit&amp;quot; )) exit(0);       &lt;br /&gt;
        pid = fork();&lt;br /&gt;
        if (pid){&lt;br /&gt;
            printf(&amp;quot;Waiting for child (%d)\n&amp;quot;, pid);&lt;br /&gt;
            pid = wait(ret_status);&lt;br /&gt;
            printf(&amp;quot;Child (%d) finished\n&amp;quot;, pid);&lt;br /&gt;
        } else {&lt;br /&gt;
            if( execvp(args[0], args)) {&lt;br /&gt;
                puts(strerror(errno));&lt;br /&gt;
                exit(127);&lt;br /&gt;
            }&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>Soma</name></author>
	</entry>
</feed>