<?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=HebaJallad</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=HebaJallad"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/HebaJallad"/>
	<updated>2026-05-12T21:37:33Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_23&amp;diff=21383</id>
		<title>Operating Systems 2017F Lecture 23</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_23&amp;diff=21383"/>
		<updated>2017-12-12T04:20:02Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec23-07Dec2017.mp4 Lecture 23 Video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 23&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
How can you tell when a process has been compromised?&lt;br /&gt;
 - from outside the process&lt;br /&gt;
&lt;br /&gt;
Classic: signatures&lt;br /&gt;
 - is it running &amp;quot;bad code&amp;quot;&lt;br /&gt;
 - is it doing &amp;quot;bad things&amp;quot;&lt;br /&gt;
   - bad system calls&lt;br /&gt;
&lt;br /&gt;
For a process to do damage, it has to make &amp;quot;bad&amp;quot; system calls&lt;br /&gt;
&lt;br /&gt;
How can I tell if a process is making bad system calls?&lt;br /&gt;
&lt;br /&gt;
I want to be lazy&lt;br /&gt;
 - complex rules are a pain&lt;br /&gt;
 - and, they don&#039;t work well either&lt;br /&gt;
&lt;br /&gt;
Make the computer solve the problem for me of determining what is good and bad&lt;br /&gt;
 - use machine learning&lt;br /&gt;
&lt;br /&gt;
But I can&#039;t teach good versus bad because I don&#039;t know bad very well&lt;br /&gt;
&lt;br /&gt;
But...I do know how systems &amp;quot;normally&amp;quot; behave&lt;br /&gt;
&lt;br /&gt;
How about teaching the system to differentiate normal from abnormal?&lt;br /&gt;
 - normal is &amp;quot;good&amp;quot;&lt;br /&gt;
 - abnormal may be bad&lt;br /&gt;
&lt;br /&gt;
abnormal but not bad =&amp;gt; false positive&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
How do we detect abnormal system calls?&lt;br /&gt;
&lt;br /&gt;
Learn normal patterns of system calls over time&lt;br /&gt;
once you&#039;ve learned enough, watch for abnormal system calls&lt;br /&gt;
&lt;br /&gt;
Since I&#039;m lazy, I want it to learn as it runs&lt;br /&gt;
 - and automatically decide when it has learned enough&lt;br /&gt;
&lt;br /&gt;
Could I do the learning in a process (or set of processes)?&lt;br /&gt;
 - you could, but all data would have to come from the kernel&lt;br /&gt;
&lt;br /&gt;
Want something fast and simple&lt;br /&gt;
 - implement in the kernel&lt;br /&gt;
&lt;br /&gt;
How simple could it be?&lt;br /&gt;
&lt;br /&gt;
First assumption: ignore arguments&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Second assumption: look at ordering of systems calls on a per-thread, per-process basis&lt;br /&gt;
&lt;br /&gt;
Third assumption: characterize processes based on the executable they are running&lt;br /&gt;
&lt;br /&gt;
 - model per executable, each trained on multiple processes&lt;br /&gt;
&lt;br /&gt;
How to model the trace of system calls coming from a process?&lt;br /&gt;
&lt;br /&gt;
* frequency analysis?&lt;br /&gt;
  - on a system call basis&lt;br /&gt;
  - high variance&lt;br /&gt;
&lt;br /&gt;
* what system calls are made (and not made)?&lt;br /&gt;
&lt;br /&gt;
* short sequences of system calls?&lt;br /&gt;
  6-10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Addiional notes :&lt;br /&gt;
&lt;br /&gt;
Assignment 4 Review:&lt;br /&gt;
&lt;br /&gt;
11) Dd write things in blocks so each write is a system call&lt;br /&gt;
If it is read then both bs and ibs are correct &lt;br /&gt;
You can also dd and then run strace on it and see how many bytes you write&lt;br /&gt;
12) kernel doesn’t make a system call , processes do. System call transition from kernel to userspace. You can do function system &lt;br /&gt;
*********************************************************************************&lt;br /&gt;
Someone messed up a process, how can you identify has been compromised from outside the process?&lt;br /&gt;
-	 &amp;gt; use classes, signatures, pattern matching, running bad code,bad strings etc.&lt;br /&gt;
o	Process doing bad things, such as system calls, this may damage the system&lt;br /&gt;
o	Ex: password programs starts modifying file other than the password&lt;br /&gt;
-	Refine the question, how can I identify if a process is making bad system calls?&lt;br /&gt;
o	Inspecting this while the program is running is inefficient and expensive &lt;br /&gt;
o	Be lazy and don’t make rules as a scale &lt;br /&gt;
o	Make the computer solve this problem and determine if it is bad or good by using machine learning&lt;br /&gt;
	However , I cant tell it the difference between good and bad but I don’t know bad very well&lt;br /&gt;
	 I know how the computer behaves&lt;br /&gt;
-	Refine the question again: How about teaching the system differentiate normal and abnormal?&lt;br /&gt;
o	Normal is good&lt;br /&gt;
o	Abnormal may be bad&lt;br /&gt;
-	False positives are bad(especially in security)&lt;br /&gt;
-	 Refine the question, how do we detect abnormal system call?&lt;br /&gt;
o	By learning normal patterns of system call over time then watch for abnormal system calls.&lt;br /&gt;
-	System calls are complicates, some have arguments like execve and some don’t like fork. To learn all of their complexity&lt;br /&gt;
-	Learn as it runs:&lt;br /&gt;
o	To automatically decide when it has learned enough &lt;br /&gt;
-	You can do the learning in a process but you want it to be fast and simple and implement in the kernel. &lt;br /&gt;
-	You want something really simple and run it as you go, but how simple could it be?&lt;br /&gt;
o	Do strace xclock&lt;br /&gt;
1)	Ignore arguments&lt;br /&gt;
2)	Analyze the ordering of system calls on per-thread, per-process basis&lt;br /&gt;
3)	Characterize system calls behavior , according to the executable they are running  &lt;br /&gt;
a.	Example: xclock cant be based of ls &lt;br /&gt;
b.	Model per executable (can do frequency analysis)&lt;br /&gt;
-Refine, how to model the trace of system, calls coming from process?&lt;br /&gt;
-&amp;gt; Frequency analysis &lt;br /&gt;
- ex : Is xclock behaving weird, &lt;br /&gt;
- run strace of different programs and watch the variation in a the pattern of sequences and it detects if a program has been compromised&lt;br /&gt;
-what system calls are made and not made?&lt;br /&gt;
- Short sequences&lt;br /&gt;
	- 6 – 10&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
Written solutions for midterm exam are on the course webpage &amp;lt;br&amp;gt;&lt;br /&gt;
Assignment 4 &amp;lt;br&amp;gt;&lt;br /&gt;
Q2: SSH keygen generates the secret key and the public key file. The private key is stored in the private key file: .ssh/id_rsa  &amp;lt;br&amp;gt;&lt;br /&gt;
Q4: Both lines because first you start from 1 and then increment from there. &amp;lt;br&amp;gt;&lt;br /&gt;
Q11: Only bs because it is write. Would be ibs and bs if it was read. &amp;lt;br&amp;gt;&lt;br /&gt;
Q12: Local kernel forwards the write system call but doesn&#039;t actually make the system call. Kernels don&#039;t make system calls.&amp;lt;br&amp;gt;&lt;br /&gt;
Lecture 23 Prof Notes &amp;lt;br&amp;gt;&lt;br /&gt;
-----------------&lt;br /&gt;
How can you tell when a process has been compromised. &amp;lt;br&amp;gt;&lt;br /&gt;
- from outside the process &amp;lt;br&amp;gt;&lt;br /&gt;
Use signatures &amp;lt;br&amp;gt;&lt;br /&gt;
- is it running &amp;quot;bad code&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
- is it doing &amp;quot;bad things&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
-- For example: password program start modifying files other than etc/password. You could specify rules to prevent this. &amp;lt;br&amp;gt;&lt;br /&gt;
-- bad system calls&amp;lt;br&amp;gt;&lt;br /&gt;
For a process to do damage, it has to make &amp;quot;bad&amp;quot; system calls &amp;lt;br&amp;gt;&lt;br /&gt;
I want to be lazy &amp;lt;br&amp;gt;&lt;br /&gt;
- complex rules are a pain &amp;lt;br&amp;gt; &lt;br /&gt;
- and they don&#039;t work well either &amp;lt;br&amp;gt; &lt;br /&gt;
Make the computer solve this problem &amp;lt;br&amp;gt;&lt;br /&gt;
- Use Machine Learning &amp;lt;br&amp;gt;&lt;br /&gt;
I can&#039;t teach good versus bad if I don&#039;t know what is bad &amp;lt;br&amp;gt;&lt;br /&gt;
But I know how systems behave normally &amp;lt;br&amp;gt;&lt;br /&gt;
How about teaching the system to differentiate normal from abnormal &amp;lt;br&amp;gt;&lt;br /&gt;
- normal is good &amp;lt;br&amp;gt;&lt;br /&gt;
- abnormal may be bad &amp;lt;br&amp;gt;&lt;br /&gt;
abnormal but not bad =&amp;gt; false positive &amp;lt;br&amp;gt;&lt;br /&gt;
False positives can be a big issue because they may cause ppl to not trust the machine&#039;s detection capabilities &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How can we detect abnormal system calls? &amp;lt;br&amp;gt;&lt;br /&gt;
Learn normal patterns of system calls over time &amp;lt;br&amp;gt;&lt;br /&gt;
Once you&#039;ve learned enough, watch for abnormal system calls &amp;lt;br&amp;gt;&lt;br /&gt;
Since I&#039;m lazy, I want to learn it as it runs &amp;lt;br&amp;gt;&lt;br /&gt;
- and automatically decide when it has learned enough &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Could I do the learning in a process (or set of processes)? &amp;lt;br&amp;gt;&lt;br /&gt;
you could, but all data would have to come from the kernel &amp;lt;br&amp;gt;&lt;br /&gt;
Want something fast and simple &amp;lt;br&amp;gt;&lt;br /&gt;
- implement in the kernel &amp;lt;br&amp;gt; &lt;br /&gt;
How simple could it be? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
First assumption: ignore arguments &amp;lt;br&amp;gt;&lt;br /&gt;
Second assumption: look at ordering of system calls on a per-thread, per-process basis &amp;lt;br&amp;gt;&lt;br /&gt;
Third Assumption: characterize processes based on the executable they are running &amp;lt;br&amp;gt;&lt;br /&gt;
model per executable, each trained on multiple processes &amp;lt;br&amp;gt;&lt;br /&gt;
How to model the trace of system calls coming from a procesd &amp;lt;br&amp;gt;&lt;br /&gt;
* frequency analysis? &amp;lt;br&amp;gt;&lt;br /&gt;
- on a system call basis &amp;lt;br&amp;gt;&lt;br /&gt;
- high variance &amp;lt;br&amp;gt;&lt;br /&gt;
* what system calls are made (and not made)? &amp;lt;br&amp;gt;&lt;br /&gt;
* short sequence of system calls? 6-10 calls &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 Lecture 23&lt;br /&gt;
&lt;br /&gt;
How can you tell a process has been compromised (i.e. from outside the process)?&lt;br /&gt;
* The process is working on behalf of an attacker&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Classic way to do this: &lt;br /&gt;
* Pattern matching -&amp;gt; signatures&lt;br /&gt;
::* is the process running bad code?&lt;br /&gt;
::* is the process doing bad things?&lt;br /&gt;
:::* i.e. /etc/passwd -&amp;gt; password prog. should only be able to access it&lt;br /&gt;
:::* if a process is going to do bad things, it&#039;s going to make &amp;quot;bad&amp;quot; system calls&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
So, how can we tell if a process is making bad system calls?&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Don&#039;t want to sit and write complex rules to determine:&lt;br /&gt;
* Which programs should make which system calls, etc.&lt;br /&gt;
::* i.e. policy based systems and sandboxing of processes&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore, we want the computer to determine what call is good/bad.&lt;br /&gt;
* i.e. use machine learning&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The issue is, we have to demonstrate, not just &amp;quot;good&amp;quot;, but also &amp;quot;bad&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
We have lots of examples of &amp;quot;bad&amp;quot;, but is not necessarily representative of &amp;quot;bad&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
Difficult to enumerate all possible occurences of &amp;quot;bad&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
However, we know how systems &amp;quot;normally&amp;quot; behave&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How about teaching the system to differentiate normal from abnormal?&lt;br /&gt;
* Assume:&lt;br /&gt;
::* normal is &amp;quot;good&amp;quot;&lt;br /&gt;
::* abnormal may be bad&lt;br /&gt;
:::* there is no guarantee that abnormal is bad, however, if it&#039;s bad, but not abnormal... we&#039;re in trouble&lt;br /&gt;
:::* false positives are bad (i.e. abnormal but not good)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do we detect abnormal system calls?&lt;br /&gt;
* a machine learning problem&lt;br /&gt;
* the system should learn as it runs and decide when it has learned &amp;quot;enough&amp;quot;&lt;br /&gt;
::* learn normal patterns of system calls over time&lt;br /&gt;
:::* once learned enough, watch for abnormal system calls&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Could we do the learning within processes?&lt;br /&gt;
* possible, but all data would have to come from the kernel&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Want something fast and simple, so it can be implemented in the kernel&lt;br /&gt;
* you&#039;re right at ground-level, where decisions are being made&lt;br /&gt;
::* i.e. if bad system call being made -&amp;gt; can stop it immediatelly&lt;br /&gt;
&lt;br /&gt;
* don&#039;t want to be training a neural network to do this -&amp;gt; too complicated, too much overhead&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Thu 7 Dec 2017 13:53:01 EST -&amp;gt; Video of observing system calls, ls vs. xclock&#039;&#039;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
=== First assumption: ===&lt;br /&gt;
ignore the arguments system calls are making -&amp;gt; look at the calls themselves&lt;br /&gt;
* but, different processes invoke different calls -&amp;gt; how to compare them?&lt;br /&gt;
* even multi-threaded processes will mirror the structure of the code in the calls it makes&lt;br /&gt;
&lt;br /&gt;
=== Second assumption: ===&lt;br /&gt;
look at the ordering of system calls on a per-thread, per-process basis&lt;br /&gt;
* doesn&#039;t make sense to think of &#039;ls&#039; system calls in the context of &#039;xclock&#039; system calls&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Therefore, any profiling will be based on the code being executed&lt;br /&gt;
&lt;br /&gt;
=== Third assumption: ===&lt;br /&gt;
characterize processes based on the executable they are running&lt;br /&gt;
* model per executable, with each one trained on multiple processes&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do we model the trace of system calls coming from a process?&lt;br /&gt;
* How often do different system calls hapen? -&amp;gt; frequency analysis&lt;br /&gt;
* high variance -&amp;gt; the calls change frequently&lt;br /&gt;
::* i.e. ls of a large dir vs. small dir&lt;br /&gt;
&lt;br /&gt;
::* What system calls does a process makes or doesn&#039;t make?&lt;br /&gt;
&lt;br /&gt;
::* Rather than examining if a process does or doesn&#039;t make a particular system call, instead look at short sequences of system calls being made.&lt;br /&gt;
:::* What is the variation in the pattern of sequences of calls being made? A compromised program will be detectable.&lt;br /&gt;
&lt;br /&gt;
:::* Table lookup of sequences made by a program and compare against new sequences&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How short is a short sequence of system calls? -&amp;gt; 6 to 10&lt;br /&gt;
&lt;br /&gt;
When a program is running, the short sequences define the control flow path of the program&amp;lt;br&amp;gt;&lt;br /&gt;
The short sequences together represent the control flow&amp;lt;br&amp;gt;&lt;br /&gt;
When a program is exploited, an abnormal control flow, an uncommon path, is being used&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Try the simple hack first, rather than designing/engineering a complex solution&lt;br /&gt;
* the simple hack will often present valuable insights&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21355</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21355"/>
		<updated>2017-12-07T16:19:08Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec19-21Nov2017.mp4]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 19&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
