<?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=Abdou</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=Abdou"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Abdou"/>
	<updated>2026-05-12T16:39:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24586</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24586"/>
		<updated>2023-11-30T17:26:42Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 8 | Tutorial 8]] || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 9 | Tutorial 9]] || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || &amp;lt;span style=&amp;quot;color:red; background:yellow&amp;quot;&amp;gt;1:05 pm-2:25 pm&amp;lt;/span&amp;gt; || &amp;lt;span style=&amp;quot;color:red; background:yellow&amp;quot;&amp;gt;MC2000&amp;lt;/span&amp;gt; || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24585</id>
		<title>COMP3000 Operating Systems F23: Tutorial 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24585"/>
		<updated>2023-10-25T02:11:57Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;By the end of this tutorial, you will have a basic familiarity with the Docker platform and be able to run, operate, and customize containers, and create simple containers of your own. You will see how kernel building blocks like namespaces make containers possible.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
===Docker containers===&lt;br /&gt;
Docker is one of the OS-level virtualization technologies that allows the creation of isolated virtual execution environments, called containers, sharing the same OS kernel and certain runtime services/libraries with other containers. The workload running inside a container will feel as if it had its own everything, OS kernel, root file system, etc. This is possible thanks to the way Docker containers are designed and implemented. The Linux kernel does not directly support the construction of containers (the userspace libraries do) but its various building blocks play an important role, among which we will cover namespaces in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Docker images===&lt;br /&gt;
A Docker image is a file containing a root file system as well as configuration parameters. It is very similar to other disk image formats in this sense. One of the main differences is that it employs a layered file system to maximize storage efficiency and allow flexible reuse of existing files.&lt;br /&gt;
 &lt;br /&gt;
