<?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_2022F_Lecture_5</id>
	<title>Operating Systems 2022F Lecture 5 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2022F_Lecture_5"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_5&amp;action=history"/>
	<updated>2026-04-05T22:41:58Z</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_2022F_Lecture_5&amp;diff=24066&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on September 22, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&gt;Zoom meeting-&gt;Cloud Recordings tab)  ==Notes==  &lt;pre&gt; Lecture 5 ---------  Today, Tutorial 3, along with some...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_5&amp;diff=24066&amp;oldid=prev"/>
		<updated>2022-09-23T02:08:13Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on September 22, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)  ==Notes==  &amp;lt;pre&amp;gt; Lecture 5 ---------  Today, Tutorial 3, along with some...&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 22, 2022 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec05-20220922.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&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 5&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Today, Tutorial 3, along with some old business&lt;br /&gt;
&lt;br /&gt;
Admin notes&lt;br /&gt;
 - Assignment 1 is due Sept 28th before midnight&lt;br /&gt;
 - Tutorial 1 &amp;amp; 2 are also due at the same time&lt;br /&gt;
    - really, you should have them done by now&lt;br /&gt;
    - MAKE SURE YOU GET CHECKED OFF ASAP&lt;br /&gt;
 - Don&amp;#039;t do the assignment before doing the tutorials!&lt;br /&gt;
&lt;br /&gt;
 - change in TA &amp;amp; tutorial policy&lt;br /&gt;
    - you can go to ANY TA to get marked for a tutorial&lt;br /&gt;
    - your assigned TA will be following up with anyone who is running&lt;br /&gt;
      behind on tutorials (i.e., starting tomorrow they will start&lt;br /&gt;
      checking in with you)&lt;br /&gt;
&lt;br /&gt;
 - Why aren&amp;#039;t there tutorial solutions?&lt;br /&gt;
    - because the answers aren&amp;#039;t the point!&lt;br /&gt;
    - you should know when you understand something&lt;br /&gt;
        - there are no solution keys once you leave school&lt;br /&gt;
    - if you focus on the answer rather than techniques for figuring&lt;br /&gt;
      out answers (beyond searching), you won&amp;#039;t do well in this class&lt;br /&gt;
      because you&amp;#039;ll nevel develop enough of a mental model to do the work&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ctrl-D is end of file in UNIX, so if you type it into many command line programs they will terminate.&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Background processing&amp;quot;&lt;br /&gt;
 - normally when you run a command in a shell, it waits for it to finish&lt;br /&gt;
 - if you run a command &amp;quot;in the background&amp;quot;, it won&amp;#039;t wait&lt;br /&gt;
    - so the shell &amp;amp; the command are running at the same time&lt;br /&gt;
 - specifically&lt;br /&gt;
    - with foreground processing, the shell does a blocking wait&lt;br /&gt;
      on the child.&lt;br /&gt;
    - with background processing, the shell continues execution and doesn&amp;#039;t&lt;br /&gt;
      do a wait until it gets a message (signal) that the child has exited&lt;br /&gt;
&lt;br /&gt;
In classic UNIX systems, we have two core system calls for creating processes and running programs:&lt;br /&gt;
 - fork duplicates the current process&lt;br /&gt;
 - execve replaces the program *in the current process* with that from a file&lt;br /&gt;
&lt;br /&gt;
(fork/execve is not great in lots of circumstances, people are developing alternative APIs currently for Linux, but for a shell they are near perfect)&lt;br /&gt;
&lt;br /&gt;
When I type &amp;quot;ls&amp;quot; at a shell prompt&lt;br /&gt;
 - the shell (bash, 3000shell) first &amp;quot;forks&amp;quot;, creates a child process&lt;br /&gt;
   that is a duplicate process (i.e., it is running bash or 3000 shell as well&lt;br /&gt;
   in exactly the same state, except for the return value of fork)&lt;br /&gt;
 - the child process (the new one that was just created) does an execve&lt;br /&gt;
   of /usr/bin/ls, thus replacing the bash binary with ls&lt;br /&gt;
 - the parent process (still running bash) waits for the child process to&lt;br /&gt;
   terminate (do an exit system call), and once it does it prints a new prompt&lt;br /&gt;