&lt;br /&gt;
* lots of programs have &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions? In what sense?&lt;br /&gt;
  - Linux kernel modules&lt;br /&gt;
  - FUSE applications?&lt;br /&gt;
  - the Linux kernel?&lt;br /&gt;
  - node web applications?&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up event handlers&lt;br /&gt;
 - the event loop can be implicit or explicit&lt;br /&gt;
   - or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; of some kind&lt;br /&gt;
 - event loops poll (check) to see when there are new events&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Additional Notes:&lt;br /&gt;
&lt;br /&gt;
Important notes:&lt;br /&gt;
How can you recover a filesystem?&lt;br /&gt;
How do you delete a file?&lt;br /&gt;
What is a filesystem?: &lt;br /&gt;
*persistent data structure &lt;br /&gt;
* stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
*maps hierarchical filenames to file contents &lt;br /&gt;
*has metadata about files (somwhow)&lt;br /&gt;
What is in a filesystem?&lt;br /&gt;
*data blocks &lt;br /&gt;
*metadata blocks &lt;br /&gt;
How do you organize metdata:&lt;br /&gt;
1)	First you must identify characteristics of the file system &lt;br /&gt;
Superblock :  summary y block which tells you about the other blocks you have and it depends on which file system you have. It’s usually the first block of a file system. &lt;br /&gt;
In the superblock? :&lt;br /&gt;
1)	What kind of file system is this? By checking what is the magic number it has &lt;br /&gt;
2)	How big is the file system?&lt;br /&gt;
3)	How is it organized?&lt;br /&gt;
4)	Where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
*How can you identify which file system it is from looking at the super class&lt;br /&gt;
-&amp;gt; google “magic number of a file” &lt;br /&gt;
-&amp;gt; ex: jpg ctr^c ctr^c : switched the pictures into a binary file &lt;br /&gt;
-&amp;gt; look at the beginning of the file you will see JFIF:  first several bytes in general that identifies the type of the file (magic number)&lt;br /&gt;
File extension : &lt;br /&gt;
	what is it ? &lt;br /&gt;
	is it important&lt;br /&gt;
	the kernel does not know and not care about it&lt;br /&gt;
&lt;br /&gt;
For POSIX file systems: &lt;br /&gt;
-.&amp;gt; file metadata is stored in inodes &lt;br /&gt;
-.&amp;gt; most have pre-reserved inodes &lt;br /&gt;
   -&amp;gt; the only way you can run out of inodes if you keep creating small files &lt;br /&gt;
&lt;br /&gt;
Usenet : al the things you use to post messages thro social media, email, etc. Those were made using Usenet. Like email but Local Usenet server. But it died over time. Every message is stored in an individual file. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Important commands: &lt;br /&gt;
File * : to identify the kind of file system&lt;br /&gt;
1.	As : Run dumpe2fs foo. What does the output of this command mean?&lt;br /&gt;
	Does this give you info about the file system?&lt;br /&gt;
	File bar : bar is the file name and cp comp3000-midterm-2017.pdf bar &lt;br /&gt;
	Evince bar : opens up the pdf file&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
* lots of program shave &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&amp;lt;br&amp;gt;&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions?&amp;lt;br&amp;gt;&lt;br /&gt;
** Linux kernel modules&amp;lt;br&amp;gt;&lt;br /&gt;
** FUSE applications?&amp;lt;br&amp;gt;&lt;br /&gt;
** the linux kernel?&amp;lt;br&amp;gt;&lt;br /&gt;
** node web applications?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up even handlers&amp;lt;br&amp;gt;&lt;br /&gt;
* the event loop can be implicit or explicit&amp;lt;br&amp;gt;&lt;br /&gt;
** or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; some kind&amp;lt;br&amp;gt;&lt;br /&gt;
* event loops poll (check) to see when there are new events&amp;lt;br&amp;gt;&lt;br /&gt;
* what are event loops for node app?&amp;lt;br&amp;gt;&lt;br /&gt;
** where are interrupts for node apps? &amp;lt;br&amp;gt;&lt;br /&gt;
***Incoming network requests, it&#039;s an event&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code run differently in the kernel : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1)functions runs on the bhealf of insmod, unles sit is Independence context &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2)codes that run on the bhelaf o the process&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3)after an interrupt: no process , it is an interrupt cotext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) file names : regular programs but the square brackets, execution context + address space. they share the kernel&#039;s address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .&amp;lt;br&amp;gt;&lt;br /&gt;
multi- threaded: maintains multiple address processes , ex: fire fox. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ps -elF | less &amp;quot;number&amp;quot; : displays threads.&lt;br /&gt;
&lt;br /&gt;
top : displays all the processes &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ls time : shows you the time . &lt;br /&gt;
&lt;br /&gt;
sys: how much time in the kernel space&lt;br /&gt;
real: how much time &lt;br /&gt;
user : how much time in user space &lt;br /&gt;
&lt;br /&gt;
process : can&#039;t manipulate its own memory map directly, it has an address space, but cant change it. Process: is limited but the kernel is not and the kernel can change it&#039;s own address and in charge of its self. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kernel tasks : are threads, when a process makes a system call , thi sis schedules in the process priority. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When running &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;quot;time ls&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
real = realtime it took to run&lt;br /&gt;
user = the user space time&lt;br /&gt;
sys = kernel time&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What&#039;s flow of control in tutorial 7? &amp;lt;br&amp;gt;&lt;br /&gt;
What is the connection? &amp;lt;br&amp;gt;&lt;br /&gt;
To exit the program, we must unmount the filesystem, run &amp;quot;sudo umount mnt&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
what is the flow of control ? what connection between things we are doing in the new terminal and the old one&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; these programs are communicating to each other, it will be invoked when we use mnt (mount) the kernel knows it is a filesystem , process runs system calls, then kernel talks to out original terminal. How? you can use strace to know, it is waiting to be invoked, to receive and responds to messages. events will be passed off to another process. switching between one process to another. it has potential security benefits. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Key to understand this tutorial : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; understand net flow control. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how do processes communicate?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how does it take a directory int and creates a filesystem from it?: &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
***sub tree starting at mount is delegated to this process.&amp;lt;br&amp;gt; &lt;br /&gt;
***permissions are limited &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How to kill it?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; ctrl c , no , you can but the kernel will be unhappy.&amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; unmount the file system when you are done using it &amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; umount / you have to do it as root &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Node web applications &amp;lt;br&amp;gt;&lt;br /&gt;
* Theres not a dedicated main function but its the first thing that runs &amp;lt;br&amp;gt;&lt;br /&gt;
* Every line in the node application terminates &amp;lt;br&amp;gt;&lt;br /&gt;
* If you start a web server, the function call starting it will terminate &amp;lt;br&amp;gt;&lt;br /&gt;
* Whats running? The main has finished. Is the program doing anything actively if theres no external input? &amp;lt;br&amp;gt;&lt;br /&gt;
* In many systems main just sets up event handlers &amp;lt;br&amp;gt;&lt;br /&gt;
* The event loop can be implicit or explicit &amp;lt;br&amp;gt;&lt;br /&gt;
* Its possible to have no loop at all just handlers and interrupts of some kind &amp;lt;br&amp;gt;&lt;br /&gt;
* Event loops check to see when there are new events &amp;lt;br&amp;gt;&lt;br /&gt;
* Os kernels behave the same way as node applications &amp;lt;br&amp;gt;&lt;br /&gt;
* Waiting for events &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
What happens when you use insmod? &amp;lt;br&amp;gt;&lt;br /&gt;
* In newgetpid: Init and exit are called when the insmod program makes system calls to load the module &amp;lt;br&amp;gt;&lt;br /&gt;
* Init is run on behalf on insmod &amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel code fits into 3 categories &amp;lt;br&amp;gt;&lt;br /&gt;
** Code that runs on behalf of a process &amp;lt;br&amp;gt;&lt;br /&gt;
** Code that runs after an interrupt &amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel threads, has lots of functionality &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Why is a kernel thread not a process? &amp;lt;br&amp;gt;&lt;br /&gt;
* The kernel maintains its own address space &amp;lt;br&amp;gt;&lt;br /&gt;
* Has its own virtual address map &amp;lt;br&amp;gt;&lt;br /&gt;
* The kernel always has just 1 address space regardless of how many threads there are &amp;lt;br&amp;gt;&lt;br /&gt;
* Processes cannot manipulate its own memory map directly, needs to ask kernel first &amp;lt;br&amp;gt;&lt;br /&gt;
* Processes are limited, the kernel is not, has control over itself &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel tasks = kernel threads &amp;lt;br&amp;gt;&lt;br /&gt;
* Independently scheduled &amp;lt;br&amp;gt;&lt;br /&gt;
* Once we call insmod everything happens in user space &amp;lt;br&amp;gt;&lt;br /&gt;
* Strace uses a system call called ptrace &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Tutorial 7: Fuse &amp;lt;br&amp;gt;&lt;br /&gt;
* Memoryll.py program &amp;lt;br&amp;gt;&lt;br /&gt;
* Always unmount a filesystem when youre done using it &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*No class Thursday! no office hours on Wednesday&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_22&amp;diff=21354</id>
		<title>Operating Systems 2017F Lecture 22</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_22&amp;diff=21354"/>
		<updated>2017-12-07T16:17:29Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec22-05Dec2017.mp4 Lecture 22 Video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 22&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
What&#039;s left?&lt;br /&gt;
&lt;br /&gt;
* scheduling&lt;br /&gt;
* device drivers&lt;br /&gt;
* virtual memory&lt;br /&gt;
  - page replacement algorithms&lt;br /&gt;
    - predict the future (optimal)&lt;br /&gt;
    - least recently used&lt;br /&gt;
    - one-handed, two-handed clocks&lt;br /&gt;
* power management&lt;br /&gt;
* security&lt;br /&gt;
  - hardening processes so coding errors don&#039;t lead to vulnerabilities&lt;br /&gt;
    (machine code injection, e.g. buffer overflow attacks)&lt;br /&gt;
&lt;br /&gt;
* virtualization&lt;br /&gt;
  - hardware-level  (run multiple kernels)  &amp;lt;-- vmware, openstack&lt;br /&gt;
  - OS-level        (run multiple userspaces) &amp;lt;-- containers, web hosting&lt;br /&gt;
  - application level (run programs on simulated machines)&lt;br /&gt;
     - JVM&lt;br /&gt;
     - JavaScript runtime in browsers/node&lt;br /&gt;
 &lt;br /&gt;
* distributed operating systems&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ADDITIONAL NOTES :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Comp 3000&lt;br /&gt;
Premissions on this directory, readable writable and executable&lt;br /&gt;
Execute permission on a Regular file : you can execute &lt;br /&gt;
Execute permission on a directory : follow the links on the directory&lt;br /&gt;
Can’t make any changes to the directory if you can’t write&lt;br /&gt;
There are exceptions :  &lt;br /&gt;
Less/etc/passwd: doesn’t actually store the password&lt;br /&gt;
 if you want to change this file, you must have a way to allow limited editing to this. &lt;br /&gt;
	You can have a process running as root and send it signals and tell it to update the entry in the password file. &lt;br /&gt;
o	Starting up a process which has more privileges which I can do , ex: EUID &lt;br /&gt;
Ls –la /sbin | grep rws : execve EUID will be set to whatever it is from the file . equal to the uid&lt;br /&gt;
Ls –la /sbin | grep r-s: s is a sticky bit, if you need extra premissions &lt;br /&gt;
You want your stcky bit to be a regular user &lt;br /&gt;
Euid = uid yes&lt;br /&gt;
Cd /tmp : directory in which everyone can write &lt;br /&gt;
This allows binaries run as users&lt;br /&gt;
Set uid and get guid : &lt;br /&gt;
Myid has euid now &lt;br /&gt;
Change the ownership &lt;br /&gt;
-	&amp;gt; chown root : root myid &lt;br /&gt;
-	&amp;gt;chown root : root mytouch &lt;br /&gt;
Ls –la : 3rd column identifies the ownership of each file on the file system&lt;br /&gt;
You can overwrite any file on the fille system using mytouch binary &lt;br /&gt;
Question : why can you remove file owned by root? &lt;br /&gt;
-	&amp;gt; to change the context of the directory , the permissions of a file don’t matter but the permissions and privileges  of the directory only matter&lt;br /&gt;
o	Someone putting a directory in ur directory is hard to remove&lt;br /&gt;
-	Ssh to a remote serve : &lt;br /&gt;
-	2 public keys involved: identity key, private key pair: one in the known host file (connecting to the machine). &lt;br /&gt;
-	If you rm _known host and do ssh , a question will ask you to add the key to ur host file &lt;br /&gt;
-	What happens if a person tries to personate your machine (same IP address)? &lt;br /&gt;
o	It will identity it is a fake person from the host&lt;br /&gt;
First line is a Hashed versionof an IP address : cat .ssh/known_host &lt;br /&gt;
Ssh demon : running in the background and must have a public key to identify its self. process that runs in the background that doesn’t run in the background(connects 1 file system to another)&lt;br /&gt;
-	&amp;gt; connects sockets and listens to connect. Doesn’t interact with user&lt;br /&gt;
Thursday: written version of the solutions for the midterm and we will talk about assignment 4 &lt;br /&gt;
3000 class content &lt;br /&gt;
We didn’t discuss scheduling much : &lt;br /&gt;
Virtual memory: similar to scheduling since, If you don’t have enough memory , you delete the page that you may want to need at last . Choosing which pages you replace : one-handed and two-handed clocks&lt;br /&gt;
Power management &lt;br /&gt;
Security &lt;br /&gt;
Virtualization : not one thing , vm ware, system which run multiple of kernels.&lt;br /&gt;
SSH question student asked, how can they know that they have the private key belongs to the pubkey it belongs to: sends a public key or a hash of th Pubkey , then an exchange : yes I have a secret key which can be inverted by the pubkey. Private key must be corresponding. encrypts with thr private key and sends it back&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_21&amp;diff=21353</id>
		<title>Operating Systems 2017F Lecture 21</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_21&amp;diff=21353"/>
		<updated>2017-12-07T16:15:14Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec21-30Nov2017.mp4 Lecture 21 video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec21/assign3-sol.txt Assignment 3 solutions]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 21&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