===Dockerfile===&lt;br /&gt;
A Dockerfile is a text file and serves as instructions to build a Docker image. Unlike storing and distributing binary data directly in images, using Dockerfiles can save space and rebuild the Docker image by always downloading the latest version of software.&lt;br /&gt;
&lt;br /&gt;
===Docker Registry===&lt;br /&gt;
The Registry is a server-side application containing and managing repositories of Docker images. We use Docker Hub (among other choices by different providers) to pull images from in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Namespaces===&lt;br /&gt;
Namespaces allow for multiple “spaces” where identical names can coexist. For example, the same process ID (PID) may refer to completely different processes. This is like how we can distinguish Tom (PID) in Ottawa (namespace) from Tom in Toronto (namespace). Namespaces are enforced by the OS kernel. They are the fundamental building block of containers.&lt;br /&gt;
&lt;br /&gt;
A few namespaces we will cover here: Mount (&amp;lt;code&amp;gt;mnt&amp;lt;/code&amp;gt;), Network (&amp;lt;code&amp;gt;net&amp;lt;/code&amp;gt;), User ID (&amp;lt;code&amp;gt;uid&amp;lt;/code&amp;gt;) and Process ID (&amp;lt;code&amp;gt;pid&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;lt;code&amp;gt;lsns&amp;lt;/code&amp;gt; to see the namespaces the current process is in. A namespace ID is actually an &#039;&#039;&#039;inode&#039;&#039;&#039;. &lt;br /&gt;
 &lt;br /&gt;
Also, the command &amp;lt;code&amp;gt;nsenter&amp;lt;/code&amp;gt; allows you to run programs with namespaces of another process. Use the &amp;lt;code&amp;gt;-t&amp;lt;/code&amp;gt; option to specify the target PID. For instance, &amp;lt;code&amp;gt;sudo nsenter -t 2772 -m ls /&amp;lt;/code&amp;gt; will list the root file system of the mount namespace of process 2772.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
The purpose of the following questions and tasks is to help you understand how containers work, which is an important artifact on top of and based on modern operating systems. The focus is on the OS building blocks – how it is made possible by the OS. Docker is just a typical and popular example to facilitate understanding. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You need to &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; for all the &amp;lt;code&amp;gt;docker&amp;lt;/code&amp;gt; commands below&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Install Docker with &amp;lt;code&amp;gt;sudo apt install docker.io&amp;lt;/code&amp;gt; if it’s not already installed.&lt;br /&gt;
&lt;br /&gt;
# Use &amp;lt;code&amp;gt;docker images&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;docker ps&amp;lt;/code&amp;gt; (similar to the purpose of &amp;lt;code&amp;gt;ps&amp;lt;/code&amp;gt;) to see what images you have and whether any containers are running. Run your first container with &amp;lt;code&amp;gt;docker run hello-world&amp;lt;/code&amp;gt;. Now, check the images and &amp;lt;code&amp;gt;docker ps&amp;lt;/code&amp;gt; again, what do you see and &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Look at the hello-world image above and you may wonder how the tiny-sized image forms a full container. Find out where the files are located (hint: using the command &amp;lt;code&amp;gt;docker inspect&amp;lt;/code&amp;gt; and looking for paths starting with &amp;lt;code&amp;gt;/var/lib/docker&amp;lt;/code&amp;gt;). What is the size of the found file? Run the file directly. &amp;lt;u&amp;gt;What do you think&amp;lt;/u&amp;gt; is the way the tiny-sized image forms the full container?&lt;br /&gt;
# &amp;lt;code&amp;gt;docker ps -a&amp;lt;/code&amp;gt; will show something different. Next, let’s try an image of a bit more complexity that will remain running. Try the centos (a Linux distribution) image: &amp;lt;code&amp;gt;docker run -d centos sleep infinity&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;man docker-run&amp;lt;/code&amp;gt; for the meaning of the options). &lt;br /&gt;
# Start a new shell: &amp;lt;code&amp;gt;docker exec -it&amp;lt;/code&amp;gt; &amp;lt;CONTAINER ID&amp;gt; &amp;lt;code&amp;gt;/bin/bash&amp;lt;/code&amp;gt; (you can find out the container ID with &amp;lt;code&amp;gt;docker ps -a&amp;lt;/code&amp;gt;. Note that you can specify just the first few digits of the ID as long as it’s distinctive). Explore the file system therein.&lt;br /&gt;
#; Next, we will examine the namespaces.&lt;br /&gt;
# Compare the mount namespaces (different views of the file system structure) between the centos container and the host, using &amp;lt;code&amp;gt;ls -l /proc/self/ns/mnt&amp;lt;/code&amp;gt;. Are they the same and if not, what are they (format: &amp;lt;code&amp;gt;mnt:[????]&amp;lt;/code&amp;gt;)? In particular, take a look at the root mount point (“&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;”) inside and outside the container (&amp;lt;code&amp;gt;mount | grep &amp;quot;on / &amp;quot;&amp;lt;/code&amp;gt;). You can always use two sessions (one in the container and one in the host) or &amp;lt;code&amp;gt;tmux&amp;lt;/code&amp;gt; as you feel convenient.&lt;br /&gt;
# With the &amp;lt;code&amp;gt;lsns&amp;lt;/code&amp;gt; command, you can get an overview of all namespaces. Comparing the centos container and the host, &amp;lt;u&amp;gt;which namespaces are the same (shared) and which are different&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Inside the container, use the command &amp;lt;code&amp;gt;id&amp;lt;/code&amp;gt; to see what user you’re logged in as (uid, gid and group). Then &amp;lt;code&amp;gt;ps -eo uid,gid,pid,command | grep sleep&amp;lt;/code&amp;gt; inside the container and outside the container respectively. Are their outputs the same?&lt;br /&gt;
# Using the pid of “sleep” you have got outside the container above, find its pid namespace (&amp;lt;code&amp;gt;sudo ls -l /proc/&amp;lt;pid&amp;gt;/ns/pid&amp;lt;/code&amp;gt;, format &amp;lt;code&amp;gt;pid:[????]&amp;lt;/code&amp;gt;). Is it consistent with the &amp;lt;code&amp;gt;lsns&amp;lt;/code&amp;gt; output inside the container?&lt;br /&gt;
# From step 6, you have the individual namespaces used by the “sleep” container (no need to go inside the container again). Let’s check the network namespace (&amp;lt;code&amp;gt;sudo nsenter -t &amp;lt;/code&amp;gt;&amp;lt;pid&amp;gt;&amp;lt;code&amp;gt; -n ip addr&amp;lt;/code&amp;gt;). &lt;br /&gt;
#: Note that uid remapping is not enabled by default. So the user (uid) inside the container will be the same outside (which does not consider security).&lt;br /&gt;
# Now, make your own Docker container. Read the current [https://raw.githubusercontent.com/docker-library/hello-world/7ecae6978055d2fb6960e2a29d24a2af612e2716/amd64/hello-world/Dockerfile Dockerfile of hello-world]. Change it in a way that it is no longer from scratch but &#039;&#039;from &amp;lt;code&amp;gt;hello-world &amp;lt;/code&amp;gt;&#039;&#039;. Here we can avoid defining &amp;lt;code&amp;gt;csimpleshell&amp;lt;/code&amp;gt; as the default command as it works with a terminal for interaction (then it will inherit &amp;lt;code&amp;gt;CMD&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;hello-world&amp;lt;/code&amp;gt;). Build a new image called &amp;lt;code&amp;gt;csimpleshell&amp;lt;/code&amp;gt; by doing the following: &lt;br /&gt;
#: &amp;lt;code&amp;gt;mkdir anyname&amp;lt;/code&amp;gt;&lt;br /&gt;
#: copy your &amp;lt;code&amp;gt;csimipleshell&amp;lt;/code&amp;gt; and the Dockerfile of &amp;lt;code&amp;gt;hello-world&amp;lt;/code&amp;gt; into this directory&lt;br /&gt;
#: &amp;lt;code&amp;gt;cd anyname&amp;lt;/code&amp;gt;&lt;br /&gt;
#: make necessary changes to the Dockerfile&lt;br /&gt;
#: &amp;lt;code&amp;gt;docker build -t csimpleshell .&amp;lt;/code&amp;gt;&lt;br /&gt;
# Run the new csimpleshell container (e.g., &amp;lt;code&amp;gt;docker run -it csimpleshell /csimpleshell&amp;lt;/code&amp;gt;). Depending on &amp;lt;code&amp;gt;how you compiled csimpleshell&amp;lt;/code&amp;gt;, check whether the container runs or if it does whether csimpleshell works as before. Try compiling csimpleshell statically (if it was dynamic) and repeat the steps.&lt;br /&gt;
# Edit the Dockerfile again and make it from “centos” instead of “hello-world”. Remove any reference to hello. Rebuild and run it. How is csimpleshell now? &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is there such a difference?&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24584</id>
		<title>COMP3000 Operating Systems F23: Tutorial 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24584"/>
		<updated>2023-10-25T02:09:06Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* General Instructions (same for all tutorials) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;By the end of this tutorial, you will have a basic familiarity with the Docker platform and be able to run, operate, and customize containers, and create simple containers of your own. You will see how kernel building blocks like namespaces make containers possible.&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
===Docker containers===&lt;br /&gt;
Docker is one of the OS-level virtualization technologies that allows the creation of isolated virtual execution environments, called containers, sharing the same OS kernel and certain runtime services/libraries with other containers. The workload running inside a container will feel as if it had its own everything, OS kernel, root file system, etc. This is possible thanks to the way Docker containers are designed and implemented. The Linux kernel does not directly support the construction of containers (the userspace libraries do) but its various building blocks play an important role, among which we will cover namespaces in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Docker images===&lt;br /&gt;
A Docker image is a file containing a root file system as well as configuration parameters. It is very similar to other disk image formats in this sense. One of the main differences is that it employs a layered file system to maximize storage efficiency and allow flexible reuse of existing files.&lt;br /&gt;
 &lt;br /&gt;
===Dockerfile===&lt;br /&gt;
A Dockerfile is a text file and serves as instructions to build a Docker image. Unlike storing and distributing binary data directly in images, using Dockerfiles can save space and rebuild the Docker image by always downloading the latest version of software.&lt;br /&gt;
&lt;br /&gt;
===Docker Registry===&lt;br /&gt;
The Registry is a server-side application containing and managing repositories of Docker images. We use Docker Hub (among other choices by different providers) to pull images from in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Namespaces===&lt;br /&gt;
Namespaces allow for multiple “spaces” where identical names can coexist. For example, the same process ID (PID) may refer to completely different processes. This is like how we can distinguish Tom (PID) in Ottawa (namespace) from Tom in Toronto (namespace). Namespaces are enforced by the OS kernel. They are the fundamental building block of containers.&lt;br /&gt;
&lt;br /&gt;
A few namespaces we will cover here: Mount (&amp;lt;tt&amp;gt;mnt&amp;lt;/tt&amp;gt;), Network (&amp;lt;tt&amp;gt;net&amp;lt;/tt&amp;gt;), User ID (&amp;lt;tt&amp;gt;uid&amp;lt;/tt&amp;gt;) and Process ID (&amp;lt;tt&amp;gt;pid&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; to see the namespaces the current process is in. A namespace ID is actually an &#039;&#039;&#039;inode&#039;&#039;&#039;. &lt;br /&gt;
 &lt;br /&gt;
Also, the command &amp;lt;tt&amp;gt;nsenter&amp;lt;/tt&amp;gt; allows you to run programs with namespaces of another process. Use the &amp;lt;tt&amp;gt;-t&amp;lt;/tt&amp;gt; option to specify the target PID. For instance, &amp;lt;tt&amp;gt;sudo nsenter -t 2772 -m ls /&amp;lt;/tt&amp;gt; will list the root file system of the mount namespace of process 2772.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
The purpose of the following questions and tasks is to help you understand how containers work, which is an important artifact on top of and based on modern operating systems. The focus is on the OS building blocks – how it is made possible by the OS. Docker is just a typical and popular example to facilitate understanding. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You need to &amp;lt;tt&amp;gt;sudo&amp;lt;/tt&amp;gt; for all the &amp;lt;tt&amp;gt;docker&amp;lt;/tt&amp;gt; commands below&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Install Docker with &amp;lt;tt&amp;gt;sudo apt install docker.io&amp;lt;/tt&amp;gt; if it’s not already installed.&lt;br /&gt;
&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;docker images&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;docker ps&amp;lt;/tt&amp;gt; (similar to the purpose of &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) to see what images you have and whether any containers are running. Run your first container with &amp;lt;tt&amp;gt;docker run hello-world&amp;lt;/tt&amp;gt;. Now, check the images and &amp;lt;tt&amp;gt;docker ps&amp;lt;/tt&amp;gt; again, what do you see and &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Look at the hello-world image above and you may wonder how the tiny-sized image forms a full container. Find out where the files are located (hint: using the command &amp;lt;tt&amp;gt;docker inspect&amp;lt;/tt&amp;gt; and looking for paths starting with &amp;lt;tt&amp;gt;/var/lib/docker&amp;lt;/tt&amp;gt;). What is the size of the found file? Run the file directly. &amp;lt;u&amp;gt;What do you think&amp;lt;/u&amp;gt; is the way the tiny-sized image forms the full container?&lt;br /&gt;
# &amp;lt;tt&amp;gt;docker ps -a&amp;lt;/tt&amp;gt; will show something different. Next, let’s try an image of a bit more complexity that will remain running. Try the centos (a Linux distribution) image: &amp;lt;tt&amp;gt;docker run -d centos sleep infinity&amp;lt;/tt&amp;gt; (&amp;lt;tt&amp;gt;man docker-run&amp;lt;/tt&amp;gt; for the meaning of the options). &lt;br /&gt;
# Start a new shell: &amp;lt;tt&amp;gt;docker exec -it&amp;lt;/tt&amp;gt; &amp;lt;CONTAINER ID&amp;gt; &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt; (you can find out the container ID with &amp;lt;tt&amp;gt;docker ps -a&amp;lt;/tt&amp;gt;. Note that you can specify just the first few digits of the ID as long as it’s distinctive). Explore the file system therein.&lt;br /&gt;
#; Next, we will examine the namespaces.&lt;br /&gt;
# Compare the mount namespaces (different views of the file system structure) between the centos container and the host, using &amp;lt;tt&amp;gt;ls -l /proc/self/ns/mnt&amp;lt;/tt&amp;gt;. Are they the same and if not, what are they (format: &amp;lt;tt&amp;gt;mnt:[????]&amp;lt;/tt&amp;gt;)? In particular, take a look at the root mount point (“&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;”) inside and outside the container (&amp;lt;tt&amp;gt;mount | grep &amp;quot;on / &amp;quot;&amp;lt;/tt&amp;gt;). You can always use two sessions (one in the container and one in the host) or &amp;lt;tt&amp;gt;tmux&amp;lt;/tt&amp;gt; as you feel convenient.&lt;br /&gt;
# With the &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; command, you can get an overview of all namespaces. Comparing the centos container and the host, &amp;lt;u&amp;gt;which namespaces are the same (shared) and which are different&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Inside the container, use the command &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; to see what user you’re logged in as (uid, gid and group). Then &amp;lt;tt&amp;gt;ps -eo uid,gid,pid,command | grep sleep&amp;lt;/tt&amp;gt; inside the container and outside the container respectively. Are their outputs the same?&lt;br /&gt;
# Using the pid of “sleep” you have got outside the container above, find its pid namespace (&amp;lt;tt&amp;gt;sudo ls -l /proc/&amp;lt;pid&amp;gt;/ns/pid&amp;lt;/tt&amp;gt;, format &amp;lt;tt&amp;gt;pid:[????]&amp;lt;/tt&amp;gt;). Is it consistent with the &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; output inside the container?&lt;br /&gt;
# From step 6, you have the individual namespaces used by the “sleep” container (no need to go inside the container again). Let’s check the network namespace (&amp;lt;tt&amp;gt;sudo nsenter -t &amp;lt;/tt&amp;gt;&amp;lt;pid&amp;gt;&amp;lt;tt&amp;gt; -n ip addr&amp;lt;/tt&amp;gt;). &lt;br /&gt;
#: Note that uid remapping is not enabled by default. So the user (uid) inside the container will be the same outside (which does not consider security).&lt;br /&gt;
# Now, make your own Docker container. Read the current [https://raw.githubusercontent.com/docker-library/hello-world/7ecae6978055d2fb6960e2a29d24a2af612e2716/amd64/hello-world/Dockerfile Dockerfile of hello-world]. Change it in a way that it is no longer from scratch but &#039;&#039;from &amp;lt;tt&amp;gt;hello-world &amp;lt;/tt&amp;gt;&#039;&#039;. Here we can avoid defining &amp;lt;tt&amp;gt;csimpleshell&amp;lt;/tt&amp;gt; as the default command as it works with a terminal for interaction (then it will inherit &amp;lt;tt&amp;gt;CMD&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;hello-world&amp;lt;/tt&amp;gt;). Build a new image called &amp;lt;tt&amp;gt;csimpleshell&amp;lt;/tt&amp;gt; by doing the following: &lt;br /&gt;
#: &amp;lt;tt&amp;gt;mkdir anyname&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: copy your &amp;lt;tt&amp;gt;csimipleshell&amp;lt;/tt&amp;gt; and the Dockerfile of &amp;lt;tt&amp;gt;hello-world&amp;lt;/tt&amp;gt; into this directory&lt;br /&gt;
#: &amp;lt;tt&amp;gt;cd anyname&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: make necessary changes to the Dockerfile&lt;br /&gt;
#: &amp;lt;tt&amp;gt;docker build -t csimpleshell .&amp;lt;/tt&amp;gt;&lt;br /&gt;
# Run the new csimpleshell container (e.g., &amp;lt;tt&amp;gt;docker run -it csimpleshell /csimpleshell&amp;lt;/tt&amp;gt;). Depending on &amp;lt;tt&amp;gt;how you compiled csimpleshell&amp;lt;/tt&amp;gt;, check whether the container runs or if it does whether csimpleshell works as before. Try compiling csimpleshell statically (if it was dynamic) and repeat the steps.&lt;br /&gt;
# Edit the Dockerfile again and make it from “centos” instead of “hello-world”. Remove any reference to hello. Rebuild and run it. How is csimpleshell now? &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is there such a difference?&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24583</id>
		<title>COMP3000 Operating Systems F23: Tutorial 9</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_9&amp;diff=24583"/>
		<updated>2023-10-25T02:09:00Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;By the end of this tutorial, you will have a basic familiarity with the Docker platform and be able to run, operate, and customize containers, and create simple containers of your own. You will see how kernel building blocks like namespaces make containers possible.  ==General Instructions (same for all tutorials)==  &amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt; Click on Expand to view. &amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt; Tutorials are graded based on participation and effo...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;By the end of this tutorial, you will have a basic familiarity with the Docker platform and be able to run, operate, and customize containers, and create simple containers of your own. You will see how kernel building blocks like namespaces make containers possible.&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Background==&lt;br /&gt;
&lt;br /&gt;
===Docker containers===&lt;br /&gt;
Docker is one of the OS-level virtualization technologies that allows the creation of isolated virtual execution environments, called containers, sharing the same OS kernel and certain runtime services/libraries with other containers. The workload running inside a container will feel as if it had its own everything, OS kernel, root file system, etc. This is possible thanks to the way Docker containers are designed and implemented. The Linux kernel does not directly support the construction of containers (the userspace libraries do) but its various building blocks play an important role, among which we will cover namespaces in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Docker images===&lt;br /&gt;
A Docker image is a file containing a root file system as well as configuration parameters. It is very similar to other disk image formats in this sense. One of the main differences is that it employs a layered file system to maximize storage efficiency and allow flexible reuse of existing files.&lt;br /&gt;
 &lt;br /&gt;
===Dockerfile===&lt;br /&gt;
A Dockerfile is a text file and serves as instructions to build a Docker image. Unlike storing and distributing binary data directly in images, using Dockerfiles can save space and rebuild the Docker image by always downloading the latest version of software.&lt;br /&gt;
&lt;br /&gt;
===Docker Registry===&lt;br /&gt;
The Registry is a server-side application containing and managing repositories of Docker images. We use Docker Hub (among other choices by different providers) to pull images from in this tutorial.&lt;br /&gt;
&lt;br /&gt;
===Namespaces===&lt;br /&gt;
Namespaces allow for multiple “spaces” where identical names can coexist. For example, the same process ID (PID) may refer to completely different processes. This is like how we can distinguish Tom (PID) in Ottawa (namespace) from Tom in Toronto (namespace). Namespaces are enforced by the OS kernel. They are the fundamental building block of containers.&lt;br /&gt;
&lt;br /&gt;
A few namespaces we will cover here: Mount (&amp;lt;tt&amp;gt;mnt&amp;lt;/tt&amp;gt;), Network (&amp;lt;tt&amp;gt;net&amp;lt;/tt&amp;gt;), User ID (&amp;lt;tt&amp;gt;uid&amp;lt;/tt&amp;gt;) and Process ID (&amp;lt;tt&amp;gt;pid&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
You can use the command &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; to see the namespaces the current process is in. A namespace ID is actually an &#039;&#039;&#039;inode&#039;&#039;&#039;. &lt;br /&gt;
 &lt;br /&gt;
Also, the command &amp;lt;tt&amp;gt;nsenter&amp;lt;/tt&amp;gt; allows you to run programs with namespaces of another process. Use the &amp;lt;tt&amp;gt;-t&amp;lt;/tt&amp;gt; option to specify the target PID. For instance, &amp;lt;tt&amp;gt;sudo nsenter -t 2772 -m ls /&amp;lt;/tt&amp;gt; will list the root file system of the mount namespace of process 2772.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
The purpose of the following questions and tasks is to help you understand how containers work, which is an important artifact on top of and based on modern operating systems. The focus is on the OS building blocks – how it is made possible by the OS. Docker is just a typical and popular example to facilitate understanding. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;You need to &amp;lt;tt&amp;gt;sudo&amp;lt;/tt&amp;gt; for all the &amp;lt;tt&amp;gt;docker&amp;lt;/tt&amp;gt; commands below&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Install Docker with &amp;lt;tt&amp;gt;sudo apt install docker.io&amp;lt;/tt&amp;gt; if it’s not already installed.&lt;br /&gt;
&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;docker images&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;docker ps&amp;lt;/tt&amp;gt; (similar to the purpose of &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) to see what images you have and whether any containers are running. Run your first container with &amp;lt;tt&amp;gt;docker run hello-world&amp;lt;/tt&amp;gt;. Now, check the images and &amp;lt;tt&amp;gt;docker ps&amp;lt;/tt&amp;gt; again, what do you see and &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Look at the hello-world image above and you may wonder how the tiny-sized image forms a full container. Find out where the files are located (hint: using the command &amp;lt;tt&amp;gt;docker inspect&amp;lt;/tt&amp;gt; and looking for paths starting with &amp;lt;tt&amp;gt;/var/lib/docker&amp;lt;/tt&amp;gt;). What is the size of the found file? Run the file directly. &amp;lt;u&amp;gt;What do you think&amp;lt;/u&amp;gt; is the way the tiny-sized image forms the full container?&lt;br /&gt;
# &amp;lt;tt&amp;gt;docker ps -a&amp;lt;/tt&amp;gt; will show something different. Next, let’s try an image of a bit more complexity that will remain running. Try the centos (a Linux distribution) image: &amp;lt;tt&amp;gt;docker run -d centos sleep infinity&amp;lt;/tt&amp;gt; (&amp;lt;tt&amp;gt;man docker-run&amp;lt;/tt&amp;gt; for the meaning of the options). &lt;br /&gt;
# Start a new shell: &amp;lt;tt&amp;gt;docker exec -it&amp;lt;/tt&amp;gt; &amp;lt;CONTAINER ID&amp;gt; &amp;lt;tt&amp;gt;/bin/bash&amp;lt;/tt&amp;gt; (you can find out the container ID with &amp;lt;tt&amp;gt;docker ps -a&amp;lt;/tt&amp;gt;. Note that you can specify just the first few digits of the ID as long as it’s distinctive). Explore the file system therein.&lt;br /&gt;
#; Next, we will examine the namespaces.&lt;br /&gt;
# Compare the mount namespaces (different views of the file system structure) between the centos container and the host, using &amp;lt;tt&amp;gt;ls -l /proc/self/ns/mnt&amp;lt;/tt&amp;gt;. Are they the same and if not, what are they (format: &amp;lt;tt&amp;gt;mnt:[????]&amp;lt;/tt&amp;gt;)? In particular, take a look at the root mount point (“&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;”) inside and outside the container (&amp;lt;tt&amp;gt;mount | grep &amp;quot;on / &amp;quot;&amp;lt;/tt&amp;gt;). You can always use two sessions (one in the container and one in the host) or &amp;lt;tt&amp;gt;tmux&amp;lt;/tt&amp;gt; as you feel convenient.&lt;br /&gt;
# With the &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; command, you can get an overview of all namespaces. Comparing the centos container and the host, &amp;lt;u&amp;gt;which namespaces are the same (shared) and which are different&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Inside the container, use the command &amp;lt;tt&amp;gt;id&amp;lt;/tt&amp;gt; to see what user you’re logged in as (uid, gid and group). Then &amp;lt;tt&amp;gt;ps -eo uid,gid,pid,command | grep sleep&amp;lt;/tt&amp;gt; inside the container and outside the container respectively. Are their outputs the same?&lt;br /&gt;
# Using the pid of “sleep” you have got outside the container above, find its pid namespace (&amp;lt;tt&amp;gt;sudo ls -l /proc/&amp;lt;pid&amp;gt;/ns/pid&amp;lt;/tt&amp;gt;, format &amp;lt;tt&amp;gt;pid:[????]&amp;lt;/tt&amp;gt;). Is it consistent with the &amp;lt;tt&amp;gt;lsns&amp;lt;/tt&amp;gt; output inside the container?&lt;br /&gt;
# From step 6, you have the individual namespaces used by the “sleep” container (no need to go inside the container again). Let’s check the network namespace (&amp;lt;tt&amp;gt;sudo nsenter -t &amp;lt;/tt&amp;gt;&amp;lt;pid&amp;gt;&amp;lt;tt&amp;gt; -n ip addr&amp;lt;/tt&amp;gt;). &lt;br /&gt;
#: Note that uid remapping is not enabled by default. So the user (uid) inside the container will be the same outside (which does not consider security).&lt;br /&gt;
# Now, make your own Docker container. Read the current [https://raw.githubusercontent.com/docker-library/hello-world/7ecae6978055d2fb6960e2a29d24a2af612e2716/amd64/hello-world/Dockerfile Dockerfile of hello-world]. Change it in a way that it is no longer from scratch but &#039;&#039;from &amp;lt;tt&amp;gt;hello-world &amp;lt;/tt&amp;gt;&#039;&#039;. Here we can avoid defining &amp;lt;tt&amp;gt;csimpleshell&amp;lt;/tt&amp;gt; as the default command as it works with a terminal for interaction (then it will inherit &amp;lt;tt&amp;gt;CMD&amp;lt;/tt&amp;gt; from &amp;lt;tt&amp;gt;hello-world&amp;lt;/tt&amp;gt;). Build a new image called &amp;lt;tt&amp;gt;csimpleshell&amp;lt;/tt&amp;gt; by doing the following: &lt;br /&gt;
#: &amp;lt;tt&amp;gt;mkdir anyname&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: copy your &amp;lt;tt&amp;gt;csimipleshell&amp;lt;/tt&amp;gt; and the Dockerfile of &amp;lt;tt&amp;gt;hello-world&amp;lt;/tt&amp;gt; into this directory&lt;br /&gt;
#: &amp;lt;tt&amp;gt;cd anyname&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: make necessary changes to the Dockerfile&lt;br /&gt;
#: &amp;lt;tt&amp;gt;docker build -t csimpleshell .&amp;lt;/tt&amp;gt;&lt;br /&gt;
# Run the new csimpleshell container (e.g., &amp;lt;tt&amp;gt;docker run -it csimpleshell /csimpleshell&amp;lt;/tt&amp;gt;). Depending on &amp;lt;tt&amp;gt;how you compiled csimpleshell&amp;lt;/tt&amp;gt;, check whether the container runs or if it does whether csimpleshell works as before. Try compiling csimpleshell statically (if it was dynamic) and repeat the steps.&lt;br /&gt;
# Edit the Dockerfile again and make it from “centos” instead of “hello-world”. Remove any reference to hello. Rebuild and run it. How is csimpleshell now? &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is there such a difference?&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24582</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24582"/>
		<updated>2023-10-25T02:08:53Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 8 | Tutorial 8]] || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 9 | Tutorial 9]] || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24581</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24581"/>
		<updated>2023-10-25T02:08:30Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 8 | Tutorial 8]] || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems W23: Tutorial 9 | Tutorial 9]] || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24580</id>
		<title>COMP3000 Operating Systems F23: Tutorial 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24580"/>
		<updated>2023-10-25T02:07:37Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-level_paging more about 5-level paging], if interested.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
