<?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_2020W_Lecture_5</id>
	<title>Operating Systems 2020W Lecture 5 - 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_2020W_Lecture_5"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_5&amp;action=history"/>
	<updated>2026-06-02T22:24:21Z</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_2020W_Lecture_5&amp;diff=22570&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on January 22, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec05-20200122.m4v is now available]....&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_5&amp;diff=22570&amp;oldid=prev"/>
		<updated>2020-03-20T02:30:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on January 22, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec05-20200122.m4v is now available]....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on January 22, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec05-20200122.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===Connecting to Openstack===&lt;br /&gt;
&lt;br /&gt;
To connect to an openstack instance off campus, either:&lt;br /&gt;
* Connect to the [https://carleton.ca/its/help-centre/remote-access/ Carleton VPN], then ssh to the instance, or&lt;br /&gt;
* If you instance is at 134.117.30.30 and your username is carletonstudent, do the following (note that you can replace the 1200 with another number between 1024 and 65535):&lt;br /&gt;
  ssh -L 1200:134.117.30.30:22 carletonstudent@access.scs.carleton.ca&lt;br /&gt;
  [stay logged in, and in another window do the following]&lt;br /&gt;
  ssh -p 1200 student@localhost&lt;br /&gt;
&lt;br /&gt;
===Using gdb to view assembly code===&lt;br /&gt;
&lt;br /&gt;
To compile for debugging with gdb:&lt;br /&gt;
  gcc -O -g myprogram.c -o myprogram&lt;br /&gt;
The -O option is for optimization (could use -O2, -O3 for more optimization, but -O is sufficient normally).  You want to optimize the code because otherwise the assembly code will be harder to follow.&lt;br /&gt;
&lt;br /&gt;
To run a program under gdb:&lt;br /&gt;
 gdb ./myprogram&lt;br /&gt;
&lt;br /&gt;
The following commands in gdb should be useful:&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;break x&amp;#039;&amp;#039;&amp;#039;: set a breakpoint at function x.  Set a breakpoint for main if you want to see program execution starting with your code.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;tui enable&amp;#039;&amp;#039;&amp;#039;: enable display of source code&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;layout asm&amp;#039;&amp;#039;&amp;#039;: switch the display to assembly code&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;layout split&amp;#039;&amp;#039;&amp;#039;: switch display to assembly and source code&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;layout src&amp;#039;&amp;#039;&amp;#039;: show source code&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;n&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;next&amp;#039;&amp;#039;&amp;#039;: next source-level statement, staying within the current function&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;step&amp;#039;&amp;#039;&amp;#039;: next source-level statement, going into called functions&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;nexti&amp;#039;&amp;#039;&amp;#039;: next assembly-language statement, staying within the current function&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;stepi&amp;#039;&amp;#039;&amp;#039;: next assembly-language statement, going into called functions&lt;br /&gt;
To repeat a command, just hit enter.&lt;br /&gt;
&lt;br /&gt;
To see a system call be executed, single-step through a program until you see a &amp;quot;syscall&amp;quot; instruction (on x86-64).  Note how even with a program that directly makes a system call such as [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/tut1/syscall-hello.c syscall-hello.c], the program first makes a function call (using &amp;lt;tt&amp;gt;callq&amp;lt;/tt&amp;gt;) to the syscall function, and that function makes the actual system call.&lt;br /&gt;
&lt;br /&gt;
For more information on gdb in tui mode, see [https://www-users.cs.umn.edu/~kauffman/ Chris Kauffman&amp;#039;s] [https://www-users.cs.umn.edu/~kauffman/2021/ UMN CSCI 2021] [https://www-users.cs.umn.edu/~kauffman/2021/gdb.html Quick guide to GDB].&lt;br /&gt;
&lt;br /&gt;
===In-Class Notes===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 5&lt;br /&gt;
---------&lt;br /&gt;
Topics:&lt;br /&gt;
- Assignment 1&lt;br /&gt;
- syscall-hello.c&lt;br /&gt;
- gdb and assembly&lt;br /&gt;
- showing a system call instruction&lt;br /&gt;
&lt;br /&gt;
- creating processes with fork&lt;br /&gt;
- running programs with execve&lt;br /&gt;
- returning values with exit&lt;br /&gt;
&lt;br /&gt;
Process is a running program&lt;br /&gt;
&lt;br /&gt;
Could have a system call to create a new process and run a program in it&lt;br /&gt;
 - this is how Windows does it with CreateProcess(), other calls?&lt;br /&gt;
&lt;br /&gt;
But UNIX divides this into two steps&lt;br /&gt;
 - fork: make a copy of the current process&lt;br /&gt;
 - execve: run a binary in a process, replacing the currently running program&lt;br /&gt;
&lt;br /&gt;
So normally, to run a program in a separate process&lt;br /&gt;
 - create a &amp;quot;child&amp;quot; process using fork&lt;br /&gt;
 - child process runs execve to load new program&lt;br /&gt;
 - parent process waits for child to finish (optional)&lt;br /&gt;
&lt;br /&gt;
Basic flow of a UNIX shell (or anything that wants to run external programs)&lt;br /&gt;
 - setup execution context&lt;br /&gt;
 - fork&lt;br /&gt;
   - parent waits for child to finish, or calls wait when told&lt;br /&gt;
     the child has finished&lt;br /&gt;
   - child does an execve to load new program&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;c&amp;quot; line&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
#include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
        pid_t fork_pid = -1;&lt;br /&gt;
        pid_t mypid;&lt;br /&gt;
&lt;br /&gt;
        fork_pid = fork();&lt;br /&gt;
        mypid = getpid();&lt;br /&gt;
        printf(&amp;quot;My pid is %d\n&amp;quot;, mypid);&lt;br /&gt;
        &lt;br /&gt;
        if (fork_pid == 0) {&lt;br /&gt;
                printf(&amp;quot;Fork done! I am the child.\n&amp;quot;);&lt;br /&gt;
        } else {&lt;br /&gt;
                printf(&amp;quot;I am the parent, my child&amp;#039;s PID is %d\n&amp;quot;, fork_pid);&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>