ssh part of a long tradition in remote access to UNIX-like systems&lt;br /&gt;
(and other systems with command lines)&lt;br /&gt;
&lt;br /&gt;
* hard link via a serial line to a terminal&lt;br /&gt;
* modem-mediated serial connection to a terminal&lt;br /&gt;
* telnet - connect in a serial-like fashion over the internet&lt;br /&gt;
  - have a program listening for remote access on a fixed port&lt;br /&gt;
  - when there&#039;s a connection, connect remote program to login&lt;br /&gt;
  - login takes username, password&lt;br /&gt;
  - if correct, starts command shell for the user&lt;br /&gt;
  * Problems with telnet&lt;br /&gt;
    - annoying to type in username and password every time&lt;br /&gt;
    - username and password (and everything else) goes in the clear, so&lt;br /&gt;
      subject to eavesdropping, modification&lt;br /&gt;
* rsh - remote shell&lt;br /&gt;
  - idea: allow login without passwords and running of one-off commands&lt;br /&gt;
  - how? check IP address/hostname of source&lt;br /&gt;
  - but...IP addresses are not a secure authenticator&lt;br /&gt;
  - also...trusting configuration of remote system&lt;br /&gt;
  - and...all communication again in the clear&lt;br /&gt;
&lt;br /&gt;
* ssh was designed as a drop-in replacement for rsh&lt;br /&gt;
  - but with better security&lt;br /&gt;
  - and also with better features, specifically X11 forwarding&lt;br /&gt;
&lt;br /&gt;
X11 is a system for displaying graphics and handing input&lt;br /&gt;
  - windows, keyboard, mice&lt;br /&gt;
  - developed in late 1980&#039;s, early 1990&#039;s&lt;br /&gt;
  - designed to allow remote connections&lt;br /&gt;
    - primarily a network protocol&lt;br /&gt;
  - X11 connections went in the clear&lt;br /&gt;
    - and were a pain to set up&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public and private keys&lt;br /&gt;
 - asymmetric cryptography&lt;br /&gt;
 - used for key establishment and signatures (authentication)&lt;br /&gt;
&lt;br /&gt;
symmetric crypto&lt;br /&gt;
 - encrypt with a key, decrypt with the same key&lt;br /&gt;
 - modern form: block ciphers (e.g., AES)&lt;br /&gt;
 - fast and very secure&lt;br /&gt;
&lt;br /&gt;
asymmetric crypto is based on &amp;quot;one way&amp;quot; functions&lt;br /&gt;
 - easy one way&lt;br /&gt;
 - hard to invert (unless you know extra info)&lt;br /&gt;
&lt;br /&gt;
To send someone a secret message&lt;br /&gt;
 - get their public key&lt;br /&gt;
 - encrypt message with their public key&lt;br /&gt;
   - really, encrypt random symmetric key (session key) with public key and&lt;br /&gt;
     encrypt message with symmetric key&lt;br /&gt;
&lt;br /&gt;
To receive a secret message&lt;br /&gt;
 - decrypt session key with your private key&lt;br /&gt;
 - use session key to decrypt message&lt;br /&gt;
&lt;br /&gt;
NEVER IMPLEMENT CRYPTO ON YOUR OWN&lt;br /&gt;
PLAN TO FIX CRYPTO CODE/PROTOCOLS OFTEN&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ADDITIONAL NOTES &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remote access : are processes accessed through command lines aka terminal.&lt;br /&gt;
-	&amp;gt; hard link via serial line : first thing you should think about &lt;br /&gt;
-	How to access the computer else where from somewhere else(remote access ) this is called a modem mediated serial connection to terminal .&lt;br /&gt;
Network: computer talk to each other&lt;br /&gt;
What is wrong with telnet : &lt;br /&gt;
1)	Insecure, everything you type in including your password and user name is watched (and modifiable)&lt;br /&gt;
2)	Annoying since it requires you to constantly log in&lt;br /&gt;
&lt;br /&gt;
RSH : is a remote shell . the ability to run a command  by giving it arguments simply &lt;br /&gt;
How does it allow you to do so without password? Since it has your IP address and hostname of source. &lt;br /&gt;
*however this is not secure enough since the IP address can be faked. &lt;br /&gt;
Ssh : developed to replace rsh with better improved security and features such as x11 forwarding.&lt;br /&gt;
When killing ssh , the x clock &amp;amp; program ended since it used that to mediate through.&lt;br /&gt;
X11: windows focused, remote desktops are different. system which displays graphics, it is weird in a way that it is used be useful but not anymore. It is a network protocol and which the program will display something on screen will talk to the computer (ask?) . &lt;br /&gt;
-Example : The server  is the display and the terminal is client. &lt;br /&gt;
-disadvantages : difficult to set up .&lt;br /&gt;
-How do I talk to the current display and connect to it? &lt;br /&gt;
               -Using an environment variable. (display environment variable) &lt;br /&gt;
-	Env | grep DISPLAY . if it is :=0 like our case then we have none.&lt;br /&gt;
Goal : use a local computer like running remote computers , use graphic access remotely &lt;br /&gt;
Clone of ssh syntax &lt;br /&gt;
*example : su –soma, rsh it then do ls &lt;br /&gt;
Xterm command after ssh? : &lt;br /&gt;
Xclock &amp;amp; : where is this program running? It is not running locally. It is running a program remotely but it is displaying here. &lt;br /&gt;
-x option to ssh : setting the display environment variable to the remote system&lt;br /&gt;
--ford their own their own things magically &lt;br /&gt;
-x , can you run the x clock &amp;amp; without –x : NO unless you do things on command lines&lt;br /&gt;
Ssh : can manage redirection from a local port to another machine (ssh tunnel).&lt;br /&gt;
Known_hosts: &lt;br /&gt;
Public VS private keys:  asymmetric cryptography: when you encrypt a file with a password, you must use the same password to decrypt it.&lt;br /&gt;
-used for key establishments and signatures (key authentication)&lt;br /&gt;
- easy to go one way (hard to go the other way and invert )&lt;br /&gt;
&lt;br /&gt;
Modern for : fixed size units , block ciphers &lt;br /&gt;
Symmetric cryptography : is much more efficient and harder to break than asymmetric.&lt;br /&gt;
    -  Fast and very secure&lt;br /&gt;
    - Disadvantages: required a way over network to obtain a key to connect&lt;br /&gt;
To send someone privately : &lt;br /&gt;
-obtain their public key (in directories ex)&lt;br /&gt;
-then use it to encrypt symmetric &lt;br /&gt;
-send both , attach the key with the message&lt;br /&gt;
*to receive a message :&lt;br /&gt;
-use the session key to decrypt it : assymetric algorithms are slow and less secure , why RSA isn’t used alone&lt;br /&gt;
- NEVER IMPLEMENT CRYPTO ON YOUR OWN because you cant implement it in the same algorithm, too many numbers of attacks and unreliable but if you do use it in your system , use it with libraries but expect them to be changed.&lt;br /&gt;
Cryptography is the base of ssh&lt;br /&gt;
The lock icon : secure connection , uses same thing as ssh. Info about the public key.]&lt;br /&gt;
-Symantec : dangerous because anyone can sign.&lt;br /&gt;
Fire fox : has public keys of certificates so you are able to send secure message and anyone can do the inverse operation using the public keys. &lt;br /&gt;
Ssh : stores on first use  .&lt;br /&gt;
Rm .ssh/known_hosts : &lt;br /&gt;
Less known_hosts &lt;br /&gt;
Cd /etc/ssh : host keys and configurations. &lt;br /&gt;
What happens if you change those keys? : it will give you a warning &lt;br /&gt;
Transfer the public key to the remote system and make sure I don’t share my private one&lt;br /&gt;
We are stuck using passwords because of usability and dangerous&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21326</id>
		<title>Operating Systems 2017F Lecture 20</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_20&amp;diff=21326"/>
		<updated>2017-11-29T03:27:31Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
[http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec20-28Nov2017.mp4 Class Video]&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 20&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an sshfs-mounted filesystem&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel&lt;br /&gt;
* the local kernel sees filesystem is FUSE, calls FUSE routines for open, getdents (via vfs abstraction)&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&lt;br /&gt;
* sshfs process sends request to remote system&lt;br /&gt;
  - via socket system calls&lt;br /&gt;
* remote sshd process receives request (via system calls)&lt;br /&gt;
* remote sshd process accesses local filesystem&lt;br /&gt;
  - makes open, getdents system calls&lt;br /&gt;
  - remote kernel checks vfs, calls ext4 routines to access data&lt;br /&gt;
* remote sshd process responds to request (via system calls)&lt;br /&gt;
* local sshfs process receives response (via system calls)&lt;br /&gt;
* local sshfs process responds to FUSE request&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process&lt;br /&gt;
&lt;br /&gt;
Normal file access permission check&lt;br /&gt;
 - compare uid, gid of file with uid, gid of process&lt;br /&gt;
&lt;br /&gt;
But really...&lt;br /&gt;
 - compares it with fsuid, fsgid of process&lt;br /&gt;
    - which is normally same as euid, egid of process&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