WARNING: The commands and programs in this tutorial are potentially extremely dangerous and may result in crashes or loss of data. Additionally, questions may not work as expected on a machine other than the course VM. For that reason, you are strongly encouraged to do this tutorial on the provided OpenStack virtual machine.&lt;br /&gt;
&lt;br /&gt;
To get started, we will first examine the source code for &amp;lt;code&amp;gt;3000physicalview.c&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000memview2.c&amp;lt;/code&amp;gt;, both of which are in [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut8/3000physicalview.tar.gz 3000physicalview.tar.gz].&lt;br /&gt;
&lt;br /&gt;
==Tasks part A: Getting Started==&lt;br /&gt;
Compile &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; using the provided &amp;lt;code&amp;gt;Makefile&amp;lt;/code&amp;gt; (i.e., by running &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Insert &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; by running &amp;lt;code&amp;gt;make insert&amp;lt;/code&amp;gt;. Confirm that the module is inserted using &amp;lt;code&amp;gt;lsmod&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Examine the call to &amp;lt;code&amp;gt;copy_from_user()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;copy_to_user()&amp;lt;/code&amp;gt; on lines 120 and 132 of &amp;lt;code&amp;gt;3000physicalview.c&amp;lt;/code&amp;gt; (as also discussed in the lecture). Consider the following:&lt;br /&gt;
#* How are these functions different from &amp;lt;code&amp;gt;get_user()&amp;lt;/code&amp;gt;/&amp;lt;code&amp;gt;put_user()&amp;lt;/code&amp;gt; that we have seen in the previous tutorial?&lt;br /&gt;
#* Why are these functions necessary? Couldn&#039;t we just access the userspace address directly? What could happen if we did?&lt;br /&gt;
# &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; exposes its API to userspace in the form of an &amp;lt;code&amp;gt;ioctl(2)&amp;lt;/code&amp;gt; call. Consider the following:&lt;br /&gt;
#* What is an ioctl? How is it different from a read or write system call? Hint: check &amp;lt;code&amp;gt;man 2 ioctl&amp;lt;/code&amp;gt;.&lt;br /&gt;
#* How does &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; implement its ioctl? What arguments does it take?&lt;br /&gt;
#* How does &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; call the ioctl? What arguments does it pass to the ioctl?&lt;br /&gt;
# Which function does the virtual-to-physical translation? What type is &amp;lt;code&amp;gt;current-&amp;gt;mm&amp;lt;/code&amp;gt;? How does it give you the address of the &amp;lt;code&amp;gt;pgd&amp;lt;/code&amp;gt;? Recall the page table walk explained in the lecture and see how it’s reflected in this function (writing it down is optional).&lt;br /&gt;
# Once you’ve got the page frame number (pfn), how is the physical address (phys) calculated? Describe in words.&lt;br /&gt;
&lt;br /&gt;
==Tasks part B: Examining Physical Memory Mappings==&lt;br /&gt;
# With &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; inserted, run &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; and examine the output. Note that it presents virtual memory addresses on the left, and physical addresses on the right. Are these mappings consistent with what you expected (e.g., in terms of patterns)?&lt;br /&gt;
# Compare &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; with &amp;lt;code&amp;gt;3000memview&amp;lt;/code&amp;gt; from Tutorial 2. What is similar about their code, and what is different? How similar is their output?&lt;br /&gt;
# Do you notice a pattern in the virtual addresses of &amp;lt;code&amp;gt;buf[i]&amp;lt;/code&amp;gt;? Is this same pattern present in the physical addresses? Why or why not?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; a few more times and consider the following:&lt;br /&gt;
#* Are the virtual addresses the same or different between runs? How about physical addresses?&lt;br /&gt;
#* Some physical addresses don&#039;t seem to be changing between runs. Which ones? Why do you think this might be the case?&lt;br /&gt;
# Force the kernel to drop the virtual memory cache using &amp;lt;code&amp;gt;sync &amp;amp;&amp;amp; echo 3 | sudo tee /proc/sys/vm/drop_caches&amp;lt;/code&amp;gt;. Run &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt; one more time and note that the physical addresses that stayed the same previously have now changed. What do you think just happened?&lt;br /&gt;
&lt;br /&gt;
==Tasks part C: Using &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt; to Monitor &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt;== &lt;br /&gt;
Now recall what you tried with eBPF in Tutorial 7 (where you applied the fix if applicable). We can also do something similar to watch the interaction between &amp;lt;code&amp;gt;3000physicalview&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000memview2&amp;lt;/code&amp;gt;. &lt;br /&gt;
Note: No in-depth understanding of eBPF is expected in this course. You only need to understand what is involved and discussed. Feel free to read more if interested.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Use the following &amp;quot;one-liner&amp;quot; (as it is just a one-line string within the single quotation marks) in a new terminal session first and in the orginal one run &amp;lt;code&amp;gt;./3000memview2&amp;lt;/code&amp;gt; as above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;code&amp;gt;sudo bpftrace -e &#039;tracepoint:syscalls:sys_enter_ioctl { printf(&amp;quot;%s: fd=%d; cmd=%d; arg=%ld \n&amp;quot;, comm, args-&amp;gt;fd, args-&amp;gt;cmd, args-&amp;gt;arg); }&#039; | grep 3000memview2&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What does this one-liner do? As always, you can check &amp;lt;code&amp;gt;man bpftrace&amp;lt;/code&amp;gt; if needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;(&amp;lt;b&amp;gt;Optional&amp;lt;/b&amp;gt; in the submission but you should do it) It seems the command above does not show useful information as the third argument is actually a pointer. So, to be able to show the two arguments &amp;lt;code&amp;gt;virt&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;phys&amp;lt;/code&amp;gt; defined in &amp;lt;code&amp;gt;3000physicalview.h&amp;lt;/code&amp;gt;, you will need to create a *.bt file.&lt;br /&gt;
Refer to &amp;lt;code&amp;gt;/usr/sbin/*.bt&amp;lt;/code&amp;gt; and convert the one-liner above into something like &amp;lt;code&amp;gt;snoop3000physicalview.bt&amp;lt;/code&amp;gt;, so that when it runs it prints the &amp;lt;code&amp;gt;virt&amp;lt;/code&amp;gt; passed in and the &amp;lt;code&amp;gt;phys&amp;lt;/code&amp;gt; that is returned.&lt;br /&gt;
The code will be posted and explained.&lt;br /&gt;
&amp;lt;br&amp;gt; Note: if you choose to directly include the header file you need to create a copy and remove the &amp;lt;code&amp;gt;MODULE_*&amp;lt;/code&amp;gt; macros. Otherwise, you can simply include the struct definition.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24579</id>
		<title>COMP3000 Operating Systems F23: Tutorial 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24579"/>
		<updated>2023-10-25T01:56:05Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-level_paging more about 5-level paging], if interested.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
WARNING: The commands and programs in this tutorial are potentially extremely dangerous and may result in crashes or loss of data. Additionally, questions may not work as expected on a machine other than the course VM. For that reason, you are strongly encouraged to do this tutorial on the provided OpenStack virtual machine.&lt;br /&gt;
&lt;br /&gt;
To get started, we will first examine the source code for &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2.c&amp;lt;/tt&amp;gt;, both of which are in [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut8/3000physicalview.tar.gz 3000physicalview.tar.gz].&lt;br /&gt;
&lt;br /&gt;
==Tasks part A: Getting Started==&lt;br /&gt;
Compile &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; using the provided &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt; (i.e., by running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Insert &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; by running &amp;lt;tt&amp;gt;make insert&amp;lt;/tt&amp;gt;. Confirm that the module is inserted using &amp;lt;tt&amp;gt;lsmod&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Examine the call to &amp;lt;tt&amp;gt;copy_from_user()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;copy_to_user()&amp;lt;/tt&amp;gt; on lines 120 and 132 of &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; (as also discussed in the lecture). Consider the following:&lt;br /&gt;
#* How are these functions different from &amp;lt;tt&amp;gt;get_user()&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;put_user()&amp;lt;/tt&amp;gt; that we have seen in the previous tutorial?&lt;br /&gt;
#* Why are these functions necessary? Couldn&#039;t we just access the userspace address directly? What could happen if we did?&lt;br /&gt;
# &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; exposes its API to userspace in the form of an &amp;lt;tt&amp;gt;ioctl(2)&amp;lt;/tt&amp;gt; call. Consider the following:&lt;br /&gt;
#* What is an ioctl? How is it different from a read or write system call? Hint: check &amp;lt;tt&amp;gt;man 2 ioctl&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; implement its ioctl? What arguments does it take?&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; call the ioctl? What arguments does it pass to the ioctl?&lt;br /&gt;
# Which function does the virtual-to-physical translation? What type is &amp;lt;tt&amp;gt;current-&amp;gt;mm&amp;lt;/tt&amp;gt;? How does it give you the address of the &amp;lt;tt&amp;gt;pgd&amp;lt;/tt&amp;gt;? Recall the page table walk explained in the lecture and see how it’s reflected in this function (writing it down is optional).&lt;br /&gt;
# Once you’ve got the page frame number (pfn), how is the physical address (phys) calculated? Describe in words.&lt;br /&gt;
&lt;br /&gt;
==Tasks part B: Examining Physical Memory Mappings==&lt;br /&gt;
# With &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; inserted, run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; and examine the output. Note that it presents virtual memory addresses on the left, and physical addresses on the right. Are these mappings consistent with what you expected (e.g., in terms of patterns)?&lt;br /&gt;
# Compare &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;3000memview&amp;lt;/tt&amp;gt; from Tutorial 2. What is similar about their code, and what is different? How similar is their output?&lt;br /&gt;
# Do you notice a pattern in the virtual addresses of &amp;lt;tt&amp;gt;buf[i]&amp;lt;/tt&amp;gt;? Is this same pattern present in the physical addresses? Why or why not?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; a few more times and consider the following:&lt;br /&gt;
#* Are the virtual addresses the same or different between runs? How about physical addresses?&lt;br /&gt;
#* Some physical addresses don&#039;t seem to be changing between runs. Which ones? Why do you think this might be the case?&lt;br /&gt;
# Force the kernel to drop the virtual memory cache using &amp;lt;tt&amp;gt;sync &amp;amp;&amp;amp; echo 3 | sudo tee /proc/sys/vm/drop_caches&amp;lt;/tt&amp;gt;. Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; one more time and note that the physical addresses that stayed the same previously have now changed. What do you think just happened?&lt;br /&gt;
&lt;br /&gt;
==Tasks part C: Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to Monitor &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;== &lt;br /&gt;
Now recall what you tried with eBPF in Tutorial 7 (where you applied the fix if applicable). We can also do something similar to watch the interaction between &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;. &lt;br /&gt;
Note: No in-depth understanding of eBPF is expected in this course. You only need to understand what is involved and discussed. Feel free to read more if interested.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Use the following &amp;quot;one-liner&amp;quot; (as it is just a one-line string within the single quotation marks) in a new terminal session first and in the orginal one run &amp;lt;tt&amp;gt;./3000memview2&amp;lt;/tt&amp;gt; as above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;tt&amp;gt;sudo bpftrace -e &#039;tracepoint:syscalls:sys_enter_ioctl { printf(&amp;quot;%s: fd=%d; cmd=%d; arg=%ld \n&amp;quot;, comm, args-&amp;gt;fd, args-&amp;gt;cmd, args-&amp;gt;arg); }&#039; | grep 3000memview2&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What does this one-liner do? As always, you can check &amp;lt;tt&amp;gt;man bpftrace&amp;lt;/tt&amp;gt; if needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;(&amp;lt;b&amp;gt;Optional&amp;lt;/b&amp;gt; in the submission but you should do it) It seems the command above does not show useful information as the third argument is actually a pointer. So, to be able to show the two arguments &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;3000physicalview.h&amp;lt;/tt&amp;gt;, you will need to create a *.bt file.&lt;br /&gt;
Refer to &amp;lt;tt&amp;gt;/usr/sbin/*.bt&amp;lt;/tt&amp;gt; and convert the one-liner above into something like &amp;lt;tt&amp;gt;snoop3000physicalview.bt&amp;lt;/tt&amp;gt;, so that when it runs it prints the &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; passed in and the &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; that is returned.&lt;br /&gt;
The code will be posted and explained.&lt;br /&gt;
&amp;lt;br&amp;gt; Note: if you choose to directly include the header file you need to create a copy and remove the &amp;lt;tt&amp;gt;MODULE_*&amp;lt;/tt&amp;gt; macros. Otherwise, you can simply include the struct definition.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24578</id>
		<title>COMP3000 Operating Systems F23: Tutorial 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24578"/>
		<updated>2023-10-25T01:54:09Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* General Instructions (same for all tutorials) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-level_paging more about 5-level paging], if interested.&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
WARNING: The commands and programs in this tutorial are potentially extremely dangerous and may result in crashes or loss of data. Additionally, questions may not work as expected on a machine other than the course VM. For that reason, you are strongly encouraged to do this tutorial on the provided OpenStack virtual machine.&lt;br /&gt;
&lt;br /&gt;
To get started, we will first examine the source code for &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2.c&amp;lt;/tt&amp;gt;, both of which are in [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut8/3000physicalview.tar.gz 3000physicalview.tar.gz].&lt;br /&gt;
&lt;br /&gt;
==Tasks part A: Getting Started==&lt;br /&gt;
Compile &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; using the provided &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt; (i.e., by running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Insert &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; by running &amp;lt;tt&amp;gt;make insert&amp;lt;/tt&amp;gt;. Confirm that the module is inserted using &amp;lt;tt&amp;gt;lsmod&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Examine the call to &amp;lt;tt&amp;gt;copy_from_user()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;copy_to_user()&amp;lt;/tt&amp;gt; on lines 120 and 132 of &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; (as also discussed in the lecture). Consider the following:&lt;br /&gt;
#* How are these functions different from &amp;lt;tt&amp;gt;get_user()&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;put_user()&amp;lt;/tt&amp;gt; that we have seen in the previous tutorial?&lt;br /&gt;
#* Why are these functions necessary? Couldn&#039;t we just access the userspace address directly? What could happen if we did?&lt;br /&gt;
# &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; exposes its API to userspace in the form of an &amp;lt;tt&amp;gt;ioctl(2)&amp;lt;/tt&amp;gt; call. Consider the following:&lt;br /&gt;
#* What is an ioctl? How is it different from a read or write system call? Hint: check &amp;lt;tt&amp;gt;man 2 ioctl&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; implement its ioctl? What arguments does it take?&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; call the ioctl? What arguments does it pass to the ioctl?&lt;br /&gt;
# Which function does the virtual-to-physical translation? What type is &amp;lt;tt&amp;gt;current-&amp;gt;mm&amp;lt;/tt&amp;gt;? How does it give you the address of the &amp;lt;tt&amp;gt;pgd&amp;lt;/tt&amp;gt;? Recall the page table walk explained in the lecture and see how it’s reflected in this function (writing it down is optional).&lt;br /&gt;
# Once you’ve got the page frame number (pfn), how is the physical address (phys) calculated? Describe in words.&lt;br /&gt;
&lt;br /&gt;
==Tasks part B: Examining Physical Memory Mappings==&lt;br /&gt;
# With &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; inserted, run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; and examine the output. Note that it presents virtual memory addresses on the left, and physical addresses on the right. Are these mappings consistent with what you expected (e.g., in terms of patterns)?&lt;br /&gt;
# Compare &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;3000memview&amp;lt;/tt&amp;gt; from Tutorial 2. What is similar about their code, and what is different? How similar is their output?&lt;br /&gt;
# Do you notice a pattern in the virtual addresses of &amp;lt;tt&amp;gt;buf[i]&amp;lt;/tt&amp;gt;? Is this same pattern present in the physical addresses? Why or why not?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; a few more times and consider the following:&lt;br /&gt;
#* Are the virtual addresses the same or different between runs? How about physical addresses?&lt;br /&gt;
#* Some physical addresses don&#039;t seem to be changing between runs. Which ones? Why do you think this might be the case?&lt;br /&gt;
# Force the kernel to drop the virtual memory cache using &amp;lt;tt&amp;gt;sync &amp;amp;&amp;amp; echo 3 | sudo tee /proc/sys/vm/drop_caches&amp;lt;/tt&amp;gt;. Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; one more time and note that the physical addresses that stayed the same previously have now changed. What do you think just happened?&lt;br /&gt;
&lt;br /&gt;
==Tasks part C: Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to Monitor &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;== &lt;br /&gt;
Now recall what you tried with eBPF in Tutorial 7 (where you applied the fix if applicable). We can also do something similar to watch the interaction between &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;. &lt;br /&gt;
Note: No in-depth understanding of eBPF is expected in this course. You only need to understand what is involved and discussed. Feel free to read more if interested.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Use the following &amp;quot;one-liner&amp;quot; (as it is just a one-line string within the single quotation marks) in a new terminal session first and in the orginal one run &amp;lt;tt&amp;gt;./3000memview2&amp;lt;/tt&amp;gt; as above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;tt&amp;gt;sudo bpftrace -e &#039;tracepoint:syscalls:sys_enter_ioctl { printf(&amp;quot;%s: fd=%d; cmd=%d; arg=%ld \n&amp;quot;, comm, args-&amp;gt;fd, args-&amp;gt;cmd, args-&amp;gt;arg); }&#039; | grep 3000memview2&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What does this one-liner do? As always, you can check &amp;lt;tt&amp;gt;man bpftrace&amp;lt;/tt&amp;gt; if needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;(&amp;lt;b&amp;gt;Optional&amp;lt;/b&amp;gt; in the submission but you should do it) It seems the command above does not show useful information as the third argument is actually a pointer. So, to be able to show the two arguments &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;3000physicalview.h&amp;lt;/tt&amp;gt;, you will need to create a *.bt file.&lt;br /&gt;
Refer to &amp;lt;tt&amp;gt;/usr/sbin/*.bt&amp;lt;/tt&amp;gt; and convert the one-liner above into something like &amp;lt;tt&amp;gt;snoop3000physicalview.bt&amp;lt;/tt&amp;gt;, so that when it runs it prints the &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; passed in and the &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; that is returned.&lt;br /&gt;
The code will be posted and explained.&lt;br /&gt;
&amp;lt;br&amp;gt; Note: if you choose to directly include the header file you need to create a copy and remove the &amp;lt;tt&amp;gt;MODULE_*&amp;lt;/tt&amp;gt; macros. Otherwise, you can simply include the struct definition.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24577</id>
		<title>COMP3000 Operating Systems F23: Tutorial 8</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_8&amp;diff=24577"/>
		<updated>2023-10-25T01:50:57Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-lev...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you’ll be learning about how virtual addresses are mapped to physical addresses (the address translation) and continue to use kernel modules to extract information that only the kernel has access to. In particular, the kernel module performs a 5-level page table walk to find out the physical address corresponding to a userspace virtual address. In addition to what was discussed in the class, You can also read [https://en.wikipedia.org/wiki/Intel_5-level_paging more about 5-level paging], if interested.&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Introduction==&lt;br /&gt;
WARNING: The commands and programs in this tutorial are potentially extremely dangerous and may result in crashes or loss of data. Additionally, questions may not work as expected on a machine other than the course VM. For that reason, you are strongly encouraged to do this tutorial on the provided OpenStack virtual machine.&lt;br /&gt;
&lt;br /&gt;
To get started, we will first examine the source code for &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2.c&amp;lt;/tt&amp;gt;, both of which are in [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut8/3000physicalview.tar.gz 3000physicalview.tar.gz].&lt;br /&gt;
&lt;br /&gt;
==Tasks part A: Getting Started==&lt;br /&gt;
Compile &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; using the provided &amp;lt;tt&amp;gt;Makefile&amp;lt;/tt&amp;gt; (i.e., by running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Insert &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; by running &amp;lt;tt&amp;gt;make insert&amp;lt;/tt&amp;gt;. Confirm that the module is inserted using &amp;lt;tt&amp;gt;lsmod&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Examine the call to &amp;lt;tt&amp;gt;copy_from_user()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;copy_to_user()&amp;lt;/tt&amp;gt; on lines 120 and 132 of &amp;lt;tt&amp;gt;3000physicalview.c&amp;lt;/tt&amp;gt; (as also discussed in the lecture). Consider the following:&lt;br /&gt;
#* How are these functions different from &amp;lt;tt&amp;gt;get_user()&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;put_user()&amp;lt;/tt&amp;gt; that we have seen in the previous tutorial?&lt;br /&gt;
#* Why are these functions necessary? Couldn&#039;t we just access the userspace address directly? What could happen if we did?&lt;br /&gt;
# &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; exposes its API to userspace in the form of an &amp;lt;tt&amp;gt;ioctl(2)&amp;lt;/tt&amp;gt; call. Consider the following:&lt;br /&gt;
#* What is an ioctl? How is it different from a read or write system call? Hint: check &amp;lt;tt&amp;gt;man 2 ioctl&amp;lt;/tt&amp;gt;.&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; implement its ioctl? What arguments does it take?&lt;br /&gt;
#* How does &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; call the ioctl? What arguments does it pass to the ioctl?&lt;br /&gt;
# Which function does the virtual-to-physical translation? What type is &amp;lt;tt&amp;gt;current-&amp;gt;mm&amp;lt;/tt&amp;gt;? How does it give you the address of the &amp;lt;tt&amp;gt;pgd&amp;lt;/tt&amp;gt;? Recall the page table walk explained in the lecture and see how it’s reflected in this function (writing it down is optional).&lt;br /&gt;
# Once you’ve got the page frame number (pfn), how is the physical address (phys) calculated? Describe in words.&lt;br /&gt;
&lt;br /&gt;
==Tasks part B: Examining Physical Memory Mappings==&lt;br /&gt;
# With &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; inserted, run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; and examine the output. Note that it presents virtual memory addresses on the left, and physical addresses on the right. Are these mappings consistent with what you expected (e.g., in terms of patterns)?&lt;br /&gt;
# Compare &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; with &amp;lt;tt&amp;gt;3000memview&amp;lt;/tt&amp;gt; from Tutorial 2. What is similar about their code, and what is different? How similar is their output?&lt;br /&gt;
# Do you notice a pattern in the virtual addresses of &amp;lt;tt&amp;gt;buf[i]&amp;lt;/tt&amp;gt;? Is this same pattern present in the physical addresses? Why or why not?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; a few more times and consider the following:&lt;br /&gt;
#* Are the virtual addresses the same or different between runs? How about physical addresses?&lt;br /&gt;
#* Some physical addresses don&#039;t seem to be changing between runs. Which ones? Why do you think this might be the case?&lt;br /&gt;
# Force the kernel to drop the virtual memory cache using &amp;lt;tt&amp;gt;sync &amp;amp;&amp;amp; echo 3 | sudo tee /proc/sys/vm/drop_caches&amp;lt;/tt&amp;gt;. Run &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt; one more time and note that the physical addresses that stayed the same previously have now changed. What do you think just happened?&lt;br /&gt;
&lt;br /&gt;
==Tasks part C: Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to Monitor &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;== &lt;br /&gt;
Now recall what you tried with eBPF in Tutorial 7 (where you applied the fix if applicable). We can also do something similar to watch the interaction between &amp;lt;tt&amp;gt;3000physicalview&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000memview2&amp;lt;/tt&amp;gt;. &lt;br /&gt;
Note: No in-depth understanding of eBPF is expected in this course. You only need to understand what is involved and discussed. Feel free to read more if interested.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;Use the following &amp;quot;one-liner&amp;quot; (as it is just a one-line string within the single quotation marks) in a new terminal session first and in the orginal one run &amp;lt;tt&amp;gt;./3000memview2&amp;lt;/tt&amp;gt; as above:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;tt&amp;gt;sudo bpftrace -e &#039;tracepoint:syscalls:sys_enter_ioctl { printf(&amp;quot;%s: fd=%d; cmd=%d; arg=%ld \n&amp;quot;, comm, args-&amp;gt;fd, args-&amp;gt;cmd, args-&amp;gt;arg); }&#039; | grep 3000memview2&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What does this one-liner do? As always, you can check &amp;lt;tt&amp;gt;man bpftrace&amp;lt;/tt&amp;gt; if needed.&amp;lt;/li&amp;gt;&lt;br /&gt;
  &amp;lt;li&amp;gt;(&amp;lt;b&amp;gt;Optional&amp;lt;/b&amp;gt; in the submission but you should do it) It seems the command above does not show useful information as the third argument is actually a pointer. So, to be able to show the two arguments &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; defined in &amp;lt;tt&amp;gt;3000physicalview.h&amp;lt;/tt&amp;gt;, you will need to create a *.bt file.&lt;br /&gt;
Refer to &amp;lt;tt&amp;gt;/usr/sbin/*.bt&amp;lt;/tt&amp;gt; and convert the one-liner above into something like &amp;lt;tt&amp;gt;snoop3000physicalview.bt&amp;lt;/tt&amp;gt;, so that when it runs it prints the &amp;lt;tt&amp;gt;virt&amp;lt;/tt&amp;gt; passed in and the &amp;lt;tt&amp;gt;phys&amp;lt;/tt&amp;gt; that is returned.&lt;br /&gt;
The code will be posted and explained.&lt;br /&gt;
&amp;lt;br&amp;gt; Note: if you choose to directly include the header file you need to create a copy and remove the &amp;lt;tt&amp;gt;MODULE_*&amp;lt;/tt&amp;gt; macros. Otherwise, you can simply include the struct definition.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24576</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24576"/>
		<updated>2023-10-25T01:50:50Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 8 | Tutorial 8]] || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24575</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24575"/>
		<updated>2023-10-25T01:50:23Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems W23: Tutorial 8 | Tutorial 8]] || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24574</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24574"/>
		<updated>2023-10-25T01:44:44Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Using bpftrace to monitor kernel module events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt;? Remember you can get output from &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;cat&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;dd&amp;lt;/code&amp;gt;. If you use &amp;lt;code&amp;gt;cat&amp;lt;/code&amp;gt;, make sure to pipe it to &amp;lt;code&amp;gt;less&amp;lt;/code&amp;gt;!&lt;br /&gt;
#* &amp;lt;code&amp;gt;cp /dev/urandom f1&amp;lt;/code&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;code&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/code&amp;gt;&lt;br /&gt;
#* &amp;lt;code&amp;gt;sudo mknod f3 c 1 9&amp;lt;/code&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;mkfifo&amp;lt;/code&amp;gt;. Use them to simulate &amp;lt;code&amp;gt;ls | wc&amp;lt;/code&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;code&amp;gt;/dev/tty&amp;lt;/code&amp;gt; (Hint: consider how you did something similar with &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; above). You can name it &amp;lt;code&amp;gt;mytty&amp;lt;/code&amp;gt;. Examine its characteristics using &amp;lt;code&amp;gt;stty --file=mytty&amp;lt;/code&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;code&amp;gt;stty --help&amp;lt;/code&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;code&amp;gt;task_struct&amp;lt;/code&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;code&amp;gt;task_struct&amp;lt;/code&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;code&amp;gt;sudo insmod simple.ko&amp;lt;/code&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;)? If so, where? (Hint: search in &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;code&amp;gt;printk()&amp;lt;/code&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;code&amp;gt;current&amp;lt;/code&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;code&amp;gt;/dev/describe&amp;lt;/code&amp;gt; rather than &amp;lt;code&amp;gt;/dev/newgetpid&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Make &amp;lt;code&amp;gt;/dev/describe&amp;lt;/code&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: the following is optional but you are encouraged to do it, as it can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;code&amp;gt;Could not resolve symbol&amp;lt;/code&amp;gt;&amp;quot; when using &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt;: Just &amp;lt;code&amp;gt;wget&amp;lt;/code&amp;gt; [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;code&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;code&amp;gt;sudo ./kmsnoop.bt&amp;lt;/code&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;code&amp;gt;sudo bpftrace -l | grep&amp;lt;/code&amp;gt; for your needed kernel functions (e.g.,&amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24573</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24573"/>
		<updated>2023-10-25T01:43:35Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt;? Remember you can get output from &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;cat&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;dd&amp;lt;/code&amp;gt;. If you use &amp;lt;code&amp;gt;cat&amp;lt;/code&amp;gt;, make sure to pipe it to &amp;lt;code&amp;gt;less&amp;lt;/code&amp;gt;!&lt;br /&gt;
#* &amp;lt;code&amp;gt;cp /dev/urandom f1&amp;lt;/code&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;code&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/code&amp;gt;&lt;br /&gt;
#* &amp;lt;code&amp;gt;sudo mknod f3 c 1 9&amp;lt;/code&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;mkfifo&amp;lt;/code&amp;gt;. Use them to simulate &amp;lt;code&amp;gt;ls | wc&amp;lt;/code&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;code&amp;gt;mknod&amp;lt;/code&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;code&amp;gt;/dev/tty&amp;lt;/code&amp;gt; (Hint: consider how you did something similar with &amp;lt;code&amp;gt;/dev/urandom&amp;lt;/code&amp;gt; above). You can name it &amp;lt;code&amp;gt;mytty&amp;lt;/code&amp;gt;. Examine its characteristics using &amp;lt;code&amp;gt;stty --file=mytty&amp;lt;/code&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;code&amp;gt;stty --help&amp;lt;/code&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;code&amp;gt;task_struct&amp;lt;/code&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;code&amp;gt;task_struct&amp;lt;/code&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;code&amp;gt;sudo insmod simple.ko&amp;lt;/code&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;)? If so, where? (Hint: search in &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;code&amp;gt;/dev/ones&amp;lt;/code&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;code&amp;gt;printk()&amp;lt;/code&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;code&amp;gt;current&amp;lt;/code&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;code&amp;gt;/dev/describe&amp;lt;/code&amp;gt; rather than &amp;lt;code&amp;gt;/dev/newgetpid&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Make &amp;lt;code&amp;gt;/dev/describe&amp;lt;/code&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;code&amp;gt;Could not resolve symbol&amp;lt;/code&amp;gt;&amp;quot; when using &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;code&amp;gt;bpftrace&amp;lt;/code&amp;gt;: Just &amp;lt;code&amp;gt;wget&amp;lt;/code&amp;gt; [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;code&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;code&amp;gt;sudo ./kmsnoop.bt&amp;lt;/code&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;code&amp;gt;sudo bpftrace -l | grep&amp;lt;/code&amp;gt; for your needed kernel functions (e.g.,&amp;lt;code&amp;gt;printk&amp;lt;/code&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24572</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24572"/>
		<updated>2023-10-25T01:41:07Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Using bpftrace to monitor kernel module events */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24571</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24571"/>
		<updated>2023-10-25T01:39:47Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks part D: Getting process information from a module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24570</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24570"/>
		<updated>2023-10-25T01:38:48Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks part C: A character device kernel module (driver) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24569</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24569"/>
		<updated>2023-10-25T01:37:48Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks part B: A simple kernel module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7_Not_Using_SCS_OpenStack&amp;diff=24568</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7_Not_Using_SCS_OpenStack&amp;diff=24568"/>
		<updated>2023-10-25T01:37:02Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;If you are not using our course VM for some reason, you might encounter problems and you can refer to the instructions below. Although they are by no means comprehensve to solve the problems, they can in many cases and serve as pointers about where to look. ==Modules fail to build== If you see errors (not just warnings) after running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt; and no &amp;lt;tt&amp;gt;.ko&amp;lt;/tt&amp;gt; file is produced, you may have installed a version of Ubuntu that is too minimal. But you can fix it by i...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are not using our course VM for some reason, you might encounter problems and you can refer to the instructions below. Although they are by no means comprehensve to solve the problems, they can in many cases and serve as pointers about where to look.&lt;br /&gt;
==Modules fail to build==&lt;br /&gt;
If you see errors (not just warnings) after running &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt; and no &amp;lt;tt&amp;gt;.ko&amp;lt;/tt&amp;gt; file is produced, you may have installed a version of Ubuntu that is too minimal. But you can fix it by installing the right packages. Do the following:&lt;br /&gt;
 sudo apt update&lt;br /&gt;
&lt;br /&gt;
 sudo apt dist-upgrade&lt;br /&gt;
 &lt;br /&gt;
 sudo apt install build-essential&lt;br /&gt;
 &lt;br /&gt;
 sudo apt clean&lt;br /&gt;
&lt;br /&gt;
If your build failed before doing this and again after, delete the downloaded code and unpack the zip file again.&lt;br /&gt;
&lt;br /&gt;
==Disk full==&lt;br /&gt;
If you find your disk space filled up, you can use the following command to pinpoint the top 20 largest files (no need to understand the specifics unless you are curious):&lt;br /&gt;
&lt;br /&gt;
 sudo find / -type f -exec du -h {} 2&amp;gt;&amp;amp;- + | sort -rh | head -20&lt;br /&gt;
&lt;br /&gt;
Or including directories:&lt;br /&gt;
&lt;br /&gt;
 sudo du -h / 2&amp;gt;&amp;amp;- | sort -rh | head -20&lt;br /&gt;
&lt;br /&gt;
==Command &#039;bpftrace&#039; not found==&lt;br /&gt;
You may be able to fix this by installing the &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; package (just the frontend and the examples):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install bpftrace&lt;br /&gt;
&lt;br /&gt;
Use its equivalent on other Linux distributions.&lt;br /&gt;
&lt;br /&gt;
Note: it could be much worse than this, e.g., not having the right kernel compiled with eBPF support, for which there won&#039;t be a quick fix.&lt;br /&gt;
In such cases, you are suggested to move to the course VM or choose a different VM of your own.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24567</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24567"/>
		<updated>2023-10-25T01:36:54Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Important Tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems F23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24566</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24566"/>
		<updated>2023-10-25T01:31:41Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Important Tips */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* &#039;&#039;&#039;Definitely do not under any circumstances attempt this on your own system. This is your last warning.&#039;&#039;&#039;&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems W23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24565</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24565"/>
		<updated>2023-10-25T01:31:13Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* General Instructions (same for all tutorials) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* Definitely do not under any circumstances attempt this on your own system. This is your last warning.&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems W23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24564</id>
		<title>COMP3000 Operating Systems F23: Tutorial 7</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_7&amp;diff=24564"/>
		<updated>2023-10-25T01:30:50Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;In this tutorial you&amp;#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.  ==General Instructions (same for all tutorials)==  &amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt; Click on Expand to view. &amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt; Tutorials are graded based on pa...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you&#039;ll be learning about special files and Linux kernel modules, part of which are device drivers. You’ll create several kernel modules and see how to interact with device drivers using special files (e.g., character device) and their file operations as an interface.&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Important Tips==&lt;br /&gt;
* There is a chance your VM will crash or your ssh session will become unresponsive when messing with the kernel. To recover, you can reboot your VM from the OpenStack web console.&lt;br /&gt;
* Definitely do not under any circumstances attempt this on your own system. This is your last warning.&lt;br /&gt;
* Remember to recompile and insert your module after making changes.&lt;br /&gt;
* Work incrementally and be prepared for your system to crash.&lt;br /&gt;
* It might be wise to code on your own computer and use scp or sshfs to transfer the files to your VM.&lt;br /&gt;
* https://elixir.bootlin.com/linux/latest/source is a great resource for learning about kernel functions and data structures.&lt;br /&gt;
&lt;br /&gt;
Note: although it&#039;s highly recommended that you use the openstack instance, if you cannot for a reason, or if you encounter other issues, check out [[COMP3000 Operating Systems W23: Tutorial 7 Not Using SCS OpenStack | these instructions]] to see if they help.&lt;br /&gt;
&lt;br /&gt;
==Special Files==&lt;br /&gt;
Before you start, review what you have learned about special files and think about the following questions (no need to answer them): 1) What does a special file represent and what backs it up? 2) Can you have multiple special files that are somehow &amp;quot;the same&amp;quot;? What does it mean to &amp;quot;copy&amp;quot; a special file? 3) How are named pipes different from unnamed pipes and what are their similarities? Take this opportunity to deepen your understanding of special files to prepare you for working with device drivers that support such special files.&lt;br /&gt;
&lt;br /&gt;
===Tasks part A: Understanding special files===&lt;br /&gt;
# Try the following commands as a non-privileged user. What does each do? How do the files f1-f3 compare? How do they compare to &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt;? Remember you can get output from &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; using &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;dd&amp;lt;/tt&amp;gt;. If you use &amp;lt;tt&amp;gt;cat&amp;lt;/tt&amp;gt;, make sure to pipe it to &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt;!&lt;br /&gt;
#* &amp;lt;tt&amp;gt;cp /dev/urandom f1&amp;lt;/tt&amp;gt; 		(hit Ctrl+C right away to avoid a huge file)&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo cp -a /dev/urandom f2&amp;lt;/tt&amp;gt;&lt;br /&gt;
#* &amp;lt;tt&amp;gt;sudo mknod f3 c 1 9&amp;lt;/tt&amp;gt;&lt;br /&gt;
#: Note: If you see any command running for more than a few seconds, hit Ctrl+C right away, check the produced file (often it’s very large) and delete it if not needed.&lt;br /&gt;
# Make named pipes using &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mkfifo&amp;lt;/tt&amp;gt;. Use them to simulate &amp;lt;tt&amp;gt;ls | wc&amp;lt;/tt&amp;gt; using just the &#039;&amp;gt;&#039; and &#039;&amp;lt;&#039; operators.&lt;br /&gt;
# Use &amp;lt;tt&amp;gt;mknod&amp;lt;/tt&amp;gt; to make a copy of your current terminal&#039;s tty - &amp;lt;tt&amp;gt;/dev/tty&amp;lt;/tt&amp;gt; (Hint: consider how you did something similar with &amp;lt;tt&amp;gt;/dev/urandom&amp;lt;/tt&amp;gt; above). You can name it &amp;lt;tt&amp;gt;mytty&amp;lt;/tt&amp;gt;. Examine its characteristics using &amp;lt;tt&amp;gt;stty --file=mytty&amp;lt;/tt&amp;gt;. Do the same for the original tty. &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;stty --help&amp;lt;/tt&amp;gt; to see what you can do with stty. Try disabling local echo. How does the shell behave with echo disabled? How can you restore echo without logging out and back in? Recall we did this in the class.&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules==&lt;br /&gt;
In this part of the tutorial you will be building and installing kernel modules. You will need root access to install kernel modules.&lt;br /&gt;
&lt;br /&gt;
It is &#039;&#039;&#039;highly recommended&#039;&#039;&#039; that you use a comp3000 openstack instance for the exercises below for two reasons. First, you may have difficulties compiling kernel modules on other systems. Second, these operations are potentially dangerous, and mistakes could &#039;&#039;&#039;destroy all data&#039;&#039;&#039; on the Linux system. Consider yourself warned!&lt;br /&gt;
&lt;br /&gt;
Before you start, review what you have learned about kernel modules and device drivers, and think about the following questions (no need to answer them): 1) How does the source of kernel modules differ from C programs? 2) How does building kernel modules differ from building userspace C programs? 3) How does invoking the file operations (e.g., read/write) of a special file trigger corresponding functions in a device driver?&lt;br /&gt;
&lt;br /&gt;
You will learn how you can access and manipulate kernel data structures and call kernel functions in a kernel module. You will also understand how processes are represented by &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt;&#039;s in the Linux kernel, what kind of information is stored in a task struct, and how to access the &amp;lt;tt&amp;gt;task_struct&amp;lt;/tt&amp;gt; of a process.&lt;br /&gt;
&lt;br /&gt;
===Tasks part B: A simple kernel module===&lt;br /&gt;
Download the source for this [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/simple.tar.gz simple module], unpack, and build it by typing &amp;quot;&amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt;&amp;quot;. You can safely ignore the warning of &amp;quot;Skipping BTF generation...&amp;quot;.&lt;br /&gt;
# Install the module using &amp;quot;&amp;lt;tt&amp;gt;sudo insmod simple.ko&amp;lt;/tt&amp;gt;&amp;quot;. The hello message is recorded in the kernel logs. How do you view the kernel logs? How many ways are there to view them?&lt;br /&gt;
# Check to see that the module has been loaded. How do you do this?&lt;br /&gt;
# Remove the module from the kernel. What did you do?&lt;br /&gt;
&lt;br /&gt;
===Tasks part C: A character device kernel module (driver)===&lt;br /&gt;
Download the source for [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/ones.tar.gz ones], a kernel module implementing a character device that outputs an unbounded string of &amp;quot;1&amp;quot;&#039;s. Build, compile, and run it as before.&lt;br /&gt;
# What kernel messages does the module generate? Does it create any new files (other than &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;)? If so, where? (Hint: search in &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# What happens when you &amp;quot;cat&amp;quot; the device &amp;lt;tt&amp;gt;/dev/ones&amp;lt;/tt&amp;gt;? How can you limit the output in more than one way?&lt;br /&gt;
# Add more &amp;lt;tt&amp;gt;printk()&amp;lt;/tt&amp;gt;’s (where you see needed) to find out at which point which functions in ones.c are called and for which purpose.&lt;br /&gt;
&lt;br /&gt;
===Tasks part D: Getting process information from a module===&lt;br /&gt;
Download the source [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/newgetpid.tar.gz newgetpid.c]. Build and run it as before. Hints for the questions below: &lt;br /&gt;
&lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/sched.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/current.h, &lt;br /&gt;
https://elixir.bootlin.com/linux/latest/source/include/linux/cred.h&lt;br /&gt;
# What type is &amp;quot;&amp;lt;tt&amp;gt;current&amp;lt;/tt&amp;gt;&amp;quot;? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; can you figure this out?&lt;br /&gt;
# Modify newgetpid.c so that it creates a device file &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; rather than &amp;lt;tt&amp;gt;/dev/newgetpid&amp;lt;/tt&amp;gt;.&lt;br /&gt;
# Make &amp;lt;tt&amp;gt;/dev/describe&amp;lt;/tt&amp;gt; output the calling process&#039;s parent ID (ppid), user ID (uid), group ID (gid), effective user ID (euid), and effective group ID (egid).&lt;br /&gt;
&lt;br /&gt;
==Using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt; to monitor kernel module events==&lt;br /&gt;
Note: you are not required to write about your experience for this part in the submitted work, but you should still do it, which can help you understand eBPF better (see how simple but still powerful an eBPF program can be).&lt;br /&gt;
&lt;br /&gt;
If you see an error like &amp;quot;&amp;lt;tt&amp;gt;Could not resolve symbol&amp;lt;/tt&amp;gt;&amp;quot; when using &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;, you need to apply a fix by installing the dbgsym package of &amp;lt;tt&amp;gt;bpftrace&amp;lt;/tt&amp;gt;: Just &amp;lt;tt&amp;gt;wget&amp;lt;/tt&amp;gt; [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/install-bpftrace-dbgsym this file], and run it with&lt;br /&gt;
&lt;br /&gt;
  sudo apt update&lt;br /&gt;
  source install-bpftrace-dbgsym&lt;br /&gt;
