<?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=KYuan</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=KYuan"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/KYuan"/>
	<updated>2026-05-12T21:37:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21286</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=21286"/>
		<updated>2017-11-21T19:14:32Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Additional Notes */&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;
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&lt;/div&gt;</summary>
		<author><name>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21283</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=21283"/>
		<updated>2017-11-21T18:37:13Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Additional 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&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; some kind&lt;br /&gt;
* event loops poll (check) to see when there are new events&lt;br /&gt;
* what are event loops for node app?&lt;br /&gt;
** where are interrupts for node apps? &lt;br /&gt;
***Incoming network requests, it&#039;s an event&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OS kernels are essentially the same thing&lt;/div&gt;</summary>
		<author><name>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_19&amp;diff=21282</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=21282"/>
		<updated>2017-11-21T18:31:42Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* [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;/div&gt;</summary>
		<author><name>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_18&amp;diff=21252</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=21252"/>
		<updated>2017-11-16T18:18:15Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Additional Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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 &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;
&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;
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;
In the superblock &amp;lt;br&amp;gt;&lt;br /&gt;
* Type of filesystem &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 &amp;lt;br&amp;gt;&lt;br /&gt;
* Where can I find the rest of the metadata &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_17&amp;diff=21234</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=21234"/>
		<updated>2017-11-14T21:16:17Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Additional Notes */&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;
* 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;
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; int he 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>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_17&amp;diff=21231</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=21231"/>
		<updated>2017-11-14T20:10:10Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Midterm Review */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
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;
&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;
&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; int he 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>KYuan</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2017F_Lecture_17&amp;diff=21230</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=21230"/>
		<updated>2017-11-14T20:07:59Z</updated>

		<summary type="html">&lt;p&gt;KYuan: /* Additional Notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&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;
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;
&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;
&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; int he 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>KYuan</name></author>
	</entry>
</feed>