&lt;br /&gt;
Assignment 4 will be autograded and in fill in the blank form. This will not be like the final exam. &amp;lt;br&amp;gt;&lt;br /&gt;
You should think about who is doing what?  Otherwise FUSE won&#039;t make much sense &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Inode numbers completely changed when you use ssh. It starts with 1 from &amp;quot;.&amp;quot; (root) and increments from there. &amp;lt;br&amp;gt;&lt;br /&gt;
Inodes come from filesystem you are acessing &amp;lt;br&amp;gt;&lt;br /&gt;
He used df to find filesystem info &amp;lt;br&amp;gt;&lt;br /&gt;
The used Commands: mount | grep ubuntu and mount | grep vda1 to find type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
In the SSH there is the filesystem type &amp;quot;fuse.sshfs&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
When you run strace on ls on the two terminals (ssh connection and the local one) you see similar output &amp;lt;br&amp;gt;&lt;br /&gt;
When we run &amp;quot;ls&amp;quot; on an ssh-mounted filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* ls makes system calls (open, getdents) to the local Linux kernel &amp;lt;br&amp;gt;&lt;br /&gt;
* the local kernel sees the filesystem is FUSE, calls DUSE routines for open, getdents (via vfs abstraction) &amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE calls the sshfs process that mounted the filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* sshfs process sends request to remote system &amp;lt;br&amp;gt;&lt;br /&gt;
- via socket system calls&amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives request (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process receives requests (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
- makes open, getdents sytem calls &amp;lt;br&amp;gt;&lt;br /&gt;
- rmeote kernel checks vfs, calls ext4 routines to access data &amp;lt;br&amp;gt;&lt;br /&gt;
* remote sshd process responds to requests  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process receives response  (via system calls) &amp;lt;br&amp;gt;&lt;br /&gt;
* local sshfs process responds to FUSE request  (via system calls)&amp;lt;br&amp;gt;&lt;br /&gt;
* FUSE passes data back to vfs layer, then back to requesting process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; If you look as lsmod | less you see a ton of modules. Some of the modules are not necessary to mount the root filesystem.&amp;lt;br&amp;gt;&lt;br /&gt;
ls /lib/modules there are directories that store the kernel modules &amp;lt;br&amp;gt;&lt;br /&gt;
You have to have a filesystem that you mount initially that has a bunch of modules in it. Thus, there is an initial root file system that is necessary to load everything else &amp;lt;br&amp;gt;&lt;br /&gt;
This is the initial RAM disk. This filesystem loads the modules needed for the real filesystem. &amp;lt;br&amp;gt;&lt;br /&gt;
To remove a file I need to remove the hardlink from the directory where the hardlink exists &amp;lt;br&amp;gt;&lt;br /&gt;
The password files maps usernames to user id&#039;s (Linux does not care about your username) &amp;lt;br&amp;gt;&lt;br /&gt;
Normal file access permission check br&amp;gt;&lt;br /&gt;
- compare uid, gid of file with uid, gid of process &amp;lt;br&amp;gt;&lt;br /&gt;
But really: &amp;lt;br&amp;gt;&lt;br /&gt;
- compares it with fsuid, fsgid of process &amp;lt;br&amp;gt;&lt;br /&gt;
- which is normally same as euid, egid of process &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Sshfs&amp;lt;br&amp;gt;&lt;br /&gt;
* Inode values are different in remote vm vs local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Values increment from 1 in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Who&#039;s supplying the inode values?&amp;lt;br&amp;gt;&lt;br /&gt;
** Ext4 filesystem in local vm&amp;lt;br&amp;gt;&lt;br /&gt;
** Fuse.sshfs filesystem in remote vm&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystem determines the interpretation of inode values&amp;lt;br&amp;gt;&lt;br /&gt;
* Inodes have no meaning outside its filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* Local to its filesystem =&amp;gt; hardlinks are different too&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;quot;strace ls&amp;quot; in both output the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
* Vfs not built into original unix filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Try &amp;quot;strace&amp;quot;ing the sshfs call, see how its interacts with fuse&amp;lt;br&amp;gt;&lt;br /&gt;
* Don&#039;t need to know exact system calls, but you should know when it has to make system calls and why&amp;lt;br&amp;gt;&lt;br /&gt;
** Needs to access files over the network&amp;lt;br&amp;gt;&lt;br /&gt;
* Understand why you can&#039;t do this with regular library calls&amp;lt;br&amp;gt;&lt;br /&gt;
* Removing the root filesystem will trigger a kernel panic&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel will prevent you from unmounting filesystems that contain other filesystems&amp;lt;br&amp;gt;&lt;br /&gt;
* Kernel modules located in &amp;quot;/lib/modules/&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* Initial filesystem is loaded into kernel&amp;lt;br&amp;gt;&lt;br /&gt;
** Fake filesystem, throw away after loaded, not persistent&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disk = filesystem stored in ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Gets the system up to the point where the kernel can load the real filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
** Bootloader has to load both kernel and the initial ram disk into ram&amp;lt;br&amp;gt;&lt;br /&gt;
** Ram disks located in &amp;quot;/boot = initrd.img&amp;lt;...&amp;gt;&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
** Kernel version specific&amp;lt;br&amp;gt;&lt;br /&gt;
** Generated as part of installation of kernel&amp;lt;br&amp;gt;&lt;br /&gt;
* Cpio: copies files to and from archives&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether you can access a file?&amp;lt;br&amp;gt;&lt;br /&gt;
** The filesystem&amp;lt;br&amp;gt;&lt;br /&gt;
* How to map from user id to username?&amp;lt;br&amp;gt;&lt;br /&gt;
** Recall that&amp;lt;br&amp;gt;&lt;br /&gt;
- Kernel knows nothing about usernames&amp;lt;br&amp;gt;&lt;br /&gt;
- This is a userspace process&amp;lt;br&amp;gt;&lt;br /&gt;
- Looks in local password file&amp;lt;br&amp;gt;&lt;br /&gt;
* What determines whether an operation is allowed?&amp;lt;br&amp;gt;&lt;br /&gt;
** Checks to see who owns the file&amp;lt;br&amp;gt;&lt;br /&gt;
** Compare uid, gid of file with uid, gid of process&amp;lt;br&amp;gt;&lt;br /&gt;
* In remote system, sftp does file access checks&amp;lt;br&amp;gt;&lt;br /&gt;
********************************************************************&lt;br /&gt;
ADDITIONAL NOTES:&lt;br /&gt;
&lt;br /&gt;
Fuse: makes you think who is doing what?&lt;br /&gt;
	How it is connected in the kernel . &lt;br /&gt;
	Fuse.sshfs : is what chose the inode numbers?&lt;br /&gt;
o	Can they be identical to the other inode numbers? &lt;br /&gt;
	Yes but why? &lt;br /&gt;
	What the process of getting the directories? &lt;br /&gt;
The inodes come from the filesystem which you are accessing &lt;br /&gt;
&lt;br /&gt;
Who chose the inode number: the filesystem determine the intereprtation of an inode number, Inode is local to a filesystem.&lt;br /&gt;
How is the kernel obtaining information? : &lt;br /&gt;
Fuse :  has three kinds &lt;br /&gt;
1)	Fuseblk&lt;br /&gt;
2)	Fuse&lt;br /&gt;
3)	Fusectl&lt;br /&gt;
Summary of sshfs: &lt;br /&gt;
Sshfs process that has to make system call to talk to the network to the remote system. &lt;br /&gt;
Similar to a web request , but the difference separate from that we have a different system calls which is the ls process. To do this, the kernel must call a process. &lt;br /&gt;
Does sshfs create 2 processes? Yes , it actually creates multiple of process&lt;br /&gt;
The remote kernel prespective : file accessing files and sending data back to another system. Remote data is not doing anything special. &lt;br /&gt;
*To verify : ps aux | grep ssh &lt;br /&gt;
To learn system call sshfs doing ,running local  strace as much as you can.&lt;br /&gt;
You can mount a file system which would not allow you to mount any further &lt;br /&gt;
When you update the kernel : the initial ram disk will not be update since it is redundant, it will generate it.&lt;br /&gt;
Can we mount a filesystem in a file?&lt;br /&gt;
*&lt;br /&gt;
What is suspicious? A lot of repetitive inodes &lt;br /&gt;
3rd column : amount of hard links. &lt;br /&gt;
Avoid multiple of binaries if you want a small system, you just need the basics. &lt;br /&gt;
After mounting it it loads the linux system.&lt;br /&gt;
Permissions:  the owner can change these permissions, but you can’t take away your own privileges.&lt;br /&gt;
1)	Removing a file : unlinking the file, removing a hardlink which modifies the directory in which a hardlink exists.  Why do I have the permission to remove it? &lt;br /&gt;
2)	Create a file : ouch afile, ls –la afile, &lt;br /&gt;
Premissions: &lt;br /&gt;
1)	Other&lt;br /&gt;
2)	User&lt;br /&gt;
3)	Group &lt;br /&gt;
4)	Files system has EUID( very important because processes can run as a user but have permissions of another user )  AND GID: permissions what you  have and fs is what ur system sees &lt;br /&gt;
Minix system which manages your CPU. &lt;br /&gt;
Busy Box : One binary to pretend it is different programs and we also have a program which pretends to be many. Give it hard link to different names.&lt;br /&gt;
Soma vs anilclass: anil class is special account. The current directory is owned by soma so how did anilclass was able to create a file? Filesystem understands those primission checks? (prof is not sure about this fact and will check it) &lt;br /&gt;
Map a user ID to your user name? it’s a user space problem, kernel doesn’t care about the username. By looking at the password file : grep 1000 /etc/passwd. &lt;br /&gt;
Where are the permissions done in sshfs? (in the steps &lt;br /&gt;
*sftp search process which will determine the permissions. remote file system and the remote kernel (ext4) will check via sftp. All the file access (grabbing the files) &lt;br /&gt;
Verify : ps aux | grep sftp&lt;br /&gt;
Who started this sftp: the sshd did.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Commands:&lt;br /&gt;
Mount | grep “name” &lt;br /&gt;
Strace ls : directories look the same although they are mounted since ls can not tell , ls is not doing anything differe just opening ur directory and getting data there &lt;br /&gt;
Man sshd : run it and give it aport like 222. Easiest way is using 2 machines on open stack and terminal. It is a good exercise&lt;br /&gt;
Initial Ram disk : to get the real root system to be mounted , similar to memory ll. &lt;br /&gt;
Sudo mount initrd.img-4.10.0-40-generic /mnt : to mount a file in a file system but it didn’t not work and there is an alternative way of doing this &lt;br /&gt;
Anther way : man CPIO : copy files to an form archives . ex : TAR &lt;br /&gt;
CPI  - - help : to figure it out &lt;br /&gt;
Ls –a bin | less&lt;br /&gt;
Cd \ boot : RAM disk &lt;br /&gt;
Du –s –h : in this case (121mb) to see the size of the busy box but the modules takes up half of that space.&lt;br /&gt;
Ls –lai | head &lt;br /&gt;
Chmod a-w : you are unable to write to this directory anymore &lt;br /&gt;
Chmod o+w : granted permission to other….&lt;br /&gt;
Ls –la /bin/fusermount &lt;br /&gt;
Who gives us premissions: just does a normal open and read , the remote kernel enforces these premissions.&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21287</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21287"/>
		<updated>2017-11-21T19:14:51Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== [Notes] ==&lt;br /&gt;
&lt;br /&gt;
Sample &lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
* lots of program shave &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&amp;lt;br&amp;gt;&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions?&amp;lt;br&amp;gt;&lt;br /&gt;
** Linux kernel modules&amp;lt;br&amp;gt;&lt;br /&gt;
** FUSE applications?&amp;lt;br&amp;gt;&lt;br /&gt;
** the linux kernel?&amp;lt;br&amp;gt;&lt;br /&gt;
** node web applications?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up even handlers&amp;lt;br&amp;gt;&lt;br /&gt;
* the event loop can be implicit or explicit&amp;lt;br&amp;gt;&lt;br /&gt;
** or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; some kind&amp;lt;br&amp;gt;&lt;br /&gt;
* event loops poll (check) to see when there are new events&amp;lt;br&amp;gt;&lt;br /&gt;
* what are event loops for node app?&amp;lt;br&amp;gt;&lt;br /&gt;
** where are interrupts for node apps? &amp;lt;br&amp;gt;&lt;br /&gt;
***Incoming network requests, it&#039;s an event&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code run differently in the kernel : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1)functions runs on the bhealf of insmod, unles sit is Independence context &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2)codes that run on the bhelaf o the process&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3)after an interrupt: no process , it is an interrupt cotext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) file names : regular programs but the square brackets, execution context + address space. they share the kernel&#039;s address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .&amp;lt;br&amp;gt;&lt;br /&gt;
multi- threaded: maintains multiple address processes , ex: fire fox. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ps -elF | less &amp;quot;number&amp;quot; : displays threads.&lt;br /&gt;
&lt;br /&gt;
top : displays all the processes &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ls time : shows you the time . &lt;br /&gt;
&lt;br /&gt;
sys: how much time in the kernel space&lt;br /&gt;
real: how much time &lt;br /&gt;
user : how much time in user space &lt;br /&gt;
&lt;br /&gt;
process : can&#039;t manipulate its own memory map directly, it has an address space, but cant change it. Process: is limited but the kernel is not and the kernel can change it&#039;s own address and in charge of its self. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kernel tasks : are threads, when a process makes a system call , thi sis schedules in the process priority. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When running &amp;lt;br&amp;gt; &lt;br /&gt;
&amp;quot;time ls&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
real = realtime it took to run&lt;br /&gt;
user = the user space time&lt;br /&gt;
sys = kernel time&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What&#039;s flow of control in tutorial 7? &amp;lt;br&amp;gt;&lt;br /&gt;
What is the connection? &amp;lt;br&amp;gt;&lt;br /&gt;
To exit the program, we must unmount the filesystem, run &amp;quot;sudo umount mnt&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
what is the flow of control ? what connection between things we are doing in the new terminal and the old one&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; these programs are communicating to each other, it will be invoked when we use mnt (mount) the kernel knows it is a filesystem , process runs system calls, then kernel talks to out original terminal. How? you can use strace to know, it is waiting to be invoked, to receive and responds to messages. events will be passed off to another process. switching between one process to another. it has potential security benefits. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Key to understand this tutorial : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; understand net flow control. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how do processes communicate?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; how does it take a directory int and creates a filesystem from it?: &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
***sub tree starting at mount is delegated to this process.&amp;lt;br&amp;gt; &lt;br /&gt;
***permissions are limited &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
How to kill it?&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
-&amp;gt; ctrl c , no , you can but the kernel will be unhappy.&amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; unmount the file system when you are done using it &amp;lt;br&amp;gt;&lt;br /&gt;
-&amp;gt; umount / you have to do it as root &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*No class Thursday! no office hours on Wednesday&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21285</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21285"/>
		<updated>2017-11-21T18:56:50Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== [Notes] ==&lt;br /&gt;
&lt;br /&gt;
Sample &lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
* lots of program shave &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions?&lt;br /&gt;
** Linux kernel modules&lt;br /&gt;
** FUSE applications?&lt;br /&gt;
** the linux kernel?&lt;br /&gt;
** node web applications?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up even handlers&amp;lt;br&amp;gt;&lt;br /&gt;
* the event loop can be implicit or explicit&amp;lt;br&amp;gt;&lt;br /&gt;
** or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; some kind&amp;lt;br&amp;gt;&lt;br /&gt;
* event loops poll (check) to see when there are new events&amp;lt;br&amp;gt;&lt;br /&gt;
* what are event loops for node app?&amp;lt;br&amp;gt;&lt;br /&gt;
** where are interrupts for node apps? &amp;lt;br&amp;gt;&lt;br /&gt;
***Incoming network requests, it&#039;s an event&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code run differently in the kernel : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1)functions runs on the bhealf of insmod, unles sit is Independence context &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2)codes that run on the bhelaf o the process&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3)after an interrupt: no process , it is an interrupt cotext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) file names : regular programs but the square brackets, execution context + address space. they share the kernel&#039;s address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .&amp;lt;br&amp;gt;&lt;br /&gt;
multi- threaded: maintains multiple address processes , ex: fire fox. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ps -elF | less &amp;quot;number&amp;quot; : displays threads.&lt;br /&gt;
&lt;br /&gt;
top : displays all the processes &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
ls time : shows you the time . &lt;br /&gt;
&lt;br /&gt;
sys: how much time in the kernel space&lt;br /&gt;
real: how much time &lt;br /&gt;
user : how much time in user space &lt;br /&gt;
&lt;br /&gt;
process : can&#039;t manipulate its own memory map directly, it has an address space, but cant change it. Process: is limited but the kernel is not and the kernel can change it&#039;s own address and in charge of its self. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kernel tasks : are threads, when a process makes a system call , thi sis schedules in the process priority. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21284</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21284"/>
		<updated>2017-11-21T18:50:28Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* [Notes] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== [Notes] ==&lt;br /&gt;
&lt;br /&gt;
Sample &amp;lt;br&amp;gt;&lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional Notes ===&lt;br /&gt;
&lt;br /&gt;
Where&#039;s main?&lt;br /&gt;
* lots of program shave &amp;quot;main&amp;quot; functions - a function that runs first and controls the execution of the program&lt;br /&gt;
* Do these have &amp;quot;main&amp;quot; functions?&lt;br /&gt;
** Linux kernel modules&lt;br /&gt;
** FUSE applications?&lt;br /&gt;
** the linux kernel?&lt;br /&gt;
** node web applications?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In many systems, &amp;quot;main&amp;quot; just sets up even handlers&amp;lt;br&amp;gt;&lt;br /&gt;
* the event loop can be implicit or explicit&amp;lt;br&amp;gt;&lt;br /&gt;
** or there may be no loop at all, just handlers and &amp;quot;interrupts&amp;quot; some kind&amp;lt;br&amp;gt;&lt;br /&gt;
* event loops poll (check) to see when there are new events&amp;lt;br&amp;gt;&lt;br /&gt;
* what are event loops for node app?&amp;lt;br&amp;gt;&lt;br /&gt;
** where are interrupts for node apps? &amp;lt;br&amp;gt;&lt;br /&gt;
***Incoming network requests, it&#039;s an event&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Code run differently in the kernel : &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
1)functions runs on the bhealf of insmod, unles sit is Independence context &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2)codes that run on the bhelaf o the process&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
3)after an interrupt: no process , it is an interrupt cotext &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4) file names : regular programs but the square brackets, execution context + address space. they share the kernel&#039;s address space, they are called kernel threads which are independently scheduling . You can not kill them but you can change their scheduling , maybe their priority but not 100%. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
does it create a proces? no , but it can create a kernel thread (is it a process? virtual adress space, .&amp;lt;br&amp;gt;&lt;br /&gt;
multi- threaded: maintains multiple address processes , ex: fire fox. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ps -elF | less &amp;quot;number&amp;quot; : displayes threads.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21281</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21281"/>
		<updated>2017-11-21T18:08:53Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== [Notes] ==&lt;br /&gt;
&lt;br /&gt;
Sample &amp;lt;br&amp;gt;&lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21280</id>
		<title>Operating Systems 2017F Lecture 19</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21280"/>
		<updated>2017-11-21T18:08:44Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: Created page with &amp;quot;[Notes] Sample &amp;lt;br&amp;gt; sample&amp;lt;br&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[Notes]&lt;br /&gt;
Sample &amp;lt;br&amp;gt;&lt;br /&gt;
sample&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21269</id>
		<title>Operating Systems 2017F Lecture 18</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21269"/>
		<updated>2017-11-16T20:41:15Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 16, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec18-16Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 18: Filesystems and such&lt;br /&gt;
--------------------------------&lt;br /&gt;
* How can you recover a filesystem?&lt;br /&gt;
* How do you delete a file?&lt;br /&gt;
&lt;br /&gt;
A filesystem is&lt;br /&gt;
 * persistent data structure&lt;br /&gt;
 * stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
 * maps hierarchical filenames to file contents&lt;br /&gt;
 * has metadata about files (somehow)&lt;br /&gt;
&lt;br /&gt;
What&#039;s in a filesystem?&lt;br /&gt;
 * data blocks&lt;br /&gt;
 * metadata blocks&lt;br /&gt;
&lt;br /&gt;
How do you organize metadata?&lt;br /&gt;
&lt;br /&gt;
First job: identify basic characteristics of the filesystem&lt;br /&gt;
&lt;br /&gt;
You need a &amp;quot;summary&amp;quot; block that tells you about everything else&lt;br /&gt;
 =&amp;gt; this is the &amp;quot;superblock&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Normally the superblock is the first block of the filesystem&lt;br /&gt;
&lt;br /&gt;
In the superblock&lt;br /&gt;
 - what kind of filesystem is this?&lt;br /&gt;
    - what filesystem magic number is there&lt;br /&gt;
 - how big is the filesystem?&lt;br /&gt;
 - how is it organized?&lt;br /&gt;
 - where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
for POSIX filesystems&lt;br /&gt;
 - file metadata is stored in...inodes&lt;br /&gt;
 - most have pre-reserved inodes&lt;br /&gt;
&lt;br /&gt;
So we have&lt;br /&gt;
 - superblock&lt;br /&gt;
 - inode blocks&lt;br /&gt;
 - data blocks&lt;br /&gt;
   - data blocks for directories&lt;br /&gt;
   - data blocks for files&lt;br /&gt;
&lt;br /&gt;
How do you recover from damage?&lt;br /&gt;
 - filesystems never &amp;quot;reboot&amp;quot;, must remain correct over&lt;br /&gt;
   the course of years&lt;br /&gt;
 - but errors will happen&lt;br /&gt;
   - bitrot&lt;br /&gt;
   - &amp;quot;accidental&amp;quot; corruption&lt;br /&gt;
   - computer failure/memory corruption/hard reboot&lt;br /&gt;
&lt;br /&gt;
To make filesystems fast, data &amp;amp; metadata is cached in RAM&lt;br /&gt;
 - bad things happen if this data hasn&#039;t been written to disk and you reboot&lt;br /&gt;
 - even worse things happen if your RAM is bad and corrupts the data&lt;br /&gt;
&lt;br /&gt;
Also bad...what if we lose the superblock?&lt;br /&gt;
 - you could lose EVERYTHING&lt;br /&gt;
 - so we have backup superblocks&lt;br /&gt;
&lt;br /&gt;
Old scandisk/fsck was slow because they had to scan all filesystem metadata&lt;br /&gt;
 - not to recover data, but to fix metadata&lt;br /&gt;
&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power&lt;br /&gt;
 - we must be writing data to disk all the time&lt;br /&gt;
 - but isn&#039;t writing all the time slow?&lt;br /&gt;
&lt;br /&gt;
On magnetic hard disks (not SSDs)&lt;br /&gt;
 - sequential operations are fast&lt;br /&gt;
 - random access is slow&lt;br /&gt;
   - we have to move the read/write head&lt;br /&gt;
&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing&lt;br /&gt;
sequentially to disk...and then later writing randomly&lt;br /&gt;
 - sequential writes go to the &amp;quot;journal&amp;quot;&lt;br /&gt;
&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
 - just check the journal for pending operations (replay the journal)&lt;br /&gt;
&lt;br /&gt;
There exist filesystems that are pure journal&lt;br /&gt;
 - log-based filesystem&lt;br /&gt;
&lt;br /&gt;
logs and journal inherently create multiple copies of data and metadata that are hard to track.  This makes deletion nearly impossible (at least to guarantee)&lt;br /&gt;
&lt;br /&gt;
Only way to guarantee...encrypt everything&lt;br /&gt;
 - if every file has its own key, you can delete the key and thus &amp;quot;delete&amp;quot; the data&lt;br /&gt;
&lt;br /&gt;
Solid State Disks (SSD) use log-structured storage at a level below blocks.&lt;br /&gt;
 - writes are coarse-grained (you have to write a lot at once)&lt;br /&gt;
 - you don&#039;t want to write to the same cells too often, they&#039;ll die&lt;br /&gt;
   - have to do &amp;quot;wear-leveling&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additional notes :&lt;br /&gt;
&lt;br /&gt;
Lecture 18, november 17 &lt;br /&gt;
&lt;br /&gt;
Comp 3000: &lt;br /&gt;
Midterm review:&lt;br /&gt;
2)mmap is called in dynamically linked libraries &lt;br /&gt;
Work on 2404 assignment&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8) yes , using mmap &lt;br /&gt;
9) shell did , because it has to open a new file &lt;br /&gt;
10) mmap allocates the entire file , &lt;br /&gt;
11) after the fork , the memory won’t be shared, no communication will happen. &lt;br /&gt;
12) no, race condition, busy wait , spin lock in the kernel. Some other user can modify the code which we are waiting. Before we decrement someone else will modify it. Someone can change with the semantics. &lt;br /&gt;
How do you do kernel hacking?&lt;br /&gt;
1)	Be humble, &lt;br /&gt;
o	you don’t necessary know everything, everyone is retarded in their own way &lt;br /&gt;
2)	Verify you assumptions &lt;br /&gt;
o	By experiments &lt;br /&gt;
o	Compile and run&lt;br /&gt;
3)	Check for errors!&lt;br /&gt;
o	Saves time&lt;br /&gt;
o	Kernel has to live “ cleanly” &lt;br /&gt;
4)	Find another part of the kernel that is close to what you want to do &lt;br /&gt;
o	Use their ideas to apply yours by analyzing their code.&lt;br /&gt;
o	Follow their pattern “pattern match” to avoid problems since you may not understand all the abstractions and assumptions&lt;br /&gt;
o	Realize if their assumptions match yours&lt;br /&gt;
5)	Understand the “flow of control” in the program&lt;br /&gt;
o	Architecture &lt;br /&gt;
o	Division of responsibilities &lt;br /&gt;
o	Division Why does this matter?&lt;br /&gt;
o	Possible to make a module and run in the background! Anything is possible! All you have to do is be creative. In fact you have to do a kernel thread &lt;br /&gt;
	When does the Ethernet card receives data?&lt;br /&gt;