&lt;br /&gt;
Download this tiny code [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut7/kmsnoop.bt kmsnoop.bt] and make it executable with &amp;lt;tt&amp;gt;chmod 755 kmsnoop.bt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now, you can open a separate SSH session and run it with &amp;lt;tt&amp;gt;sudo ./kmsnoop.bt&amp;lt;/tt&amp;gt;. It will wait for events. When you do any &amp;quot;insmod&amp;quot; or &amp;quot;rmmod&amp;quot; in the other session, you will see it outputs a line of message.&lt;br /&gt;
&lt;br /&gt;
If you want to avoid opening another SSH window, you can use tmux (a terminal multiplexer) by just typing tmux and hit enter.&lt;br /&gt;
&lt;br /&gt;
To create a new session: press Ctrl-B and C&lt;br /&gt;
&lt;br /&gt;
To move between sessions: press Ctrl-B and N (or P)&lt;br /&gt;
&lt;br /&gt;
How could this save you from doing any &amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;&#039;s in your kernel module code?&lt;br /&gt;
You can also &amp;lt;tt&amp;gt;sudo bpftrace -l | grep&amp;lt;/tt&amp;gt; for your needed kernel functions (e.g.,&amp;lt;tt&amp;gt;printk&amp;lt;/tt&amp;gt;) to hook to.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24563</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24563"/>
		<updated>2023-10-25T01:30:40Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24562</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24562"/>
		<updated>2023-10-25T01:30:11Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems W23: Tutorial 7 | Tutorial 7]] || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24561</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24561"/>
		<updated>2023-10-25T01:14:57Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;code&amp;gt;/usr/sbin/getty&amp;lt;/code&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;code&amp;gt;/usr/bin/login&amp;lt;/code&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;code&amp;gt;adduser&amp;lt;/code&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;code&amp;gt;su someuser&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;code&amp;gt;man&amp;lt;/code&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;chown&amp;lt;/code&amp;gt; command makes the binary owned by root, and the &amp;lt;code&amp;gt;chmod&amp;lt;/code&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;code&amp;gt;getpwnam()&amp;lt;/code&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;code&amp;gt;sudo ./3000userlogin someuser&amp;lt;/code&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;code&amp;gt;/etc/passwd&amp;lt;/code&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;code&amp;gt;chsh&amp;lt;/code&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;code&amp;gt;chsh&amp;lt;/code&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;code&amp;gt;environ&amp;lt;/code&amp;gt; not &amp;lt;code&amp;gt;envp&amp;lt;/code&amp;gt; (as an argument to &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;code&amp;gt;envp&amp;lt;/code&amp;gt;? (Try changing the code to use &amp;lt;code&amp;gt;envp&amp;lt;/code&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;code&amp;gt;/etc/shadow&amp;lt;/code&amp;gt; and you may need to learn how to use the &amp;lt;code&amp;gt;openssl passwd&amp;lt;/code&amp;gt; command.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24560</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24560"/>
		<updated>2023-10-25T01:12:45Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;code&amp;gt;lstat()&amp;lt;/code&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;code&amp;gt;readlink(2)&amp;lt;/code&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;code&amp;gt;man 2 readlink&amp;lt;/code&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, a sysfs is mounted on &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;code&amp;gt;/media/&amp;lt;/code&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;code&amp;gt;/dev/*&amp;lt;/code&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;code&amp;gt;/dev/loop1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;code&amp;gt;fsck&amp;lt;/code&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/code&amp;gt; and use the &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;code&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/code&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;mkfs.ext4 foo&amp;lt;/code&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;code&amp;gt;mkfs.ext4 foo2&amp;lt;/code&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;sudo touch test.txt&amp;lt;/code&amp;gt;) and run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt;. What device is mounted on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo umount /mnt&amp;lt;/code&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/code&amp;gt;. How does the &amp;quot;&amp;lt;code&amp;gt;conv=notrunc&amp;lt;/code&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24559</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24559"/>
		<updated>2023-10-25T01:12:35Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;code&amp;gt;lstat()&amp;lt;/code&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;code&amp;gt;readlink(2)&amp;lt;/code&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;code&amp;gt;man 2 readlink&amp;lt;/code&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, a sysfs is mounted on &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;code&amp;gt;/media/&amp;lt;/code&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;code&amp;gt;/dev/*&amp;lt;/code&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;code&amp;gt;/dev/loop1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;code&amp;gt;fsck&amp;lt;/code&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/code&amp;gt; and use the &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;code&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/code&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;mkfs.ext4 foo&amp;lt;/code&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;code&amp;gt;mkfs.ext4 foo2&amp;lt;/code&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;sudo touch test.txt&amp;lt;/code&amp;gt;) and run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt;. What device is mounted on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo umount /mnt&amp;lt;/code&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/code&amp;gt;. How does the &amp;quot;&amp;lt;code&amp;gt;conv=notrunc&amp;lt;/code&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24558</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24558"/>
		<updated>2023-10-25T01:12:05Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks/Questions (Part A) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;code&amp;gt;lstat()&amp;lt;/code&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;code&amp;gt;readlink(2)&amp;lt;/code&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;code&amp;gt;man 2 readlink&amp;lt;/code&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, a sysfs is mounted on &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;code&amp;gt;/media/&amp;lt;/code&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;code&amp;gt;/dev/*&amp;lt;/code&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;code&amp;gt;/dev/loop1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;code&amp;gt;fsck&amp;lt;/code&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/code&amp;gt; and use the &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;code&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/code&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;mkfs.ext4 foo&amp;lt;/code&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;code&amp;gt;mkfs.ext4 foo2&amp;lt;/code&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;sudo touch test.txt&amp;lt;/code&amp;gt;) and run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt;. What device is mounted on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo umount /mnt&amp;lt;/code&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/code&amp;gt;. How does the &amp;quot;&amp;lt;code&amp;gt;conv=notrunc&amp;lt;/code&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24557</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24557"/>
		<updated>2023-10-25T01:11:36Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks/Questions (Part B) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, a sysfs is mounted on &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;code&amp;gt;/media/&amp;lt;/code&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;code&amp;gt;/dev/*&amp;lt;/code&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;code&amp;gt;/dev/loop1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;code&amp;gt;fsck&amp;lt;/code&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/code&amp;gt; and use the &amp;lt;code&amp;gt;ls&amp;lt;/code&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;code&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/code&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;mkfs.ext4 foo&amp;lt;/code&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;code&amp;gt;mkfs.ext4 foo2&amp;lt;/code&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt; (e.g., &amp;lt;code&amp;gt;sudo touch test.txt&amp;lt;/code&amp;gt;) and run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;df&amp;lt;/code&amp;gt;. What device is mounted on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo umount /mnt&amp;lt;/code&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/code&amp;gt;. How does the &amp;quot;&amp;lt;code&amp;gt;conv=notrunc&amp;lt;/code&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;code&amp;gt;sudo mount foo /mnt&amp;lt;/code&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24556</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24556"/>
		<updated>2023-10-25T01:10:50Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Creating, Mounting, and Unmounting Filesystem */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;code&amp;gt;/proc&amp;lt;/code&amp;gt;, a sysfs is mounted on &amp;lt;code&amp;gt;/sys&amp;lt;/code&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;code&amp;gt;/media/&amp;lt;/code&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;code&amp;gt;/dev/*&amp;lt;/code&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;code&amp;gt;/mnt&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;code&amp;gt;/dev/sdb1&amp;lt;/code&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;code&amp;gt;/dev/loop1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;code&amp;gt;fsck&amp;lt;/code&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/tt&amp;gt; and use the &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/tt&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;tt&amp;gt;mkfs.ext4 foo2&amp;lt;/tt&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt; (e.g., &amp;lt;tt&amp;gt;sudo touch test.txt&amp;lt;/tt&amp;gt;) and run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;. What device is mounted on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo umount /mnt&amp;lt;/tt&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;. How does the &amp;quot;&amp;lt;tt&amp;gt;conv=notrunc&amp;lt;/tt&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24555</id>
		<title>COMP3000 Operating Systems F23: Tutorial 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24555"/>
		<updated>2023-10-25T01:09:18Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* C: Producer/Consumer with Shared Memory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-sema.pdf Chapter 31 (Semaphores)]. While you can look at this part of the textbook, note that we will not be covering this material in the same level of detail, as should be clear from this tutorial.&lt;br /&gt;
&lt;br /&gt;
==A: Getting Started==&lt;br /&gt;
Download [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut6/3000pc.zip 3000pc.zip], unpack, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; to compile &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Try to take this opportunity to read and understand the two programs line by line.&lt;br /&gt;
&lt;br /&gt;
:: Note that these programs take 3 arguments each:&lt;br /&gt;
::* The number of events to process&lt;br /&gt;
::* The number of events to produce before the producer sleeps for 1 second&lt;br /&gt;
::* The number of events to consume before the consumer sleeps for 1 second&lt;br /&gt;
&lt;br /&gt;
# Run both programs with the same arguments of your choice. Do this a few times with different arguments. Do they behave the same way? Do you notice &amp;lt;u&amp;gt;any differences&amp;lt;/u&amp;gt;?  (again, no “correct” answers but just play with them and document your observations)&lt;br /&gt;
# Repeat the above experiment, this time running each program under &amp;lt;code&amp;gt;strace&amp;lt;/code&amp;gt; (with the &amp;lt;code&amp;gt;-f&amp;lt;/code&amp;gt; flag to trace children too). Do you notice any difference in the system calls each program makes? Remember to ignore the lines before &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; that might be distracting, e.g., start looking around and after the &amp;lt;code&amp;gt;clone()&amp;lt;/code&amp;gt; system call.&lt;br /&gt;
# You can see there is &amp;quot;&amp;lt;code&amp;gt;#define QUEUESIZE 32&amp;lt;/code&amp;gt;&amp;quot; in both programs. Are they actually used? &amp;lt;u&amp;gt;Why (not)&amp;lt;/u&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
==B: Producer/Consumer with Pipes==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt;. Pay attention to the call to &amp;lt;code&amp;gt;pipe(pipefd)&amp;lt;/code&amp;gt; on line 192 and make the connection with what has been discussed in the lecture (also look at the man page for &amp;lt;code&amp;gt;pipe(2)&amp;lt;/code&amp;gt;). Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer receive words to consume? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer generate and send words to the consumer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Why is the call to &amp;lt;code&amp;gt;srandom(time(NULL))&amp;lt;/code&amp;gt; on line 169 necessary? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Replace the call to &amp;lt;code&amp;gt;srandom(time(NULL))&amp;lt;/code&amp;gt; on line 169 with &amp;lt;code&amp;gt;srandom(42)&amp;lt;/code&amp;gt;. What differences do you notice in &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt;&#039;s behavior? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C: Producer/Consumer with Shared Memory==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt;. Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What are a few ways that &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt; is different from &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt;? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What does the call to &amp;lt;code&amp;gt;mmap()&amp;lt;/code&amp;gt; on line 347 do (compared to our previous uses of &amp;lt;code&amp;gt;mmap()&amp;lt;/code&amp;gt;)? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; did you figure this out? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer notify the consumer that the queue is no longer empty? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer notify the producer that the queue is no longer full? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the producer wait for the consumer? Hint: Check the size of the queue. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the consumer wait for the producer? (You can disregard the wait at the very beginning as the queue is initially empty) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Another student tells you that the difference between processes and threads is that processes never share memory, while threads do. Is this statement correct or incorrect? How can the behavior of &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt; help justify your answer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Change the calls to &amp;lt;code&amp;gt;pthread_mutexattr_setpshared()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;pthread_condattr_setpshared()&amp;lt;/code&amp;gt; (lines 293 and 298) to take 0 instead of 1. How does the behavior or &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt; change? Does anything break? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24554</id>
		<title>COMP3000 Operating Systems F23: Tutorial 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24554"/>
		<updated>2023-10-25T01:08:23Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* B: Producer/Consumer with Pipes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-sema.pdf Chapter 31 (Semaphores)]. While you can look at this part of the textbook, note that we will not be covering this material in the same level of detail, as should be clear from this tutorial.&lt;br /&gt;
&lt;br /&gt;
==A: Getting Started==&lt;br /&gt;
Download [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut6/3000pc.zip 3000pc.zip], unpack, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; to compile &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Try to take this opportunity to read and understand the two programs line by line.&lt;br /&gt;
&lt;br /&gt;
:: Note that these programs take 3 arguments each:&lt;br /&gt;
::* The number of events to process&lt;br /&gt;
::* The number of events to produce before the producer sleeps for 1 second&lt;br /&gt;
::* The number of events to consume before the consumer sleeps for 1 second&lt;br /&gt;
&lt;br /&gt;
# Run both programs with the same arguments of your choice. Do this a few times with different arguments. Do they behave the same way? Do you notice &amp;lt;u&amp;gt;any differences&amp;lt;/u&amp;gt;?  (again, no “correct” answers but just play with them and document your observations)&lt;br /&gt;
# Repeat the above experiment, this time running each program under &amp;lt;code&amp;gt;strace&amp;lt;/code&amp;gt; (with the &amp;lt;code&amp;gt;-f&amp;lt;/code&amp;gt; flag to trace children too). Do you notice any difference in the system calls each program makes? Remember to ignore the lines before &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; that might be distracting, e.g., start looking around and after the &amp;lt;code&amp;gt;clone()&amp;lt;/code&amp;gt; system call.&lt;br /&gt;
# You can see there is &amp;quot;&amp;lt;code&amp;gt;#define QUEUESIZE 32&amp;lt;/code&amp;gt;&amp;quot; in both programs. Are they actually used? &amp;lt;u&amp;gt;Why (not)&amp;lt;/u&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
==B: Producer/Consumer with Pipes==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt;. Pay attention to the call to &amp;lt;code&amp;gt;pipe(pipefd)&amp;lt;/code&amp;gt; on line 192 and make the connection with what has been discussed in the lecture (also look at the man page for &amp;lt;code&amp;gt;pipe(2)&amp;lt;/code&amp;gt;). Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer receive words to consume? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer generate and send words to the consumer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Why is the call to &amp;lt;code&amp;gt;srandom(time(NULL))&amp;lt;/code&amp;gt; on line 169 necessary? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Replace the call to &amp;lt;code&amp;gt;srandom(time(NULL))&amp;lt;/code&amp;gt; on line 169 with &amp;lt;code&amp;gt;srandom(42)&amp;lt;/code&amp;gt;. What differences do you notice in &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt;&#039;s behavior? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C: Producer/Consumer with Shared Memory==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;. Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What are a few ways that &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; is different from &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What does the call to &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt; on line 347 do (compared to our previous uses of &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt;)? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; did you figure this out? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer notify the consumer that the queue is no longer empty? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer notify the producer that the queue is no longer full? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the producer wait for the consumer? Hint: Check the size of the queue. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the consumer wait for the producer? (You can disregard the wait at the very beginning as the queue is initially empty) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Another student tells you that the difference between processes and threads is that processes never share memory, while threads do. Is this statement correct or incorrect? How can the behavior of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; help justify your answer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Change the calls to &amp;lt;tt&amp;gt;pthread_mutexattr_setpshared()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;pthread_condattr_setpshared()&amp;lt;/tt&amp;gt; (lines 293 and 298) to take 0 instead of 1. How does the behavior or &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; change? Does anything break? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24553</id>
		<title>COMP3000 Operating Systems F23: Tutorial 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24553"/>
		<updated>2023-10-25T01:07:51Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* A: Getting Started */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-sema.pdf Chapter 31 (Semaphores)]. While you can look at this part of the textbook, note that we will not be covering this material in the same level of detail, as should be clear from this tutorial.&lt;br /&gt;
&lt;br /&gt;
==A: Getting Started==&lt;br /&gt;
Download [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut6/3000pc.zip 3000pc.zip], unpack, and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; to compile &amp;lt;code&amp;gt;3000pc-fifo&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;3000pc-rendezvous&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Try to take this opportunity to read and understand the two programs line by line.&lt;br /&gt;
&lt;br /&gt;
:: Note that these programs take 3 arguments each:&lt;br /&gt;
::* The number of events to process&lt;br /&gt;
::* The number of events to produce before the producer sleeps for 1 second&lt;br /&gt;
::* The number of events to consume before the consumer sleeps for 1 second&lt;br /&gt;
&lt;br /&gt;
# Run both programs with the same arguments of your choice. Do this a few times with different arguments. Do they behave the same way? Do you notice &amp;lt;u&amp;gt;any differences&amp;lt;/u&amp;gt;?  (again, no “correct” answers but just play with them and document your observations)&lt;br /&gt;
# Repeat the above experiment, this time running each program under &amp;lt;code&amp;gt;strace&amp;lt;/code&amp;gt; (with the &amp;lt;code&amp;gt;-f&amp;lt;/code&amp;gt; flag to trace children too). Do you notice any difference in the system calls each program makes? Remember to ignore the lines before &amp;lt;code&amp;gt;main()&amp;lt;/code&amp;gt; that might be distracting, e.g., start looking around and after the &amp;lt;code&amp;gt;clone()&amp;lt;/code&amp;gt; system call.&lt;br /&gt;
# You can see there is &amp;quot;&amp;lt;code&amp;gt;#define QUEUESIZE 32&amp;lt;/code&amp;gt;&amp;quot; in both programs. Are they actually used? &amp;lt;u&amp;gt;Why (not)&amp;lt;/u&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
==B: Producer/Consumer with Pipes==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;. Pay attention to the call to &amp;lt;tt&amp;gt;pipe(pipefd)&amp;lt;/tt&amp;gt; on line 192 and make the connection with what has been discussed in the lecture (also look at the man page for &amp;lt;tt&amp;gt;pipe(2)&amp;lt;/tt&amp;gt;). Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer receive words to consume? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer generate and send words to the consumer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Why is the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 necessary? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Replace the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 with &amp;lt;tt&amp;gt;srandom(42)&amp;lt;/tt&amp;gt;. What differences do you notice in &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;&#039;s behavior? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C: Producer/Consumer with Shared Memory==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;. Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What are a few ways that &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; is different from &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What does the call to &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt; on line 347 do (compared to our previous uses of &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt;)? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; did you figure this out? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer notify the consumer that the queue is no longer empty? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer notify the producer that the queue is no longer full? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the producer wait for the consumer? Hint: Check the size of the queue. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the consumer wait for the producer? (You can disregard the wait at the very beginning as the queue is initially empty) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Another student tells you that the difference between processes and threads is that processes never share memory, while threads do. Is this statement correct or incorrect? How can the behavior of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; help justify your answer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Change the calls to &amp;lt;tt&amp;gt;pthread_mutexattr_setpshared()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;pthread_condattr_setpshared()&amp;lt;/tt&amp;gt; (lines 293 and 298) to take 0 instead of 1. How does the behavior or &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; change? Does anything break? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24552</id>
		<title>COMP3000 Operating Systems F23: Tutorial 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24552"/>
		<updated>2023-10-25T01:06:17Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* General Instructions (same for all tutorials) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-sema.pdf Chapter 31 (Semaphores)]. While you can look at this part of the textbook, note that we will not be covering this material in the same level of detail, as should be clear from this tutorial.&lt;br /&gt;