&lt;br /&gt;
If I type &amp;quot;ls &amp;amp;&amp;quot;&lt;br /&gt;
 - it is exactly the same except for the last step.  It just prints the prompt.&lt;br /&gt;
 &lt;br /&gt;
   &lt;br /&gt;
Why does the output look weird with &amp;quot;ls &amp;amp;&amp;quot;?&lt;br /&gt;
  - because the prompt is printed before the output of ls&lt;br /&gt;
&lt;br /&gt;
Note in bash, if you say &amp;quot;exec &amp;lt;cmd&amp;gt;&amp;quot; it will skip the fork, will just do an execve&lt;br /&gt;
&lt;br /&gt;
What is execve actually doing?&lt;br /&gt;
 - we will be discussing this, several details, but basically it throws away&lt;br /&gt;
   everything that was there, replacing it with the code from the new process&lt;br /&gt;
     - some bits are preserved, but it is very limited&lt;br /&gt;
&lt;br /&gt;
Note that this fork/execve thing happens in a shell every time you run an *external* command.  Internal ones are just handled by the shell process.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
On a standard UNIX machine, there are many processes always running &amp;quot;in the background&amp;quot; providing services&lt;br /&gt;
 - these are referred to as daemons&lt;br /&gt;
   (not evil, more useful servants)&lt;br /&gt;
&lt;br /&gt;
For example, sshd is running on your virtual machines (the d is for daemon)&lt;br /&gt;
  - it is listening for incoming ssh connection requests&lt;br /&gt;
  - this is what lets you connect to your VM!&lt;br /&gt;
&lt;br /&gt;
processes are the basic unit of concurrency on UNIX systems&lt;br /&gt;
  - threads were later added as part of this, but at its heart&lt;br /&gt;
    UNIX just wants to deal with processes&lt;br /&gt;
      - process: something created by fork&lt;br /&gt;
&lt;br /&gt;
Now if you do strace on a modern Linux system, you won&amp;#039;t see &amp;quot;fork&amp;quot;, you&amp;#039;ll see &amp;quot;clone&amp;quot;&lt;br /&gt;
  - it is a more general system call, superset of fork&amp;#039;s functionality&lt;br /&gt;
&lt;br /&gt;
envp, environ - all refer to environment variables&lt;br /&gt;
 - key/value combinations&lt;br /&gt;
 - each is one string, with the first part being the key, then an =, then the value&lt;br /&gt;
 - passed in by execve, is there whenever a new program runs, given to it&lt;br /&gt;
   by the previous program that was running in that process (along with argv)&lt;br /&gt;
 - used to specify the process&amp;#039;s &amp;quot;environment&amp;quot;&lt;br /&gt;
    - whatever info might be relevant, can be almost anything&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that environment variables are copied&lt;br /&gt;
 - when you do a fork, child process has a copy of the parent&amp;#039;s environment variables (because they have a copy of all memory)&lt;br /&gt;
 - on execve, the new program has whatever the old program gave it as envp to execve&lt;br /&gt;
&lt;br /&gt;
So that means changes to environment variables are always local&lt;br /&gt;
 - there is no global state across processes for environment variables&lt;br /&gt;
&lt;br /&gt;
But if you define environment variables as part of your startup configuration,&lt;br /&gt;
all processes in your session will get the same environment variables so they can seem to be &amp;quot;global&amp;quot;, but they were just copied all along the way&lt;br /&gt;
  - unless someone in the middle decided to mess with them&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ones that we are using here:&lt;br /&gt;
  PATH: directories to search for program binaries&lt;br /&gt;
&lt;br /&gt;
&amp;quot;session&amp;quot; - a user&amp;#039;s session, starts when the log in and ends when they log out&lt;br /&gt;
 - configured by dot files:&lt;br /&gt;
    - .profile, .bash_profile   &amp;lt;--- note .profile is for all shells,&lt;br /&gt;
    - .bashrc, .bash_aliases    &amp;lt;--- rest start with bash because they are for&lt;br /&gt;
                                &amp;lt;--- bash!&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>