o	The Ethernet card sends an interrupt to the kernel &lt;br /&gt;
o	The CPU calls the kernel code for handling Ethernet data&lt;br /&gt;
	When does the kernel run? &lt;br /&gt;
o	The kernel gets woken up for those events &lt;br /&gt;
o	The clock generates a timer interrupt &lt;br /&gt;
	Interrupt requires a CPU score to be taken over&lt;br /&gt;
o	Core was probably running a user space process and this is scheduling is about&lt;br /&gt;
	Schedule: what to do after having kicked a user space process off a core.&lt;br /&gt;
o	Can it be a complex CPU algorithm : no since it always sending interrupts?&lt;br /&gt;
o	Determines what is the next task to do?&lt;br /&gt;
	Normally on a core:&lt;br /&gt;
o	A running userspace process&lt;br /&gt;
o	Interrupt happens&lt;br /&gt;
o	Core switches to supervisor mode, runs kernel code&lt;br /&gt;
o	Last part of the  kernel code is the scheduler, chooses which userspace code to run &lt;br /&gt;
o	Goto top&lt;br /&gt;
	Kernel is entered via interrupts, exited via scheduler &lt;br /&gt;
	Entry and exit the kernel has to do low-level tasks&lt;br /&gt;
o	Uses assembly code&lt;br /&gt;
	Limits because it is hard to manage &lt;br /&gt;
On the website:&lt;br /&gt;
	Arch : arch culture specific and the driver specific code, &lt;br /&gt;
	Entry_64.5 : before the system call it calls this. Don’t mess up with it. It take cares of dispatching the system calls.&lt;br /&gt;
	Shced.h: what the kernel uses to keep track of processes , go through it &lt;br /&gt;
	:1 means bitfields in c &lt;br /&gt;
	What criteria should the scheduler use? &lt;br /&gt;
o	“fairness” : everyone should get a turn, everyone gets to share the CPU.&lt;br /&gt;
o	Starvation : a term when a program does not get the CPU&lt;br /&gt;
o	Prevent starvation!&lt;br /&gt;
o	Equal share of resources.&lt;br /&gt;
o	Why would not you want your scheduler being fair? To avoid “foreground” tasks in the interactive systems.&lt;br /&gt;
o	Never enough biased towards “ foreground” tasks&lt;br /&gt;
o	Series of hacks and heuristics  &lt;br /&gt;
&lt;br /&gt;
	Memory is allocated lazily is the kernel : &lt;br /&gt;
o	which means it is possible to allocate way more memory that can be ever used.&lt;br /&gt;
o	This will cause “memory debt”&lt;br /&gt;
o	Out of memory killer : killing process when you exceed the amount of memory(ex: shoots whoever deposits the money)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Continuation of lecture 18: &lt;br /&gt;
&lt;br /&gt;
Important notes:&lt;br /&gt;
How can you recover a filesystem?&lt;br /&gt;
How do you delete a file?&lt;br /&gt;
What is a filesystem?: &lt;br /&gt;
*persistent data structure &lt;br /&gt;
* stored in fixed-sized blocks (at least 512 bytes in size)&lt;br /&gt;
*maps hierarchical filenames to file contents &lt;br /&gt;
*has metadata about files (somwhow)&lt;br /&gt;
What is in a filesystem?&lt;br /&gt;
*data blocks &lt;br /&gt;
*metadata blocks &lt;br /&gt;
How do you organize metdata:&lt;br /&gt;
1)	First you must identify characteristics of the file system &lt;br /&gt;
Superblock :  summary y block which tells you about the other blocks you have and it depends on which file system you have. It’s usually the first block of a file system. &lt;br /&gt;
In the superblock? :&lt;br /&gt;
1)	What kind of file system is this? By checking what is the magic number it has &lt;br /&gt;
2)	How big is the file system?&lt;br /&gt;
3)	How is it organized?&lt;br /&gt;
4)	Where can I find the rest of the metadata?&lt;br /&gt;
&lt;br /&gt;
*How can you identify which file system it is from looking at the super class&lt;br /&gt;
-&amp;gt; google “magic number of a file” &lt;br /&gt;
-&amp;gt; ex: jpg ctr^c ctr^c : switched the pictures into a binary file &lt;br /&gt;
-&amp;gt; look at the beginning of the file you will see JFIF:  first several bytes in general that identifies the type of the file (magic number)&lt;br /&gt;
File extension : &lt;br /&gt;
	what is it ? &lt;br /&gt;
	is it important&lt;br /&gt;
	the kernel does not know and not care about it&lt;br /&gt;
&lt;br /&gt;
For POSIX file systems: &lt;br /&gt;
-.&amp;gt; file metadata is stored in inodes &lt;br /&gt;
-.&amp;gt; most have pre-reserved inodes &lt;br /&gt;
   -&amp;gt; the only way you can run out of inodes if you keep creating small files &lt;br /&gt;
&lt;br /&gt;
Usenet : al the things you use to post messages thro social media, email, etc. Those were made using Usenet. Like email but Local Usenet server. But it died over time. Every message is stored in an individual file. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Important commands: &lt;br /&gt;
File * : to identify the kind of file system&lt;br /&gt;
1.	As : Run dumpe2fs foo. What does the output of this command mean?&lt;br /&gt;
	Does this give you info about the file system?&lt;br /&gt;
	File bar : bar is the file name and cp comp3000-midterm-2017.pdf bar &lt;br /&gt;
	Evince bar : opens up the pdf file&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
