<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_6</id>
	<title>Operating Systems 2021F Lecture 6 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2021F_Lecture_6"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_6&amp;action=history"/>
	<updated>2026-04-06T04:46:34Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_6&amp;diff=23349&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on September 28, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec06-20210928.m4...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_6&amp;diff=23349&amp;oldid=prev"/>
		<updated>2021-09-28T16:37:03Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on September 28, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec06-20210928.m4...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video from the lecture given on September 28, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec06-20210928.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec06-20210928.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Class zoom meetings-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 6&lt;br /&gt;
---------&lt;br /&gt;
 - deadlines&lt;br /&gt;
   - A1 is due Friday, Oct 1&lt;br /&gt;
      - but will be accepted until October 5th 10 AM&lt;br /&gt;
        no penalty&lt;br /&gt;
        (we&amp;#039;ll discuss solutions in class)&lt;br /&gt;
   - but T1 &amp;amp; T2 are due by midnight on October 1st&lt;br /&gt;
&lt;br /&gt;
   - Tutorial 3 came out yesterday, officially due in a week&lt;br /&gt;
      - but will be accepted until the official due date of A2&lt;br /&gt;
&lt;br /&gt;
 - missing official deadlines don&amp;#039;t have grading penalties&lt;br /&gt;
    - until the hard deadline&lt;br /&gt;
 - but if you miss one, you should consider yourself behind&lt;br /&gt;
&lt;br /&gt;
What is the material for the midterm?&lt;br /&gt;
 - the two assignments&lt;br /&gt;
 - I literally take the assignment questions as a basis for&lt;br /&gt;
   the midterm questions (making a question up to cover the concepts of an assignment question or two)&lt;br /&gt;
 - midterm is all short answer, should be answerable without&lt;br /&gt;
   referring to notes or using a computer&lt;br /&gt;
    - but it is open book, open note, open internet&lt;br /&gt;
    - just NO COLLABORATION&lt;br /&gt;
 - remember there will be randomized interviews after&lt;br /&gt;
   - to make sure they were graded fairly&lt;br /&gt;
   - but yes, if it is clear what you know is different from&lt;br /&gt;
     what is on the test...we&amp;#039;ll have a problem&lt;br /&gt;
&lt;br /&gt;
 - My dog&amp;#039;s name is Roshi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Topics for today&lt;br /&gt;
----------------&lt;br /&gt;
 - stack vs. heap&lt;br /&gt;
 - assembly directives&lt;br /&gt;
 - standard I/O, I/O redirection&lt;br /&gt;
 - terminals&lt;br /&gt;
&lt;br /&gt;
To try and understand a memory map, helpful to run with setarch -R&lt;br /&gt;
 - disables ASLR (address space layout randomization),&lt;br /&gt;
   a security mitigation against code injection attacks&lt;br /&gt;
&lt;br /&gt;
Note that the addresses in a process are consistent from run to run with setarch -R&lt;br /&gt;
 - because each process has its own address space&lt;br /&gt;
 - process address spaces are &amp;quot;virtual&amp;quot;&lt;br /&gt;
    - no direct correspondence to addresses of actual RAM in your&lt;br /&gt;
      computer (physical addresses)&lt;br /&gt;
 - OS manages virtual &amp;lt;-&amp;gt; physical address mappings&lt;br /&gt;
 - memview gives us a view of virtual addresses&lt;br /&gt;
    - cannot access physical addresses outside of the kernel&lt;br /&gt;
    - (page tables are the data structure that maintains&lt;br /&gt;
       virtual &amp;lt;-&amp;gt; physical mappings, but we&amp;#039;ll talk about that&lt;br /&gt;
       later)&lt;br /&gt;
&lt;br /&gt;
 - In a classic view of C programs, variables are stored in the&lt;br /&gt;
   &amp;quot;stack&amp;quot; or the &amp;quot;heap&amp;quot;&lt;br /&gt;
     - stack is for local variables&lt;br /&gt;
     - heap is for malloc&amp;#039;d variables&lt;br /&gt;
 - but the memory map is more complex&lt;br /&gt;
&lt;br /&gt;
 - normally there is an area for runtime data storage in memory that holds the stack and the heap&lt;br /&gt;
    - heap is allocated starting from the bottom (lowest address) and the stack is allocated from the top (highest address)&lt;br /&gt;
    - sbrk(0) gives you the address of the beginnig of the free space in the heap&lt;br /&gt;
    - as you allocate things dynamically, sbrk(0) increases&lt;br /&gt;
    &lt;br /&gt;
 - note that code &amp;amp; static data (data fixed at compile time)&lt;br /&gt;
   are stored together (i.e., strings embedded in the code)&lt;br /&gt;
 &lt;br /&gt;
A segment is just a variable-sized area of memory&lt;br /&gt;
 - generally with specific semantics (purpose)&lt;br /&gt;
     .text is normally the code&lt;br /&gt;
     .rodata is read-only data known at compile time&lt;br /&gt;
 - main thing to know is the stack and the heap don&amp;#039;t have&lt;br /&gt;
   anything really in the on-disk segments&lt;br /&gt;
     - at most you have a declaration&lt;br /&gt;
     - they are then dynamically allocated at runtime&lt;br /&gt;
 - stack/heap is really one segment used for dynamic allocation&lt;br /&gt;
    - but nowadays they are logically separate because we don&amp;#039;t&lt;br /&gt;
      want the stack and the heap to ever collide&lt;br /&gt;
       - we add barriers between them&lt;br /&gt;
 - a &amp;quot;quad&amp;quot; is a 64-bit quantity&lt;br /&gt;
   - I think this is historic, quad word, when&lt;br /&gt;
     a &amp;quot;word&amp;quot; was 16 bits (i.e., when registers only held&lt;br /&gt;
     16 bits, not 64 bit quantities)&lt;br /&gt;
&lt;br /&gt;
- With static linking, all references are resolved at link time&lt;br /&gt;
- With dynamic linking, some references have to be resolved at&lt;br /&gt;
runtime (the runtime dynamic linker has to run before main starts)&lt;br /&gt;
&lt;br /&gt;
- this is why dynamically linked programs have many more system calls before main than do statically linked programs&lt;br /&gt;
  - it is literally loading files from disk, i.e., the C library&lt;br /&gt;
&lt;br /&gt;
 - make sure you understand the output of memview&lt;br /&gt;
    - and try similar things in 3000quiz to see its memory map&lt;br /&gt;
&lt;br /&gt;
I would suggest translating the output of 3000memview into a diagram&lt;br /&gt;
  - label it with addresses&lt;br /&gt;
  - see where things are relative to each other&lt;br /&gt;
  - you should see a clear picture&lt;br /&gt;
     - and if parts don&amp;#039;t make sense, ask!&lt;br /&gt;
&lt;br /&gt;
Standard I/O&lt;br /&gt;
 - you&amp;#039;ve learned about standard in, out, and error&lt;br /&gt;
 - correspond to file descriptors 0, 1, and 2 as we&lt;br /&gt;
   previously discussed&lt;br /&gt;
 - but how do we change them, and where do they point by default?&lt;br /&gt;
&lt;br /&gt;
In most shells, you can use &amp;lt;, &amp;gt;, and | to redirect standard in and out&lt;br /&gt;
 - &amp;gt;  redirect standard output&lt;br /&gt;
 - &amp;lt;  redirect standard input&lt;br /&gt;
 - |  redirect the standard output of one program to the&lt;br /&gt;
      standard input of another&lt;br /&gt;
&lt;br /&gt;
These operators can work with arbitrary file descriptors,&lt;br /&gt;
just give the number before them (for &amp;lt; and &amp;gt; at least)&lt;br /&gt;
&lt;br /&gt;
Example, standard error redirection is 2&amp;gt;&lt;br /&gt;
 (so 1&amp;gt; is the same as &amp;gt;)&lt;br /&gt;
&lt;br /&gt;
If I don&amp;#039;t redirect standard in, out, and error, where are they going by default?&lt;br /&gt;
 - they are going to a file, but what file?&lt;br /&gt;
&lt;br /&gt;
Whether you are in a graphical text window locally or have ssh&amp;#039;d to a remote system, you&amp;#039;ll probably see bash&amp;#039;s file descriptors referring to /dev/pts/? (where ? is a small number)&lt;br /&gt;
&lt;br /&gt;
What is /dev/pts?&lt;br /&gt;
 - pseudo TTYs&lt;br /&gt;
&lt;br /&gt;
A teletype is like a fancy telegraph&lt;br /&gt;
 - you type in things locally, they appear at a remote printer&lt;br /&gt;
 - remote person types, you see it locally, printed out&lt;br /&gt;
 - OLD fashion version of texting&lt;br /&gt;
&lt;br /&gt;
When computers came around, early interactive interfaces were teletypes&lt;br /&gt;
 - computer was one side, rather than a human&lt;br /&gt;
 - was printing to paper rather than a screen&lt;br /&gt;
 - could produce A LOT of paper&lt;br /&gt;
&lt;br /&gt;
Eventually the paper was replaced with a CRT (cathode ray tube)&lt;br /&gt;
 - see the VT100, a &amp;quot;video terminal&amp;quot;&lt;br /&gt;
 - teletype but with screen output, not paper output&lt;br /&gt;
 - pure text! (except sometimes for weird fonts with shapes)&lt;br /&gt;
&lt;br /&gt;
There were LOTS of video terminals&lt;br /&gt;
 - many incompatibilities&lt;br /&gt;
 - so UNIX developed ways of dealing with different terminals&lt;br /&gt;
   - terminfo database&lt;br /&gt;
 - the TERM environment variable says which terminal you&amp;#039;re using&lt;br /&gt;
 - when you connect to your class VM, what&amp;#039;s the value of TERM&lt;br /&gt;
   for you?  It may be different from mine&lt;br /&gt;
&lt;br /&gt;
Why does the type of terminal matter?&lt;br /&gt;
 - because not all text interfaces are the same!&lt;br /&gt;
 - when I run a program in a terminal that shows colors or positions text at specific locations on the screen, it is using special escape codes to do all that&lt;br /&gt;
    - it is just sending data to standard out, encoded so&lt;br /&gt;
      the terminal understands it&lt;br /&gt;
    - the terminfo files tells common libraries how to use&lt;br /&gt;
      common terminal capabilities&lt;br /&gt;
&lt;br /&gt;
 - but how do you get a program like gnome-terminal to behave like a teletype, and how can ssh do the same?&lt;br /&gt;
   - they implement the pseudo tty interface via /dev/pts&lt;br /&gt;
   - any program that implements the pseudo tty interface&lt;br /&gt;
     can behave like a terminal to a program&lt;br /&gt;
&lt;br /&gt;
So question, why does it have to be a special device?&lt;br /&gt;
 - because terminals are devices with special capabilities&lt;br /&gt;
   - special things for interacting with keyboard and screen&lt;br /&gt;
     - big thing is speed traditionally, we&amp;#039;d connect via&lt;br /&gt;
       modems and so buffering, local echo were necessary&lt;br /&gt;
 - different from a regular file&lt;br /&gt;
&lt;br /&gt;
When you interact with a terminal, you&amp;#039;re dealing with tech with 50+ years of history&lt;br /&gt;
 - lots of weird bits if you really dig in&lt;br /&gt;
&lt;br /&gt;
Terminal tricks&lt;br /&gt;
 - reset state: reset&lt;br /&gt;
 - disable local echo (say for password entry): stty -echo&lt;br /&gt;
&lt;br /&gt;
man stty to see all the things you can do with a terminal&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>