&lt;br /&gt;
==A: Getting Started==&lt;br /&gt;
Download [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut6/3000pc.zip 3000pc.zip], unpack, and run &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt; to compile &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Try to take this opportunity to read and understand the two programs line by line.&lt;br /&gt;
&lt;br /&gt;
:: Note that these programs take 3 arguments each:&lt;br /&gt;
::* The number of events to process&lt;br /&gt;
::* The number of events to produce before the producer sleeps for 1 second&lt;br /&gt;
::* The number of events to consume before the consumer sleeps for 1 second&lt;br /&gt;
&lt;br /&gt;
# Run both programs with the same arguments of your choice. Do this a few times with different arguments. Do they behave the same way? Do you notice &amp;lt;u&amp;gt;any differences&amp;lt;/u&amp;gt;?  (again, no “correct” answers but just play with them and document your observations)&lt;br /&gt;
# Repeat the above experiment, this time running each program under &amp;lt;tt&amp;gt;strace&amp;lt;/tt&amp;gt; (with the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag to trace children too). Do you notice any difference in the system calls each program makes? Remember to ignore the lines before &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt; that might be distracting, e.g., start looking around and after the &amp;lt;tt&amp;gt;clone()&amp;lt;/tt&amp;gt; system call.&lt;br /&gt;
# You can see there is &amp;quot;&amp;lt;tt&amp;gt;#define QUEUESIZE 32&amp;lt;/tt&amp;gt;&amp;quot; in both programs. Are they actually used? &amp;lt;u&amp;gt;Why (not)&amp;lt;/u&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
==B: Producer/Consumer with Pipes==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;. Pay attention to the call to &amp;lt;tt&amp;gt;pipe(pipefd)&amp;lt;/tt&amp;gt; on line 192 and make the connection with what has been discussed in the lecture (also look at the man page for &amp;lt;tt&amp;gt;pipe(2)&amp;lt;/tt&amp;gt;). Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer receive words to consume? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer generate and send words to the consumer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Why is the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 necessary? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Replace the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 with &amp;lt;tt&amp;gt;srandom(42)&amp;lt;/tt&amp;gt;. What differences do you notice in &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;&#039;s behavior? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C: Producer/Consumer with Shared Memory==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;. Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What are a few ways that &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; is different from &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What does the call to &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt; on line 347 do (compared to our previous uses of &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt;)? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; did you figure this out? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer notify the consumer that the queue is no longer empty? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer notify the producer that the queue is no longer full? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the producer wait for the consumer? Hint: Check the size of the queue. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the consumer wait for the producer? (You can disregard the wait at the very beginning as the queue is initially empty) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Another student tells you that the difference between processes and threads is that processes never share memory, while threads do. Is this statement correct or incorrect? How can the behavior of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; help justify your answer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Change the calls to &amp;lt;tt&amp;gt;pthread_mutexattr_setpshared()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;pthread_condattr_setpshared()&amp;lt;/tt&amp;gt; (lines 293 and 298) to take 0 instead of 1. How does the behavior or &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; change? Does anything break? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24551</id>
		<title>COMP3000 Operating Systems F23: Tutorial 6</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_6&amp;diff=24551"/>
		<updated>2023-10-25T01:05:40Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about two implementations of the [https://en.wikipedia.org/wiki/Producer%E2%80%93consumer_problem producer-consumer problem], a classic example of a concurrency problem. The [http://pages.cs.wisc.edu/~remzi/OSTEP/ class textbook] covers concurrency in great detail in Chapters 25-34, and the producer-consumer problem is covered in [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-cv.pdf Chapter 30 (Condition Variables)] and [http://pages.cs.wisc.edu/~remzi/OSTEP/threads-sema.pdf Chapter 31 (Semaphores)]. While you can look at this part of the textbook, note that we will not be covering this material in the same level of detail, as should be clear from this tutorial.&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==A: Getting Started==&lt;br /&gt;
Download [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut6/3000pc.zip 3000pc.zip], unpack, and run &amp;lt;tt&amp;gt;make&amp;lt;/tt&amp;gt; to compile &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Try to take this opportunity to read and understand the two programs line by line.&lt;br /&gt;
&lt;br /&gt;
:: Note that these programs take 3 arguments each:&lt;br /&gt;
::* The number of events to process&lt;br /&gt;
::* The number of events to produce before the producer sleeps for 1 second&lt;br /&gt;
::* The number of events to consume before the consumer sleeps for 1 second&lt;br /&gt;
&lt;br /&gt;
# Run both programs with the same arguments of your choice. Do this a few times with different arguments. Do they behave the same way? Do you notice &amp;lt;u&amp;gt;any differences&amp;lt;/u&amp;gt;?  (again, no “correct” answers but just play with them and document your observations)&lt;br /&gt;
# Repeat the above experiment, this time running each program under &amp;lt;tt&amp;gt;strace&amp;lt;/tt&amp;gt; (with the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag to trace children too). Do you notice any difference in the system calls each program makes? Remember to ignore the lines before &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt; that might be distracting, e.g., start looking around and after the &amp;lt;tt&amp;gt;clone()&amp;lt;/tt&amp;gt; system call.&lt;br /&gt;
# You can see there is &amp;quot;&amp;lt;tt&amp;gt;#define QUEUESIZE 32&amp;lt;/tt&amp;gt;&amp;quot; in both programs. Are they actually used? &amp;lt;u&amp;gt;Why (not)&amp;lt;/u&amp;gt;?&lt;br /&gt;
&lt;br /&gt;
==B: Producer/Consumer with Pipes==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;. Pay attention to the call to &amp;lt;tt&amp;gt;pipe(pipefd)&amp;lt;/tt&amp;gt; on line 192 and make the connection with what has been discussed in the lecture (also look at the man page for &amp;lt;tt&amp;gt;pipe(2)&amp;lt;/tt&amp;gt;). Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer receive words to consume? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer generate and send words to the consumer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Why is the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 necessary? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Replace the call to &amp;lt;tt&amp;gt;srandom(time(NULL))&amp;lt;/tt&amp;gt; on line 169 with &amp;lt;tt&amp;gt;srandom(42)&amp;lt;/tt&amp;gt;. What differences do you notice in &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;&#039;s behavior? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==C: Producer/Consumer with Shared Memory==&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:decimal&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Examine the source code of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt;. Explain the following:&lt;br /&gt;
&amp;lt;ol style=&amp;quot;list-style-type:lower-alpha&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What are a few ways that &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; is different from &amp;lt;tt&amp;gt;3000pc-fifo&amp;lt;/tt&amp;gt;? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What does the call to &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt; on line 347 do (compared to our previous uses of &amp;lt;tt&amp;gt;mmap()&amp;lt;/tt&amp;gt;)? &amp;lt;u&amp;gt;How&amp;lt;/u&amp;gt; did you figure this out? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the producer notify the consumer that the queue is no longer empty? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; How does the consumer notify the producer that the queue is no longer full? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the producer wait for the consumer? Hint: Check the size of the queue. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; What arguments can you provide to make the consumer wait for the producer? (You can disregard the wait at the very beginning as the queue is initially empty) &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Another student tells you that the difference between processes and threads is that processes never share memory, while threads do. Is this statement correct or incorrect? How can the behavior of &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; help justify your answer? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Change the calls to &amp;lt;tt&amp;gt;pthread_mutexattr_setpshared()&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;pthread_condattr_setpshared()&amp;lt;/tt&amp;gt; (lines 293 and 298) to take 0 instead of 1. How does the behavior or &amp;lt;tt&amp;gt;3000pc-rendezvous&amp;lt;/tt&amp;gt; change? Does anything break? &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24550</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24550"/>
		<updated>2023-10-25T01:05:32Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 7 || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24549</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24549"/>
		<updated>2023-10-25T01:04:53Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems W23: Tutorial 6 | Tutorial 6]] || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 7 || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24548</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24548"/>
		<updated>2023-10-25T00:50:25Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks/Questions (Part A) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;tt&amp;gt;/proc&amp;lt;/tt&amp;gt;, a sysfs is mounted on &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;tt&amp;gt;/media/&amp;lt;/tt&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;tt&amp;gt;/dev/*&amp;lt;/tt&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;tt&amp;gt;/dev/sdb1&amp;lt;/tt&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;tt&amp;gt;/dev/loop1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;tt&amp;gt;fsck&amp;lt;/tt&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/tt&amp;gt; and use the &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/tt&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;tt&amp;gt;mkfs.ext4 foo2&amp;lt;/tt&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt; (e.g., &amp;lt;tt&amp;gt;sudo touch test.txt&amp;lt;/tt&amp;gt;) and run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;. What device is mounted on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo umount /mnt&amp;lt;/tt&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;. How does the &amp;quot;&amp;lt;tt&amp;gt;conv=notrunc&amp;lt;/tt&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24547</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24547"/>
		<updated>2023-10-25T00:48:54Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* General Instructions (same for all tutorials) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;tt&amp;gt;/proc&amp;lt;/tt&amp;gt;, a sysfs is mounted on &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;tt&amp;gt;/media/&amp;lt;/tt&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;tt&amp;gt;/dev/*&amp;lt;/tt&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;tt&amp;gt;/dev/sdb1&amp;lt;/tt&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;tt&amp;gt;/dev/loop1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;tt&amp;gt;fsck&amp;lt;/tt&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/tt&amp;gt; and use the &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/tt&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;tt&amp;gt;mkfs.ext4 foo2&amp;lt;/tt&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt; (e.g., &amp;lt;tt&amp;gt;sudo touch test.txt&amp;lt;/tt&amp;gt;) and run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;. What device is mounted on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo umount /mnt&amp;lt;/tt&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;. How does the &amp;quot;&amp;lt;tt&amp;gt;conv=notrunc&amp;lt;/tt&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24546</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24546"/>
		<updated>2023-10-25T00:48:24Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;tt&amp;gt;/proc&amp;lt;/tt&amp;gt;, a sysfs is mounted on &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;tt&amp;gt;/media/&amp;lt;/tt&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;tt&amp;gt;/dev/*&amp;lt;/tt&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;tt&amp;gt;/dev/sdb1&amp;lt;/tt&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;tt&amp;gt;/dev/loop1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;tt&amp;gt;fsck&amp;lt;/tt&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/tt&amp;gt; and use the &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/tt&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;tt&amp;gt;mkfs.ext4 foo2&amp;lt;/tt&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt; (e.g., &amp;lt;tt&amp;gt;sudo touch test.txt&amp;lt;/tt&amp;gt;) and run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;. What device is mounted on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo umount /mnt&amp;lt;/tt&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;. How does the &amp;quot;&amp;lt;tt&amp;gt;conv=notrunc&amp;lt;/tt&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24545</id>
		<title>COMP3000 Operating Systems F23: Tutorial 5</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_5&amp;diff=24545"/>
		<updated>2023-10-25T00:47:25Z</updated>

		<summary type="html">&lt;p&gt;Abdou: Created page with &amp;quot;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &amp;#039;&amp;#039;&amp;#039;WARNING:&amp;#039;&amp;#039;&amp;#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.  &amp;#039;&amp;#039;&amp;#039;Note: there are two parts of Tasks/Questions, Part...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial you will be learning about files and filesystems by experimenting with and extending [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut5/3000test.c 3000test.c], and creating and manipulating local filesystems. &#039;&#039;&#039;WARNING:&#039;&#039;&#039; Several of the commands here can lead to system corruption and data loss if not properly used. You have been warned. Please use a VM and make backups, when necessary.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: there are two parts of Tasks/Questions, Part A and Part B&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==General Instructions (same for all tutorials)==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Click on Expand to view.&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&lt;br /&gt;
Tutorials are graded based on participation and effort (&#039;&#039;&#039;so no need to struggle to have the “correct” answers — what matters is the attempts and sufficient thinking reflected in your answers&#039;&#039;&#039;), but you should still turn in your work. Submit your answers on Brightspace as a single text file named &amp;quot;&amp;lt;username&amp;gt;-comp3000-t&amp;lt;n&amp;gt;.txt&amp;quot; (where username is your MyCarletonOne username and n is the tutorial number). The first four lines of this file should be &amp;quot;COMP 3000 Tutorial &amp;lt;n&amp;gt;&amp;quot;, your name, student number, and the date of submission. Your submitted answers must at least respond to all the items in the &#039;&#039;&#039;Tasks/Questions&#039;&#039;&#039; section.&lt;br /&gt;
&lt;br /&gt;
The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.&lt;br /&gt;
&lt;br /&gt;
You should also check in with your assigned TA (in person or by responding to a poll if online). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Files and inodes==&lt;br /&gt;
In UNIX/Linux filesystems, a filename does not directly refer to the contents of a file. Instead, a filename refers to an inode (as specified in a directory entry --- dentry, of its parent directory), and the inode then refers to the data. An inode is where file metadata is stored. File ownership, timestamps, and permissions are all stored in a file&#039;s inode. Regular files are just &#039;&#039;&#039;hard links&#039;&#039;&#039; connecting a file name to an inode. &lt;br /&gt;
&lt;br /&gt;
In addition to regular files, we also have symbolic links, directories, block devices, character devices, and pipes. Each is its own type of inode.&lt;br /&gt;
&lt;br /&gt;
Note that while you can find out a file&#039;s inode, you cannot go from an inode to a pathname or otherwise manipulate an inode directly from userspace - you always have to go through the pathname. The kernel, however, can access individual inodes directly (indeed it has to in order to get to the contents of a file when given a filename).&lt;br /&gt;
&lt;br /&gt;
3000test.c uses stat() to give information on a given inode.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part A)==&lt;br /&gt;
# Compile and run [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut5/3000test.c 3000test.c]. It takes a filename as an argument and reports information on the file. Try giving it the following and see what it reports:&lt;br /&gt;
#* a regular text file that exists&lt;br /&gt;
#* a directory&lt;br /&gt;
#* a symbolic link&lt;br /&gt;
#* a device file (character or block)&lt;br /&gt;
# Change 3000test to use &amp;lt;tt&amp;gt;lstat()&amp;lt;/tt&amp;gt; rather than stat. How does its behavior change?&lt;br /&gt;
# Modify 3000test so when it is given a symbolic link it reports the name of the target. Use &amp;lt;tt&amp;gt;readlink(2)&amp;lt;/tt&amp;gt; (this notation describes how to access the man page, e.g., &amp;lt;tt&amp;gt;man 2 readlink&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# Are there files or directories that you cannot run 3000test on? Can you configure file/directory permissions so as to make something inaccessible to 3000test? Note that this is twofold: 1) whether it is completely inaccessible to 3000test (&#039;&#039;&#039;nothing can be displayed&#039;&#039;&#039;, except the error msg); 2) whether it can be accessed for the search (&#039;&#039;&#039;no access to file content&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
==Creating, Mounting, and Unmounting Filesystem==&lt;br /&gt;
In UNIX/Linux systems we always have a single hierarchical namespace for files and directories. Pathnames that start with a &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt; are absolute, starting at the top of the namespace, while ones that do not start with a / are relative to the current directory.&lt;br /&gt;
&lt;br /&gt;
The files in this single namespace come from many sources, each of which can have very different semantics. These sources are known as &#039;&#039;&#039;filesystems&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
When first started, a system must have at least one filesystem. This first filesystem is known as the root filesystem and has the contents of &amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;. We can then add other filesystems to this initial set of files by &#039;&#039;&#039;mounting&#039;&#039;&#039; each filesystem on an existing directory.&lt;br /&gt;
&lt;br /&gt;
On Ubuntu 22.04, the root filesystem is ext4 by default and many others are mounted on top of it. For example, a proc filesystem is mounted on &amp;lt;tt&amp;gt;/proc&amp;lt;/tt&amp;gt;, a sysfs is mounted on &amp;lt;tt&amp;gt;/sys&amp;lt;/tt&amp;gt;. If you run &amp;quot;mount&amp;quot; with no arguments, it lists all the currently mounted filesystems. Note that most of these are virtual filesystems, in that they do not correspond to any persistent storage (like a disk).&lt;br /&gt;
&lt;br /&gt;
If you insert a USB stick on a laptop or desktop running Linux, it must be mounted before you can access its contents. The current convention is for it to be mounted in &amp;lt;tt&amp;gt;/media/&amp;lt;/tt&amp;gt;&amp;lt;mounting user&amp;gt;&amp;lt;tt&amp;gt;/&amp;lt;/tt&amp;gt;&amp;lt;name of USB stick filesystem&amp;gt;. This usually happens automatically nowadays when the USB stick is plugged in.&lt;br /&gt;
&lt;br /&gt;
To create an ext4 filesystem, you just run&lt;br /&gt;
&lt;br /&gt;
 mkfs.ext4 &amp;lt;writable block device&amp;gt;  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it with any &amp;lt;tt&amp;gt;/dev/*&amp;lt;/tt&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you were to run this on the root filesystem of your current system, it would reformat your entire disk if it was allowed to complete. In all likelihood the system should prevent you from doing this as the root filesystem (and any mounted filesystem) gets special protections.&lt;br /&gt;
&lt;br /&gt;
To mount a filesystem, you specify the filesystem to be mounted (by its type or by the device) and the mountpoint:&lt;br /&gt;
&lt;br /&gt;
 mount /dev/sdb1 /mnt  &amp;lt;span style=&amp;quot;color:#ff0000&amp;quot;&amp;gt;#Do not try it unless you have that block device and want to do it&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would mount the first partition of the second disk on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Filesystems can be stored on block devices - devices whose contents are accessed by specifying a block index/address. The other main type of device file, character devices, are used for devices where the data is accessed a single byte (character) at a time. Terminals, modems, printers – for example, will generally be represented as a character device.&lt;br /&gt;
&lt;br /&gt;
Note that mount here can identify the filesystem on &amp;lt;tt&amp;gt;/dev/sdb1&amp;lt;/tt&amp;gt; by looking at its superblock. The superblock is usually either in block 0 or 1 of a device. The superblock holds metadata of a filesystem, allowing it to be identified and specified. Without the superblock you cannot do anything with a filesystem. Because of its importance, there are backup superblocks in addition to the primary one. The blocks of a filesystem can be classified as either being superblocks, inode blocks, or data blocks.&lt;br /&gt;
&lt;br /&gt;
Sometimes we want to play with a new filesystem but we don&#039;t have a physical device to format. If we have free space for a file in our current filesystem, however, we can put a filesystem in a file by using a loopback block device. A loopback block device is a block device where its data is stored in a regular file on another filesystem (rather than on a separate device). If you do filesystem commands with a regular file, it will transparently associate the file with an available loopback block device (e.g., &amp;lt;tt&amp;gt;/dev/loop1&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Note that inode numbers are filesystem-specific. Thus, the contents of a file are uniquely specified by its filesystem and inode. Only the kernel has to worry about this level of detail; in userspace, a file&#039;s full path contains all the necessary information.&lt;br /&gt;
&lt;br /&gt;
Filesystems on persistent storage are always at risk of corruption. File system checker programs (&amp;lt;tt&amp;gt;fsck&amp;lt;/tt&amp;gt;) can detect and repair filesystem errors.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions (Part B)==&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo bs=8192 count=32K&amp;lt;/tt&amp;gt; and use the &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command to check it. What is the logical size of the file foo? How much space does it consume on disk? (Hint: Look at the size option to ls). In comparison, create another file with &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo2 bs=8192 seek=31K count=1K&amp;lt;/tt&amp;gt;. Any observations?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;. Does foo consume any more space or less? Do the same (&amp;lt;tt&amp;gt;mkfs.ext4 foo2&amp;lt;/tt&amp;gt;) to the other file and answer the same question.&lt;br /&gt;
# Create any file in &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt; (e.g., &amp;lt;tt&amp;gt;sudo touch test.txt&amp;lt;/tt&amp;gt;) and run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. Do you still see the file you just created?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;. What device is mounted on &amp;lt;tt&amp;gt;/mnt&amp;lt;/tt&amp;gt;? What is this device? &lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo umount /mnt&amp;lt;/tt&amp;gt;. What have gone away and what is back?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;. How does the &amp;quot;&amp;lt;tt&amp;gt;conv=notrunc&amp;lt;/tt&amp;gt;&amp;quot; change dd&#039;s behavior (versus the command in question 1)?&lt;br /&gt;
# Run &amp;lt;tt&amp;gt;sudo mount foo /mnt&amp;lt;/tt&amp;gt;. What error do you get?&lt;br /&gt;
# What command can you run to make foo mountable again? What characteristic of the file system enables this command to work? (Hint: revisit the instructions of this tutorial if you have no idea)&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24544</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24544"/>
		<updated>2023-10-25T00:47:19Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 6 || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 7 || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24543</id>
		<title>COMP3000 Operating Systems 2023F Tutorials</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_2023F_Tutorials&amp;diff=24543"/>
		<updated>2023-10-25T00:46:45Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tutorial Sections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains Tutorial instructions for COMP3000 A, Fall 2023.&lt;br /&gt;
&lt;br /&gt;
The main page for the course can be found [https://people.scs.carleton.ca/~abdou/COMP3000_F2023.html here].&lt;br /&gt;
&lt;br /&gt;
==Information about the Tutorials==&lt;br /&gt;
Tutorials are in person. You need to be physically in the room to finish up the tutorial instructions on your laptop and get checked-out by one of the two present TAs. Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session. &lt;br /&gt;
&lt;br /&gt;
Please stick to the tutorial session you are registered in. This avoids overcrowding. &lt;br /&gt;
&lt;br /&gt;
Make well use of these tutorials to help you better understand the course material. The plan is to have 9 tutorial sessions this term, each would be worth 2.22% of your total grade. We might revisit this as the term progresses.&lt;br /&gt;
&lt;br /&gt;
Read through the instructions before starting your work to get an overall picture. When source files are needed, you can download them by clicking on the hyperlink.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Getting Access to a Linux Machine ==&lt;br /&gt;
&lt;br /&gt;
For the tutorials, you need to get access to a Linux machine. It is recommended to use an SCS Openstack instance (see instructions below). Alternatively, if you prefer to work directly on your laptop and avoid Openstack, you can also download [https://git.scs.carleton.ca/downloads/CourseVirtualMachines/2022F-2023W/COMP3000-W23.ova &amp;lt;b&amp;gt;this VirtualBox image&amp;lt;/b&amp;gt;] (courtesy of Prof. Zhao from Winter 2023). You will need access to a Linux system for the entire semester, ideally the same one.&lt;br /&gt;
&lt;br /&gt;
=== Setting up an Openstack VM instance for the first time ===&lt;br /&gt;
We will use Openstack for the tutorials of this course. Follow these instructions for setting up an Openstack VM instance: [[COMP3000 Operating Systems F23: Openstack Instructions | instructions here]]. You only need to do this once for the whole term. Please use the same instance for both: the tutorials and the assignments. &#039;&#039;No need to create two instances&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
=== Connecting to the VM ===&lt;br /&gt;
You can find instructions with various ways to connect to your Openstack instance [[COMP3000 Operating Systems F23: Connecting to SCS Openstack | here]].&lt;br /&gt;
&lt;br /&gt;
=== Downloading files from the VM ===&lt;br /&gt;
To download files from your Openstack VM instance, you can find instructions [[COMP3000 Operating Systems F23: Downloading files from your Openstack VM | here]].&lt;br /&gt;
&lt;br /&gt;
=== Backing up the VM ===&lt;br /&gt;
&lt;br /&gt;
To backup your VM, the image provides an &amp;quot;scs-backup&amp;quot; command that will backup the student user&#039;s directory to the SCS linux machines. So if your SCS username is janedoe, you can type:&lt;br /&gt;
&lt;br /&gt;
 scs-backup janedoe&lt;br /&gt;
&lt;br /&gt;
and it will create a copy of everything in the student account&#039;s home directory (note: you can customize it) in a directory called &amp;quot;COMP3000VM-backup&amp;quot; in your SCS home directory. You can ssh/sftp to &amp;lt;tt&amp;gt;access.scs.carleton.ca&amp;lt;/tt&amp;gt; in order to access this copy of your VM&#039;s files. You should do backups at the end of every session and before you do anything dangerous.&lt;br /&gt;
&lt;br /&gt;
Reminder: &#039;&#039;do &#039;&#039;&#039;not&#039;&#039;&#039; take snapshots of your instance!&#039;&#039; Note that you cannot take snapshots of your VM anyway (it will keep trying and never succeed, and you&#039;ll create work for the tech staff who will have to undo what you did), so please don&#039;t try.&lt;br /&gt;
&lt;br /&gt;
==Tutorial Sections==&lt;br /&gt;
&lt;br /&gt;
* COMP 3000 A1: Tue: 08:35 - 09:55 at Loeb 720 (LA720). [Ethan and Sneha (T1-T9)]&lt;br /&gt;
* COMP 3000 A2: Fri: 11:35 - 12:55 at Loeb 720 (LA720). [Ethan and Ali (T1-T3), Ethan and Nareen (T4-T6), Ali and Nareen (T7-T9)]&lt;br /&gt;
* COMP 3000 A3: Thu: 08:35 - 09:55 at St. Patrick&#039;s 303 (SP303). [Ali and Nareen (T1-T9)] &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|+ Tutorial Schedules&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! Section !! Date !! Time !! Room !! TAs&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems 2023F Tutorials: Tutorial 1 | Tutorial 1]] || A1 || Sep 26 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Sep 28 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Sep 29 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 2 | Tutorial 2]] || A1 || Oct 3 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 5 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 6 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 3 | Tutorial 3]] || A1 || Oct 10 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Oct 12 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Oct 13 || 11:35 am-12:55 pm || LA720 || Ethan and Ali&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems F23: Tutorial 4 | Tutorial 4]] || A1 || Oct 31 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 2 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 3 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | [[COMP3000 Operating Systems W23: Tutorial 5 | Tutorial 5]] || A1 || Nov 7 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 9 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 10 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 6 || A1 || Nov 14 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 16 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 17 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 7 || A1 || Nov 21 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 23 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Nov 24 || 11:35 am-12:55 pm || LA720 || Ethan and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 8 || A1 || Nov 28 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Nov 30 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 1 || 11:35 am-12:55 pm || LA720 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;3&amp;quot; | Tutorial 9 || A1 || Dec 5 || 8:35 am-9:55 am || LA720 || Ethan and Sneha&lt;br /&gt;
|-&lt;br /&gt;
| A3 || Dec 7 || 8:35 am-9:55 am || SP303 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
| A2 || Dec 8 || 11:35 am-12:55 pm || MC2000 || Ali and Nareen&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24542</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24542"/>
		<updated>2023-10-24T20:56:11Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Optional/advanced tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;code&amp;gt;adduser&amp;lt;/code&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;code&amp;gt;su someuser&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;code&amp;gt;man&amp;lt;/code&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;chown&amp;lt;/code&amp;gt; command makes the binary owned by root, and the &amp;lt;code&amp;gt;chmod&amp;lt;/code&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;code&amp;gt;/etc/shadow&amp;lt;/code&amp;gt; and you may need to learn how to use the &amp;lt;code&amp;gt;openssl passwd&amp;lt;/code&amp;gt; command.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24541</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24541"/>
		<updated>2023-10-24T20:55:07Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Optional/advanced tasks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;code&amp;gt;adduser&amp;lt;/code&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;code&amp;gt;su someuser&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;code&amp;gt;man&amp;lt;/code&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;chown&amp;lt;/code&amp;gt; command makes the binary owned by root, and the &amp;lt;code&amp;gt;chmod&amp;lt;/code&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;code&amp;gt;/etc/shadow&amp;lt;/code&amp;gt; and you may need to learn how to use the &amp;lt;code&amp;gt;openssl passwd&amp;lt;/code&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Note: you are &#039;&#039;&#039;not&#039;&#039;&#039; required to complete and submit work for this optional task. Doing it will enhance your understanding of how authentication works.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24540</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24540"/>
		<updated>2023-10-24T20:53:43Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Logging in to a Linux system */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;code&amp;gt;adduser&amp;lt;/code&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;code&amp;gt;su someuser&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;code&amp;gt;man&amp;lt;/code&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;chown&amp;lt;/code&amp;gt; command makes the binary owned by root, and the &amp;lt;code&amp;gt;chmod&amp;lt;/code&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; and you may need to learn how to use the &amp;lt;tt&amp;gt;openssl passwd&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Note: you are &#039;&#039;&#039;not&#039;&#039;&#039; required to complete and submit work for this optional task. Doing it will enhance your understanding of how authentication works.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24539</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24539"/>
		<updated>2023-10-24T20:49:37Z</updated>

		<summary type="html">&lt;p&gt;Abdou: /* Tasks/Questions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;tt&amp;gt;adduser&amp;lt;/tt&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;tt&amp;gt;su someuser&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;chown&amp;lt;/tt&amp;gt; command makes the binary owned by root, and the &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; and you may need to learn how to use the &amp;lt;tt&amp;gt;openssl passwd&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Note: you are &#039;&#039;&#039;not&#039;&#039;&#039; required to complete and submit work for this optional task. Doing it will enhance your understanding of how authentication works.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24538</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24538"/>
		<updated>2023-10-24T20:49:22Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;tt&amp;gt;adduser&amp;lt;/tt&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;tt&amp;gt;su someuser&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;chown&amp;lt;/tt&amp;gt; command makes the binary owned by root, and the &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; and you may need to learn how to use the &amp;lt;tt&amp;gt;openssl passwd&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Note: you are &#039;&#039;&#039;not&#039;&#039;&#039; required to complete and submit work for this optional task. Doing it will enhance your understanding of how authentication works.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24537</id>
		<title>COMP3000 Operating Systems F23: Tutorial 4</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP3000_Operating_Systems_F23:_Tutorial_4&amp;diff=24537"/>
		<updated>2023-10-24T20:48:25Z</updated>

		<summary type="html">&lt;p&gt;Abdou: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial, you will learn about how user accounts and logging in work through exploring [https://people.scs.carleton.ca/~abdou/comp3000/f23/tut4/3000userlogin.c 3000userlogin.c]. You’ll also have a better understanding of the permission system and the shell/terminal environment.&lt;br /&gt;
&lt;br /&gt;
==Logging in to a Linux system==&lt;br /&gt;
As mentioned in the lecture, in order to log in to a Linux-like system (including UNIX), the following steps must occur (potentially not in this order).&lt;br /&gt;
# The user must use a terminal to connect to the system, locally or remotely (e.g., initiated by &amp;lt;tt&amp;gt;/usr/sbin/getty&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# The user must authenticate themselves, proving an identify with authorized access to the system. By default, this is done through a username and password (e.g., by exec’ing &amp;lt;tt&amp;gt;/usr/bin/login&amp;lt;/tt&amp;gt;).&lt;br /&gt;
# After authentication, login changes uid and gid to that of the new user.&lt;br /&gt;
# Login sets up other aspects of the user&#039;s context (mainly setting key environment variables).&lt;br /&gt;
# Login does an exec of the user&#039;s chosen/default shell.&lt;br /&gt;
&lt;br /&gt;
[https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut4/3000userlogin.c 3000userlogin] is a basic implementation of steps 3-5. (Steps 1 and 2 are accomplished by running 3000userlogin in a shell, as running an external command means the shell also creates a new process for it, assuming an authenticated session with a terminal.)&lt;br /&gt;
&lt;br /&gt;
When 3000userlogin is properly compiled and set up, you can run:&lt;br /&gt;
&lt;br /&gt;
 ./3000userlogin student&lt;br /&gt;
&lt;br /&gt;
and you&#039;ll be logged in (again) as &amp;quot;student&amp;quot;. This only works when you’re already logged in as student (see below).&lt;br /&gt;
&lt;br /&gt;
You can add a user with the &amp;lt;tt&amp;gt;adduser&amp;lt;/tt&amp;gt; command. For example, to create the user &amp;quot;someuser&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 sudo adduser someuser&lt;br /&gt;
&lt;br /&gt;
Note you&#039;ll have to answer several questions. Then you need to switch to someuser (&amp;lt;tt&amp;gt;su someuser&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
If you just compile 3000userlogin normally, you won&#039;t be able to log in as anyone except the current user (be it student or someuser). To set up 3000userlogin properly, do the following:&lt;br /&gt;
&lt;br /&gt;
 sudo chown root:root 3000userlogin&lt;br /&gt;
 sudo chmod u+s 3000userlogin&lt;br /&gt;
&lt;br /&gt;
Feel free to read the &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; pages for both commands to learn more.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;chown&amp;lt;/tt&amp;gt; command makes the binary owned by root, and the &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command makes it setuid. Thus, when the program is exec&#039;d it will have an effective user ID of root (euid=0). To facilitate the following tasks, you may also want to create different versions of 3000userlogin by naming them, e.g., 3000userlogin.setuid and 3000userlogin.orig, of your choice.&lt;br /&gt;
&lt;br /&gt;
==Tasks/Questions==&lt;br /&gt;
# Compile and setup [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w23/tut4/3000userlogin.c 3000userlogin] as described above. Create a new user account. Verify that you can use 3000userlogin to login as the new user without typing the password of the new user (without logging in beforehand). Think about &amp;lt;u&amp;gt;why&amp;lt;/u&amp;gt; you are able to avoid typing the password and still get authenticated.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; is the syntax highlighting gone (coloring characters)? What simple change (one line) can you make to have 3000userlogin preserve the colors? (Hint: check the environment variables)&lt;br /&gt;
# What is returned as the user&#039;s password by &amp;lt;tt&amp;gt;getpwnam()&amp;lt;/tt&amp;gt; (in terms of type)? Is this what you expected? Read the manual page as you find necessary.&lt;br /&gt;
# Compare the uid, gid, euid, egid when running 3000userlogin as a regular user (this means without the “chown” and “chmod” commands above), running it setuid root, and running it as root (i.e., running it from a root shell without the setuid bit set, e.g., “&amp;lt;tt&amp;gt;sudo ./3000userlogin someuser&amp;lt;/tt&amp;gt;”). Also check to see what happens when you set the setgid bit.&lt;br /&gt;
# &amp;lt;u&amp;gt;Why&amp;lt;/u&amp;gt; does 3000userlogin change its gid before changing its uid? &amp;lt;u&amp;gt;What happens&amp;lt;/u&amp;gt; if you switch the order of these operations?&lt;br /&gt;
# Make 3000userlogin use the shell that is specified in the user&#039;s password entry (which is actually read from &amp;lt;tt&amp;gt;/etc/passwd&amp;lt;/tt&amp;gt;). Check by setting someuser’s shell to a new shell and then see if that new shell runs when you run 3000userlogin. You can change a user&#039;s shell with the &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
# Can you set 3000shell to be a user&#039;s default shell? What changes do you have to make for &amp;lt;tt&amp;gt;chsh&amp;lt;/tt&amp;gt; to accept 3000shell? Does anything obvious break when running 3000shell this way, and how can you change 3000userlogin to fix it?&lt;br /&gt;
# Does a user&#039;s default shell have to be a regular shell? Could it instead be an arbitrary program? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Are the environment variables set by 3000userlogin the only environment variables that are set (visible) after you successfully login? &amp;lt;u&amp;gt;How do you know&amp;lt;/u&amp;gt;?&lt;br /&gt;
# Note that 3000userlogin uses &amp;lt;tt&amp;gt;environ&amp;lt;/tt&amp;gt; not &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; (as an argument to &amp;lt;tt&amp;gt;main()&amp;lt;/tt&amp;gt;) to access environment variables. &amp;lt;u&amp;gt;Why not&amp;lt;/u&amp;gt; use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt;? (Try changing the code to use &amp;lt;tt&amp;gt;envp&amp;lt;/tt&amp;gt; and see what happens: worse or better?)&lt;br /&gt;
&lt;br /&gt;
==Optional/advanced tasks==&lt;br /&gt;
# Prompt for the user&#039;s password before logging the user in (Step 2 above). To do this, you&#039;ll need to get the right password hash and then figure out how to hash the entered password to check if it matches. Recall the format of &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; and you may need to learn how to use the &amp;lt;tt&amp;gt;openssl passwd&amp;lt;/tt&amp;gt; command.&lt;br /&gt;
&lt;br /&gt;
Note: you are &#039;&#039;&#039;not&#039;&#039;&#039; required to complete and submit work for this optional task. Doing it will enhance your understanding of how authentication works.&lt;/div&gt;</summary>
		<author><name>Abdou</name></author>
	</entry>
</feed>