Lec 18 &amp;lt;br&amp;gt;&lt;br /&gt;
* More on filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* How can you recover a fs and how do you delete a file? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
A filesystem is a: &amp;lt;br&amp;gt;&lt;br /&gt;
* Persistent data structure &amp;lt;br&amp;gt;&lt;br /&gt;
* Stored in fixed size blocks (at least 512 bytes in size) &amp;lt;br&amp;gt;&lt;br /&gt;
* Maps hierarchical filenames to file contents &amp;lt;br&amp;gt;&lt;br /&gt;
* Has metadata about files somehow &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What&#039;s in a filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks (stores file content) &amp;lt;br&amp;gt;&lt;br /&gt;
* metadata blocks, you need someway to find the blocks&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you organize metadata?&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
First identify basic characteristics of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- How big is the filesystem? &amp;lt;br&amp;gt;&lt;br /&gt;
- What is the block size? &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do we differentiate between this and other filesystems?&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
You need a &amp;quot;superblock&amp;quot; which is a &amp;quot;summary&amp;quot; block that tells you about everything else&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Format depends on filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
- Normally the superblock is the first block of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
- Think of it almost like the root of a binary tree &amp;lt;br&amp;gt;&lt;br /&gt;
In the superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* Type of filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
** What filesystem magic number is there (lets us identify one filesystem from another just by looking at the first block) &amp;lt;br&amp;gt;&lt;br /&gt;
** File command to know file type &amp;lt;br&amp;gt;&lt;br /&gt;
* Size of the filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
* How the filesystem is organized (different filesystems organize their data differently) &amp;lt;br&amp;gt;&lt;br /&gt;
* Where can I find the rest of the metadata &amp;lt;br&amp;gt;&lt;br /&gt;
He opened a .jpg as a binary file to show us the magic number in a file, first several bytes identify type of file. &amp;lt;br&amp;gt;&lt;br /&gt;
- Kernel does not care about file extension but userspace programs may care about the extension.&amp;lt;br&amp;gt;&lt;br /&gt;
- File extensions are only really useful for the people looking at them&lt;br /&gt;
- Typical for binary file formats to have a set of bytes that identify the type of file&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
POSIX is a standard for maintaining compatibility between operating systems &amp;lt;br&amp;gt;&lt;br /&gt;
- QNX, UNIX, MacOS are all POSIX compliant&lt;br /&gt;
- Others comply on a varying scale&lt;br /&gt;
For POSIX filesystems &amp;lt;br&amp;gt;&lt;br /&gt;
* File metadata is stored in INODES&amp;lt;br&amp;gt;&lt;br /&gt;
* When you create a filesystem, certain blocks are dedicated to being INODES &amp;lt;br&amp;gt;&lt;br /&gt;
- Possible to have space in your filesystem without being able to store things if you run out of INODES &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What is usenet?&lt;br /&gt;
- A worldwide distributed discussion system (stone age version of reddit) &amp;lt;br&amp;gt;&lt;br /&gt;
- Deprecated now because it could not handle the spam people uploaded into it, lol &amp;lt;br&amp;gt;&lt;br /&gt;
- Format for usenet was every message stored in its own file =&amp;gt; lots of small files &amp;lt;br&amp;gt;&lt;br /&gt;
- Everyone has a local usenet server, access to read posts on the forum &amp;lt;br&amp;gt;&lt;br /&gt;
- To post a message, send to local server which replicates it and sends it to all the other servers &amp;lt;br&amp;gt;&lt;br /&gt;
So we have: &amp;lt;br&amp;gt;&lt;br /&gt;
* superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* inode blocks &amp;lt;br&amp;gt;&lt;br /&gt;
* data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for directories &amp;lt;br&amp;gt;&lt;br /&gt;
** data blocks for files &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
How do you recover from damage?&amp;lt;br&amp;gt;&lt;br /&gt;
* Filesystems never &amp;quot;reboot&amp;quot;, must remain correct over time &amp;lt;br&amp;gt;&lt;br /&gt;
* Errors will happen: bitrot (when bits change), accidental corruption, computer failiure/memory corruption/hard reboot &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
To make filesystems fast, data and metadata are cached in RAM &amp;lt;br&amp;gt;&lt;br /&gt;
* Bad things happen if this data hasn&#039;t been writen to disk and you reboot &amp;lt;br&amp;gt;&lt;br /&gt;
* Even worse things happen if your RAM is bad and corrupts the data &amp;lt;br&amp;gt; &lt;br /&gt;
* FSCK is like scandisk in Windows 98 (this only happens when you do a hard reset)&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What happens if you lose the superblock?&amp;lt;br&amp;gt;&lt;br /&gt;
* You could lose EVERYTHING &amp;lt;br&amp;gt;&lt;br /&gt;
* Node trunc dd command blew away first bytes of the file system so you could not mount it because you corrupted the superblock. However, fsck fixed this because we have backup superblocks :D &amp;lt;br&amp;gt;&lt;br /&gt;
- Most filesystems keep copies of the superblock in random locations throughout which takes up some unusable amount of data &amp;lt;br&amp;gt;&lt;br /&gt;
- But this is an impractical way to deal with data blocks &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Old scandisk/fsck was slow because we they had to scan all filesystem metadata &amp;lt;br&amp;gt;&lt;br /&gt;
* Not to recover data, but to fix metadata &amp;lt;br&amp;gt;&lt;br /&gt;
* lost+found might have some files that you might recover. It is a part of the filesystem for fsck to use. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Nowadays fsck is very fast and we rarely lose data due to losing power &amp;lt;br&amp;gt;&lt;br /&gt;
* What this means is we must be writing to disk all the time &amp;lt;br&amp;gt;&lt;br /&gt;
* But isn&#039;t writing slow? All writes aren&#039;t slow particularly on conventional hard disks. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On Magnetic Hard Disks (not SSD&#039;s) &amp;lt;br&amp;gt;&lt;br /&gt;
* sequential oeprations are fast &amp;lt;br&amp;gt;&lt;br /&gt;
* random access is slow &amp;lt;br&amp;gt;&lt;br /&gt;
** we have to move the read/write head &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
So, on modern systems we update metadata (and sometimes data) by writing sequentially to disk...and then later writing randomly &amp;lt;br&amp;gt;&lt;br /&gt;
* Sequential writes go to the journal &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
On fsck on a journaled filesystem&lt;br /&gt;
* just check the journal for pending operations (replaying the journal) &amp;lt;br&amp;gt; &lt;br /&gt;
There exists filesytems for optimizing writes that are pure journal&amp;lt;br&amp;gt;&lt;br /&gt;
* log-based filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Logs and journal inherently create multiple copies of data and metadata that are hard to track. This makes deletion nearly impossible (at least to guarantee) &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Only way to garauntee...encrypt everything &amp;lt;br&amp;gt;&lt;br /&gt;
* if every file has its own key, you can delete the key and this &amp;quot;delete&amp;quot; the data &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
SSD&#039;s use log-structured sotrage at a level below blocks &amp;lt;br&amp;gt;&lt;br /&gt;
* Writes are coarse-grained (you have to write a lot at once) &amp;lt;br&amp;gt;&lt;br /&gt;
* You don&#039;t want to write to the same cells too often, they will die &amp;lt;br&amp;gt; &lt;br /&gt;
** You have to do &amp;quot;wear-leveling&amp;quot; &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_17&amp;diff=21268</id>
		<title>Operating Systems 2017F Lecture 17</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_17&amp;diff=21268"/>
		<updated>2017-11-16T20:39:44Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* In Class */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Nov. 14, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec17-14Nov2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
How do you do kernel hacking?&lt;br /&gt;
&lt;br /&gt;
* Be humble&lt;br /&gt;
  - you don&#039;t know how everything works, and nobody else does&lt;br /&gt;
&lt;br /&gt;
* Verify your assumptions as you go&lt;br /&gt;
  - perform lots of experiments&lt;br /&gt;
  - incremental development, compile and run very often&lt;br /&gt;
&lt;br /&gt;
* Check for errors ALWAYS&lt;br /&gt;
  - will save you from later errors&lt;br /&gt;
  - kernel has to &amp;quot;live cleanly&amp;quot;&lt;br /&gt;
&lt;br /&gt;
* Find another part of the kernel that is close to what you want to do.&lt;br /&gt;
  Read that code, use their approach where possible&lt;br /&gt;
  - You don&#039;t understand all the abstractions and assumptions, so&lt;br /&gt;
    &amp;quot;pattern match&amp;quot; to minimize trouble&lt;br /&gt;
  - Realize that the assumptions behind code you find don&#039;t necessarily match&lt;br /&gt;
    your own.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Additional Notes : &lt;br /&gt;
Lecture 17: &lt;br /&gt;
COMP 3000&lt;br /&gt;
Important notes: &lt;br /&gt;
&lt;br /&gt;
Install kernel module on the remote vm &lt;br /&gt;
Edit them locally, mount the file locally &lt;br /&gt;
Sshfs : What determines what files I can or can’t create, it is file operations, useful tools to edit modules  &lt;br /&gt;
Cd . : what does the . do ? nothing &lt;br /&gt;
. = is the current directory &lt;br /&gt;
.. = parent directory &lt;br /&gt;
It can link to itself &lt;br /&gt;
Compiling and loading all in the vm :  inorder to build ur own modules , you must associate the header to a specific kernel. &lt;br /&gt;
Something is wrong with the metadata ? the files are in the soma not anil class?&lt;br /&gt;
&lt;br /&gt;
Module Professor is walking through , ones:&lt;br /&gt;
 1) Extend its functionality , so it can access info about the process which has made the system call. &lt;br /&gt;
2) Output your process ID is blocked &lt;br /&gt;
-&amp;gt; how to make these changes:&lt;br /&gt;
1) change the dev 1 name ,  newgetpid, change the make file &lt;br /&gt;
-&amp;gt; 2) #define dev name = newgetpid (renaming the device)&lt;br /&gt;
-&amp;gt; 3) get the pid of the user: &lt;br /&gt;
 where is get pid? /kernel/sys.c.  SYS: not a c code, defining a system call that get pid with 0 arguments . &lt;br /&gt;
	Get pid returns? &lt;br /&gt;
Line 37 ) newgetpid_read: these changes are close but it kept repeating itself  &lt;br /&gt;
	Typy char *message = “your PID is unknown!\n”;&lt;br /&gt;
o	Msglen = 21; &lt;br /&gt;
	Change the for loop &lt;br /&gt;
o	For (I =0; I &amp;lt; msglen; i++){&lt;br /&gt;
o	    Put_user(message[i], buf++);&lt;br /&gt;
o	}&lt;br /&gt;
 *offset : long int , and it was equal to 0 so we had to update the offset &lt;br /&gt;
-1: error&lt;br /&gt;
0 : no more bytes to read &lt;br /&gt;
	To figure out if we return the right PID , code a printk&lt;br /&gt;
	Convert int to a string presentation , in order to output how? &lt;br /&gt;
o	Line 39 : create a buffer called message char message [100];&lt;br /&gt;
o	Snprintf : like printf &lt;br /&gt;
	Why is the number is the pid increasing ? since the cat spawns a process &lt;br /&gt;
	Why not use printf instead of snprintf ? since we don’t have STDOUT, it prints to a buffer. &lt;br /&gt;
&lt;br /&gt;
Printk : goeas to kernel log&lt;br /&gt;
	Reading from a file is just an API&lt;br /&gt;
	REST API is similar to the os : since we can read and write anything&lt;br /&gt;
	With a device file : ?? //ask the prof &lt;br /&gt;
	To implement a new function, get the major and minor and device name , creat a function by registering a device file &lt;br /&gt;
	Every device as their own read and write functions , they have to be custome defined &lt;br /&gt;
	They are special, and you can do this to any file &lt;br /&gt;
	Fuse : file system user space , to connect &lt;br /&gt;
	Why do we use goto? : we should not use , can only in the same functions , raising an exception essential in kernel code since the kernel has to resource management and allocating resources and in error condition you don’t . &lt;br /&gt;
	Failed_devreg : deallocating &lt;br /&gt;
	Printf : its not defined in the kernel code, it is defined in the c code and we don’t have stdout &lt;br /&gt;
	&lt;br /&gt;
&lt;br /&gt;
Textbook : No more readings for further lectures &lt;br /&gt;
	Active learning rather than passing &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Important Commands: &lt;br /&gt;
Ls vm : to display the directories in the vm&lt;br /&gt;
Ls –la vm ?: &lt;br /&gt;
Sshfs: &lt;br /&gt;
Get pid: process ID &lt;br /&gt;
Rm ones*: removing the ones&lt;br /&gt;
Sudo rmmod newgetpid : &lt;br /&gt;
Sudo insmode newgetpid.ko: to load the modules?&lt;br /&gt;
Sudo insmode|grep new &lt;br /&gt;
Man getpid : information to get pif of  a process&lt;br /&gt;
Ls –la : for directories and links&lt;br /&gt;
Mkdir : making  directory.&lt;br /&gt;
Uname –r?: &lt;br /&gt;
First number on the left : 21 hardlinks : every directory has a sub directory to it. &lt;br /&gt;
Additional Notes : snprintf is essentially a function that redirects the output of printf to a buffer. This is particularly useful for avoiding repetition of a formatted string. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Understand the &amp;quot;flow of control&amp;quot; inside the program&lt;br /&gt;
  - architecture&lt;br /&gt;
  - division of responsibilites&lt;br /&gt;
  - purpose of data structures/objects&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Scheduling&lt;br /&gt;
----------&lt;br /&gt;
How does the kernel maintain control?&lt;br /&gt;
 - CPU is given entirely to userspace processes to run most of the time&lt;br /&gt;
&lt;br /&gt;
Kernel needs to run when it needs to run&lt;br /&gt;
 - and no process should be able to stop it&lt;br /&gt;
&lt;br /&gt;
*The interrupt table*&lt;br /&gt;
 - pointers to code that the CPU runs when it receives different hardware&lt;br /&gt;
   or software interrupts&lt;br /&gt;
 - since the kernel runs first, it gets to set the interrupt table&lt;br /&gt;
 - only supervisor code can change the table, not user code&lt;br /&gt;
&lt;br /&gt;
So when the ethernet card receives data...&lt;br /&gt;
...the ethernet card sends an interrupt to the kernel&lt;br /&gt;
...the CPU calls the kernel code for handling ethernet data&lt;br /&gt;
&lt;br /&gt;
When the clock generates a timer interrupt...&lt;br /&gt;
...the CPU calls the kernel code for handling timer interrupts&lt;br /&gt;
&lt;br /&gt;
In order to process an interrupt, an CPU core has to be taken over&lt;br /&gt;
 - that core was probably running a userspace process&lt;br /&gt;
&lt;br /&gt;
Scheduling is all about what to do after having kicked a userspace process&lt;br /&gt;
off of a core&lt;br /&gt;
&lt;br /&gt;
Normally on a core&lt;br /&gt;
* userspace process is running&lt;br /&gt;
* interrupt happens&lt;br /&gt;
* core swiches to supervisor mode, runs kernel code&lt;br /&gt;
* last part of kernel code is scheduler, chooses which userspace code to run&lt;br /&gt;
* goto top :-)&lt;br /&gt;
&lt;br /&gt;
Kernel is entered via interrupts, exited via the scheduler&lt;br /&gt;
&lt;br /&gt;
Entry and exit to the kernel has to do low-level tasks like changing CPU modes,&lt;br /&gt;
manage CPU registers&lt;br /&gt;
 - must be written in assembly&lt;br /&gt;
&lt;br /&gt;
Most OS kernels minimize this low-level code&lt;br /&gt;
&lt;br /&gt;
What criteria should the scheduler use in deciding what to run?&lt;br /&gt;
 - &amp;quot;fairness&amp;quot;&lt;br /&gt;
   - prevent starvation&lt;br /&gt;
   - absent other conditions, equal allocation of resources&lt;br /&gt;
 - bias resources towards &amp;quot;foreground&amp;quot; tasks in interactive systems&lt;br /&gt;
   - never biased enough&lt;br /&gt;
   - always hacks, heuristics&lt;br /&gt;
&lt;br /&gt;
Memory overcommitment&lt;br /&gt;
 - it is possible to allocate way more memory than can be ever used&lt;br /&gt;
 - goes into &amp;quot;memory debt&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Midterm Review===&lt;br /&gt;
1. Execve and no it does not create a new process&lt;br /&gt;
&lt;br /&gt;
2. Dynamically linked programs map in dynamically linked libraries&lt;br /&gt;
&lt;br /&gt;
3. Hard links maps filenames to inodes&lt;br /&gt;
&lt;br /&gt;
4. Sleep until the consumer wakes it&lt;br /&gt;
&lt;br /&gt;
5. Using type conversion, read returns number of bytes written. We must convert back to the number of unsigned long, minus one because maximum index of array is one less&lt;br /&gt;
&lt;br /&gt;
6. uses of signals:&lt;br /&gt;
* kill process&lt;br /&gt;
* find out when child process is terminated&lt;br /&gt;
* start/stop a process&lt;br /&gt;
* detect when a program has made a ptr error&lt;br /&gt;
&lt;br /&gt;
7. Pointers in C contain virtual memory addresses because the memory of a process is a virtual address space. Each process thinks it has its own stretch of memory.&lt;br /&gt;
&lt;br /&gt;
8. processes make a sys call to allocate memory. execve -&amp;gt; then mmap and/or sbreak to allocate memory&lt;br /&gt;
&lt;br /&gt;
9. shell opens the file output.txt.&lt;br /&gt;
&lt;br /&gt;
10. mmap contents of file can allocate the contents of it into ram.&lt;br /&gt;
* comparing 1 mb of both files at a time will be less expensive&lt;br /&gt;
* only makes sense to mmap if you will access files multiple times&lt;br /&gt;
&lt;br /&gt;
11. producer and consumer now have no way of talking to each other because they do not share the same memory.&lt;br /&gt;
&lt;br /&gt;
12. no. there is a race condition. while loop loops while sem &amp;lt; 0.&lt;br /&gt;
someone else could access and modify the variable between the while and the sem--;.&lt;br /&gt;
* you need special instructions to test and set the variable at the same time.&lt;br /&gt;
* also, int sem parameter isn&#039;t a ptr so it&#039;s a local variable.&lt;br /&gt;
&lt;br /&gt;
===Additional Notes===&lt;br /&gt;
&lt;br /&gt;
How do you do kernel hacking? Some tips for low level kernel code:&lt;br /&gt;
Be humble; You cannot know how everything works&amp;lt;br&amp;gt;&lt;br /&gt;
Verify your assumptions as you go&amp;lt;br&amp;gt;&lt;br /&gt;
Perform lots of experiments&amp;lt;br&amp;gt;&lt;br /&gt;
Incremental Development, compile and run often&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Check for errors ALWAYS or they will cascade and hurt you later&amp;lt;br&amp;gt;&lt;br /&gt;
*This will save you from later errors&amp;lt;br&amp;gt;&lt;br /&gt;
*Kernel has to live cleanly&amp;lt;br&amp;gt;&lt;br /&gt;
*This principle applies to any large scale coding&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Find another part of the kernel that is close to what you want to do (Search online! This is a good link: http://elixir.free-electrons.com/linux/v4.4.83/source &amp;lt;br&amp;gt;&lt;br /&gt;
You do not understand all abstractions and assumptions, so &amp;quot;pattern match&amp;quot; to minimize trouble &amp;lt;br&amp;gt;&lt;br /&gt;
*Functionality that you want to implement might already exist in the kernel, look at how they do things and follow the pattern.&amp;lt;br&amp;gt;&lt;br /&gt;
*Refine understanding as you go, the other implementation might be for something else. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt; &lt;br /&gt;
Realize that the assumptions behind code you don&#039;t necessarily match to your own. Spend the time reading other people&#039;s code. &amp;lt;br&amp;gt;&lt;br /&gt;
Understand the &amp;quot;flow of control&amp;quot; inside the program&amp;lt;br&amp;gt;&lt;br /&gt;
*Architecture&amp;lt;br&amp;gt;&lt;br /&gt;
*Division of responsibilities&amp;lt;br&amp;gt;&lt;br /&gt;
*Purpose of data structures/objects&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the tutorial 6 he gave us a link for a reason. If you click on it you can search getpid and then dig deeper! For example cut and paste the line inside getuid function. &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Scheduling&amp;lt;br&amp;gt;&lt;br /&gt;
Scheduler decides when what process should run at a high level&amp;lt;br&amp;gt;&lt;br /&gt;
Questions: How does the scheduler work/kernel control when a program runs/how can you make sure one program does not take over CPU from anyone else?&amp;lt;br&amp;gt;&lt;br /&gt;
CPU is given entirely to userspace processes to run most of the time&amp;lt;br&amp;gt;&lt;br /&gt;
Kernel needs to run when it needs to run and no process should be able to stop it&amp;lt;br&amp;gt;&lt;br /&gt;
* The interrupt table: pointers to code that the CPU runs when it receives different hardware or software interrupts. Since the kernel runs first it gets to set the interrupt table. Only supervisor code can change the table not user code.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
When the Ethernet card receives data: &amp;lt;br&amp;gt;&lt;br /&gt;
1) The Ethernet card sends an interrupt to the kernel &amp;lt;br&amp;gt;&lt;br /&gt;
2) The CPU calls the kernel code for handling Ethernet data  &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
When the clock generates a timer interrupt: &amp;lt;br&amp;gt;&lt;br /&gt;
1) The CPU calls the kernel code for handling timer interrupts &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
2) In order to process an interrupt, a CPU core has to be taken over&amp;lt;br&amp;gt;&lt;br /&gt;
3) That core was probably running a userspace process &amp;lt;br&amp;gt;&lt;br /&gt;
4) Scheduling is all about what to do after having kicked a userspace process off of a core&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Normally on a core:&amp;lt;br&amp;gt;&lt;br /&gt;
* Userspace is happening&amp;lt;br&amp;gt;&lt;br /&gt;
* Interrupt happens &amp;lt;br&amp;gt;&lt;br /&gt;
* core switches to supervisor mode, runs kernel code&amp;lt;br&amp;gt;&lt;br /&gt;
* last part of kernel code is scheduler, chooses which userspace code to run. Repeat the process&amp;lt;br&amp;gt;&lt;br /&gt;
Kernel is entered via interrupts, exited via the scheduler&amp;lt;br&amp;gt;&lt;br /&gt;
Scheduler needs to be efficient because interrupts are frequent and we do not want to waste resources that could be put towards actual computing&amp;lt;br&amp;gt;&lt;br /&gt;
Entry and exit to kernel has to do low-level tasks like changing CPU modes, manage CPU registers. This is Assembly code. &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Go to http://elixir.free-electrons.com/linux/v4.4.83/source&amp;lt;br&amp;gt;&lt;br /&gt;
Go into arch: code specific to CPU architecture. Two most commons are arm and x86&amp;lt;br&amp;gt;&lt;br /&gt;
Go up one level&amp;lt;br&amp;gt;&lt;br /&gt;
Drivers directory have drivers for all kinds of things&amp;lt;br&amp;gt;&lt;br /&gt;
Linux Kernel designed for x86 but it now abstracted to support different architectures. &lt;br /&gt;
Go into architecture -&amp;gt; x86 -&amp;gt; entry &amp;lt;br&amp;gt;&lt;br /&gt;
Open entry.s: Large assembly language file. This is the code that runs before system call specific code.&amp;lt;br&amp;gt;&lt;br /&gt;
shced.h -&amp;gt; Contains definition of task_struct. Data structure that keeps track of a process.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
What criteria should the scheduler use in deciding what to run?&amp;lt;br&amp;gt;&lt;br /&gt;
*Fairness: Starvation is when a program does not get the CPU &amp;lt;br&amp;gt;&lt;br /&gt;
**Everyone should get a turn&lt;br /&gt;
**CPU is passed around&lt;br /&gt;
** Nobody should be left that they never get the CPU&lt;br /&gt;
**Prevent Starvation &amp;lt;br&amp;gt;&lt;br /&gt;
**Absent other conditions, equal allocation of resources&lt;br /&gt;
*Bias resources towards &amp;quot;foreground&amp;quot; tasks in interactive systems &lt;br /&gt;
**never Biased enough&lt;br /&gt;
**always hacks, heuristics&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Memory overcommitment&amp;lt;br&amp;gt;&lt;br /&gt;
Memory does not get allocated when you mmap. It is loaded &amp;quot;lazily&amp;quot; in the Linux kernel. It is possible to allocate way more memory than can ever be used. &amp;lt;br&amp;gt;&lt;br /&gt;
Goes into &amp;quot;memory debt&amp;quot; &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21176</id>
		<title>Operating Systems 2017F Lecture 16</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_16&amp;diff=21176"/>
		<updated>2017-11-07T19:08:49Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In Class&lt;br /&gt;
Comp 3000 &lt;br /&gt;
Lecture 16&lt;br /&gt;
Important notes: Tutorial 5:&lt;br /&gt;
File system : &lt;br /&gt;
	persistent data structure organized around blocks (which are fixed allocation units)&lt;br /&gt;
	maps hierarchal names (keys) to values&lt;br /&gt;
	provides a file-like API like open,  read, write, close,etc&lt;br /&gt;
What does it mean to “make” a file system?&lt;br /&gt;
	Initializing a data structure.&lt;br /&gt;
	“formatting” a disk&lt;br /&gt;
Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file)&lt;br /&gt;
Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation &lt;br /&gt;
&lt;br /&gt;
Physical : &lt;br /&gt;
	By default or for multiple of files it is 1K blocks &lt;br /&gt;
	Example : Ext4 has 4k blocks&lt;br /&gt;
&lt;br /&gt;
Kernel Programing : &lt;br /&gt;
	Warning: &lt;br /&gt;
o	If you use linux base , you may crash your whole system, just backup before you do so using “rsync”.&lt;br /&gt;
Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu&lt;br /&gt;
	You are required to use sude to add a user name, so u can play around in root.&lt;br /&gt;
What is a Kernel module ? &lt;br /&gt;
	A way of splitting up kernel functionality so everything does not have to load at boot.&lt;br /&gt;
	Modifies a kernel functionality &lt;br /&gt;
	Runs in kernel space , is the key thing to think about&lt;br /&gt;
o	It is more powerful than root and it can do anything &lt;br /&gt;
o	Access to all kernel memory&lt;br /&gt;
o	And you can modify everything &lt;br /&gt;
	If you miss anything in the kernel development your system will crash &lt;br /&gt;
	Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal&lt;br /&gt;
	Once you install a module , the module is unstrained &lt;br /&gt;
Why do we use modules? Why don’t we load processes instead?&lt;br /&gt;
	No new mechanisms &lt;br /&gt;
	Increased security (restricted access)&lt;br /&gt;
	Makes the kernel less smaller, microkernel design, &lt;br /&gt;
o	Putting in the functions that are supposed to be in the kernel into processes&lt;br /&gt;
o	Process do IPC rather than code talking in supervisor mode&lt;br /&gt;
	Examples : &lt;br /&gt;
•	Filesystems&lt;br /&gt;
•	Drivers&lt;br /&gt;
•	Networking&lt;br /&gt;
•	Minix, QNX, GNU, hurd, &lt;br /&gt;
	Why is Linux  “monolithics” kernel ?&lt;br /&gt;
o	Switching between contexts are expensive (context switch)&lt;br /&gt;
o	How to make microkernels fast can be adopted by monolithics kernels to make them even faster &lt;br /&gt;
o	Unreal security benefits :&lt;br /&gt;
	if you control the file system process, you can control everything &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Rebuilding and changing the kernel: &lt;br /&gt;
	1)Type “make” : more compilacted than 2401 &lt;br /&gt;
o	Kernel built&lt;br /&gt;
	2)Make modules &lt;br /&gt;
	3)Sudo make install &lt;br /&gt;
	4) sudo make-modules install &lt;br /&gt;
	5) Sudo shutdown –r now : for the vm to reboot &lt;br /&gt;
	Which configuration would you use to build your own kernel ? &lt;br /&gt;
o	Don’t do configurations from scratch&lt;br /&gt;
o	Copy the configurations and use them&lt;br /&gt;
o	Make localmodconfig : output for ls mod and uses that for configuring your kernel&lt;br /&gt;
o	Requires time and effort &lt;br /&gt;
	Why less /dev/ones doesn’t exist anymore?&lt;br /&gt;
o	Since reboot occurred&lt;br /&gt;
o	You must load the modules again &lt;br /&gt;
o	Head –c 100 /dev/ones to be able to use it again&lt;br /&gt;
	Implementing the device file of dev 1 ? &lt;br /&gt;
&lt;br /&gt;
o	Implement the file API required &lt;br /&gt;
o	Teach the kernel what it means to do operations like read, etc&lt;br /&gt;
Code from the tutorial ones.c:&lt;br /&gt;
	Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset &lt;br /&gt;
o	Offset : position in the file &lt;br /&gt;
o	Fills the buffer with ones &lt;br /&gt;
o	Why don’t we just set it to 1 instead of putting put_user? &lt;br /&gt;
	Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely &lt;br /&gt;
o	Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Commands: &lt;br /&gt;
Man ls : to see different ls commands &lt;br /&gt;
	Ls –las block &lt;br /&gt;
	Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1&lt;br /&gt;
	Ls –mod : displays all the moduls which are currently loaded on the virtual machine &lt;br /&gt;
	IBM ps/2 :  series of computers created to control PC, developed the interfaces to have a mouse and keyboard. &lt;br /&gt;
	Less readme : to check instructions of how to do a make&lt;br /&gt;
	Make menuconfig : options of kernel configurations&lt;br /&gt;
	Cat/pro&lt;br /&gt;
	Less .config : bad idea to go directly in it , use “make menuconfig “&lt;br /&gt;
	/boot : where the kernel got installed.&lt;br /&gt;
o	Ls –lah : to see the size&lt;br /&gt;
	Less/ etc/modules&lt;br /&gt;
	Modul init: what function should be called when loaded and when it is unloaded &lt;br /&gt;
	Modul exit: &lt;br /&gt;
	Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)&lt;br /&gt;
	What happens if you start running to the file ? permission are read only, not writing&lt;br /&gt;
o	Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_14&amp;diff=21167</id>
		<title>Operating Systems 2017F Lecture 14</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_14&amp;diff=21167"/>
		<updated>2017-11-04T04:59:49Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* Review Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
The video from the lecture given on Oct. 31, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec14-31Oct2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Review Notes==&lt;br /&gt;
&lt;br /&gt;
Definitions:&lt;br /&gt;
&lt;br /&gt;
 - OS: A resource Manager that abstracts the hardware so that applications can get easy access to it.  The OS facilitates resource sharing among concurrent programs.&lt;br /&gt;
 - Kernel: The first program to launch when the computer boots.  The kernel has absolute power over the hardware; it manages and controls access to these resources.&lt;br /&gt;
 - Process: A running program.  It has one or more threads and address space.&lt;br /&gt;
 - Thread: A function that runs in the same memory space as other functions.&lt;br /&gt;
 - Memory: A contiguous array of bytes.  Modern systems virtualize memory, mapping it to physical memory so it can be shared among processes.&lt;br /&gt;
 - Interrupts: A mechanism used by the kernel that interrupts the CPU when other tasks are higher priority.&lt;br /&gt;
 - Signals: Inter-process communications.  A mechanism used by the kernel and processes to communicate with one another.&lt;br /&gt;
 - System Call: Specialized functions used by programs to request more resources from the kernel.&lt;br /&gt;
 - File: A hierarchical name with a value mapping (Key/Value pair)&lt;br /&gt;
 - Shell: Another program that is used to send system calls to the kernel or launch other programs.&lt;br /&gt;
 - File system: A set of files grouped together with a common hierarchical root.&lt;br /&gt;
 - Fragmentation: Variable sized memory allocation.&lt;br /&gt;
 - Internal Fragmentation: Space wasted in an allocation.&lt;br /&gt;
 - Concurrency: More than one thing happening at a time.&lt;br /&gt;
 - Atomic Variables: Variables that guarantee a strict ordering of operations.&lt;br /&gt;
 - Segmentation: Managing memory without paging.&lt;br /&gt;
 - Segments: A variable sized block of memory that can be placed in different parts of the address space.&lt;br /&gt;
 - Segfault: When a virtual address does not have a corresponding physical address.&lt;br /&gt;
 - mmap: The virtual address range corresponds to the contents of a file or RAM.&lt;br /&gt;
 - Concurrency: More than one thing is happening at the same time.&lt;br /&gt;
&lt;br /&gt;
**********************************************************&lt;br /&gt;
Professor&#039;s explanations of assignment 1 and 2 :&lt;br /&gt;
&lt;br /&gt;
What does stat really return?&lt;br /&gt;
Inode number, directry , number if hard links &lt;br /&gt;
If you have a file, you basically hard link, and it is basically a reference count.&lt;br /&gt;
	Manual page for stat() , man stat(2)&lt;br /&gt;
o	Ctime: modification made by the inode,&lt;br /&gt;
o	Everytime you read a file, you write to a file system , and it is expensive and not good for you device&lt;br /&gt;
	Device files are not real file, they are name spaces to access other things, like terminal, screen video. &lt;br /&gt;
o	Ex: dev random, is not really a file, it just produces bits&lt;br /&gt;
o	You have to compare which device they are pointing to and if they return the same major and minor ID’s then they are equal&lt;br /&gt;
Q10 Review : &lt;br /&gt;
	Only if it is waiting you wake it up and set the flag into 1 &lt;br /&gt;
o	Affect = kicks you out &lt;br /&gt;
o	Generating a lot of signals to the consumer&lt;br /&gt;
	A signal should happen occasionally &lt;br /&gt;
o	Kill -1 , you kill every process . don’t get it ask ? &lt;br /&gt;
o	Maybe you should set the consumer to 0 and see what happens , in 3000pc &lt;br /&gt;
	Why does the program deadlocks when request a large amount of numbers ? &lt;br /&gt;
o	signals aren’t always delivered , they sometimes get lost, but generlay they get there unless you send various amount of signals&lt;br /&gt;
	theory about time: &lt;br /&gt;
o	gettimeofdat: man gettimeofday&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Creating a process:&lt;br /&gt;
* fork() creates a process and execve() loads the binary to the new process.&lt;br /&gt;
** returns a process id&lt;br /&gt;
*** pid &amp;gt; 0, parent process&lt;br /&gt;
*** pid &amp;lt; 0, error&lt;br /&gt;
*** pid = 0, child process&lt;br /&gt;
&lt;br /&gt;
* When a parent does not deal with its child processes they become zombies&lt;br /&gt;
* If a parent dies before its children they become orphans that are re-parented by the OS&lt;br /&gt;
&lt;br /&gt;
* wait()&lt;br /&gt;
** suspends the current process until one, some, or all of its children have terminated&lt;br /&gt;
** wait() can be called anytime to check on the status of children&lt;br /&gt;
&lt;br /&gt;
IO redirection:&lt;br /&gt;
* &amp;gt;, direct to stdout&lt;br /&gt;
* &amp;lt;, direct to stdin&lt;br /&gt;
* |, connect the output of one process to the input of another process&lt;br /&gt;
* when a process starts it is given file descriptors to stdout, stdin, and stderr&lt;br /&gt;
&lt;br /&gt;
Inodes:&lt;br /&gt;
* Contain information about the blocks corresponding to the contents of a file on disk, its owner, and the file access permissions.&lt;br /&gt;
* A filename points to an inode&lt;br /&gt;
* The inode count represents all of the files and folders on disk&lt;br /&gt;
* Hard links create another name to the same inode number&lt;br /&gt;
** Only point to files within the same file system&lt;br /&gt;
* Symbolic links are files with their own inode&lt;br /&gt;
** Can point to files in other partitions or file systems&lt;br /&gt;
&lt;br /&gt;
Virtual Memory:&lt;br /&gt;
* Every process receives a memory map with virtual addresses that correspond to physical addresses.&lt;br /&gt;
&lt;br /&gt;
Memory Allocation Challenges:&lt;br /&gt;
* Need to have a contiguous address range&lt;br /&gt;
* Data Structures can not be moved once allocated&lt;br /&gt;
* Memory is constantly allocated and deallocated&lt;br /&gt;
&lt;br /&gt;
Solution to these challenges:&lt;br /&gt;
* Use fixed size chunks that can be stored anywhere&lt;br /&gt;
** Called a page in memory or a block on disk&lt;br /&gt;
** Sizes are always a power of 2 because addresses are indexed in bits&lt;br /&gt;
** The benefit: it removes the limitations on array sizes.&lt;br /&gt;
** Use a table to map virtual memory to physical memory -- called a page table&lt;br /&gt;
** In a 32 bit system: the top 20 bits are the page locations and the lower 12 bits are the page offset&lt;br /&gt;
&lt;br /&gt;
Concurrency:&lt;br /&gt;
* Challenge: keeping the shared state consistent; want deterministic behavior from concurrent computations&lt;br /&gt;
* Solution: Need mechanisms that bypass the memory hierarchy.&lt;br /&gt;
** Use filesystem locking primitives -&amp;gt; atomic variables -&amp;gt; semaphores&lt;br /&gt;
** Use signals to synchronize the shared state&lt;br /&gt;
&lt;br /&gt;
Segmentation:&lt;br /&gt;
* The physical address can be found by adding the segment register to the offset.&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_13&amp;diff=21166</id>
		<title>Operating Systems 2017F Lecture 13</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_13&amp;diff=21166"/>
		<updated>2017-11-04T04:58:24Z</updated>

		<summary type="html">&lt;p&gt;HebaJallad: /* Note */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on October 19, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec13-19Oct2017.mp4 is now available].&lt;br /&gt;
&lt;br /&gt;
==Code==&lt;br /&gt;
&lt;br /&gt;
Files from the lecture [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec13/ are available].&lt;br /&gt;
&lt;br /&gt;
==Note==&lt;br /&gt;
&lt;br /&gt;
===Questions:===&lt;br /&gt;
Mutex and semaphore?&lt;br /&gt;
&lt;br /&gt;
Mutex is a binary semaphore, it is a semaphore that take a value that is zero or one, a classic semaphore can count.&lt;br /&gt;
&lt;br /&gt;
Mutex stands for ‘mutual exclusion’: I am exclusive access, no one else does.&lt;br /&gt;
&lt;br /&gt;
More general semaphore is used when you need to keep track of numbers.&lt;br /&gt;
&lt;br /&gt;
Most classic semaphore: read write semaphore. which will be seen in the kernel. The idea is multiple reader and only one writer.&lt;br /&gt;
&lt;br /&gt;
Most of the time we use mutex.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== dinner philosopher problem ===&lt;br /&gt;
&lt;br /&gt;
 Wiki page: https://en.wikipedia.org/wiki/Dining_philosophers_problem&lt;br /&gt;
&lt;br /&gt;
You have five philosophers sitting around the table, these philosophers will talk, and they will talk so much, they don’t really want to focus on eating. And for some reason there is not enough of forks at the table. There is one fork at every position between the plates. In order to eat anything, you need two forks.(Maybe better to think about using chopsticks instead of forks). There are five people there and only five forks.&lt;br /&gt;
&lt;br /&gt;
******************************************************************************************************************************************************************************************************&lt;br /&gt;
Important notes, 3000&lt;br /&gt;
Lecture 13&lt;br /&gt;
//can be represented with chopsticks which makes more sense.&lt;br /&gt;
Illustration of the dining philosophers problems: an example the professor represented, in which philosophers need 2 forks to have dinner but they only have 1 so they will share at random timing but will end up in a mess and an error . This error illustrates deadlock. We can have them to have a delay then pick it up but then they will never eat, we can also have them to do that at randomization which will work but then end up in an error which I explained earlier.&lt;br /&gt;
Code used in class is tutorial 4 code and the professor is modifying it to explain. &lt;br /&gt;
Shared state: when they get both of locks (2 chopsticks) they get a message. Modify the code. The message will state “eat it” in the code.&lt;br /&gt;
In the code presented in class: 5 philosopher and 5 chopsticks. Initilized each semaphore, each Copstick has a lock.&lt;br /&gt;
Create a processes for each philosopher by forking each one and each will have an ID.&lt;br /&gt;
Exit the for loop so each child will continue to fork &lt;br /&gt;
Wait time :  they are concurrent , the real time is 1 sec. Philosophers are running concurrently &lt;br /&gt;
&lt;br /&gt;
	Dead lock: the computation cant proceed any further, since the concurrent processes can’t access the other resources. Enough resources you never have to share, deadlock won’t happen. But if you have shared sources you may occur with a deadlock.&lt;br /&gt;
&amp;gt;	Release the locks: ( put a chopstick down) using post in the code&lt;br /&gt;
Does is matter which one will be released first? &lt;br /&gt;
	Running the code: someone only has one chopstick and someone did not get it. The code got stuck &lt;br /&gt;
o	How so we solve this? : &lt;br /&gt;
	Man Sem_wait()  to see if it is available to solve this problem. Put sem_wait() and sem_trywait() to check out the problem. &lt;br /&gt;
	Create a new function called get chopstick , and it failed so thr prof added a sleep() &lt;br /&gt;
	There is no chopstick 5 = have a bug,  #1 failed  and no one else is eating except #1. They tried to eat 50 times&lt;br /&gt;
	No deadlock since we have enough sources, since they exit.&lt;br /&gt;
	If one exits there is enough chopsticks&lt;br /&gt;
	The prof tried while (1) which  is an infinite loop.&lt;br /&gt;
	 Our code never locks, no dead lock now. Why is that? Nvm some of them are deadlocked such as 4. &lt;br /&gt;
	Why don’t we access the CHPstick in a fixed order? (Ask what he means) &lt;br /&gt;
•	Which one do we get first? &lt;br /&gt;
	Solution :  If you get 1 only and not 2, you must let go of it and then try to get both.&lt;br /&gt;
	Release in the opposite order you acquire them &lt;br /&gt;
	Practice on semaphores, and creating processes&lt;br /&gt;
	After the midterm : kernel hacking&lt;br /&gt;
	Linux cross reference : source code into file system (fs) data_sem and others are semaphores&lt;br /&gt;
	Have to enforce mutual exclusion and that why we use semaphores down = lock, up = release. &lt;br /&gt;
	Have to release the semaphores so someone accesses the inode&lt;br /&gt;
To ask :&lt;br /&gt;
Why is there more chopsticks than philosophers &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
*Senario 1: they all pick the left one at the same time, they all now have one fork.- can any of them eat? no, they suppose to use two forks to eat.&lt;br /&gt;
*Senario 2: Immediately put a fork down, wait for five seconds, and pick a fork. (have a delay, and pick it up) -they will never eat, because they always get one fork.&lt;br /&gt;
*Senario 3: randomize it? When they get one fork and couldn’t get the other one, they put it back down, wait a random amount of time and get the next one. -Yes this will work on average, except sometime randomly they will pick up a fork at the same time and starve to death. (unless you have a timeout)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This illustrate the concept of &#039;&#039;&#039;deadlock&#039;&#039;&#039;: you get to the point where the computation cannot proceed any further. Because the concurrence processes cannot get all the resource. Some of them can access the resources and some of them do not have the resources, so everyone stuck. &lt;br /&gt;
&lt;br /&gt;
 Wiki page: https://en.wikipedia.org/wiki/Deadlock&lt;br /&gt;
&lt;br /&gt;
When your computer logs up, a lot of time it is because of the deadlock. Something get locked and never get unlocked at the driver.&lt;br /&gt;
&lt;br /&gt;
One way to avoid deadlock: if you have enough resources you never have to share, deadlock never happen.&lt;br /&gt;
If you have shared resources, you can’t have deadlock.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After the midterm we will do more kernel hacking.&lt;/div&gt;</summary>
		<author><name>HebaJallad</name></author>
	</entry>
</feed>