<?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_3</id>
	<title>Operating Systems 2021F Lecture 3 - 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_3"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_3&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_3&amp;diff=23279&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on September 16, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec03-20210916.m4...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_3&amp;diff=23279&amp;oldid=prev"/>
		<updated>2021-09-16T18:27:30Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on September 16, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec03-20210916.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 16, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec03-20210916.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec03-20210916.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 3&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Today we&amp;#039;re talking about shells&lt;br /&gt;
&lt;br /&gt;
And I&amp;#039;m going to try making a drawing here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
     ---------------------&lt;br /&gt;
     |shell| vi | firefox|   &amp;lt;---  running programs (processes)&lt;br /&gt;
     |-------------------+&lt;br /&gt;
      |------------------+&lt;br /&gt;
      |  kernel (Linux)	 |&lt;br /&gt;
      |			 |    &amp;lt;--- drivers go in here&lt;br /&gt;
      +------------------+|&lt;br /&gt;
      |    hardware	  |   &amp;lt;--- firmware goes here, but loaded by kernel&lt;br /&gt;
      +------------------/-        (more to this story)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The shell is just another running program (process)&lt;br /&gt;
&lt;br /&gt;
Drivers are code that is added to the kernel so it can access specific devices&lt;br /&gt;
&lt;br /&gt;
Today we&amp;#039;re focused on the shell, because that&amp;#039;s how you&amp;#039;re going to interact with the kernel (to start with), and because it gives you a nice view of what the kernel is doing&lt;br /&gt;
&lt;br /&gt;
(sorry things have been confusing so far, will get to firmer ground soon)&lt;br /&gt;
&lt;br /&gt;
When you ssh to openstack, openstack only allows connections from the Carleton network.  So you have to get onto the carleton network.&lt;br /&gt;
&lt;br /&gt;
Two ways to do this:&lt;br /&gt;
 - VPN to Carleton&lt;br /&gt;
 - ssh to Carleton (e.g., access.scs.carleton.ca)&lt;br /&gt;
&lt;br /&gt;
If you ssh to Carleton, you can use that ssh connection to &amp;quot;tunnel&amp;quot; other&lt;br /&gt;
connections.  That&amp;#039;s what the -L is for&lt;br /&gt;
&lt;br /&gt;
If you VPN to Carleton, ALL of your network traffic goes through the Carleton network.&lt;br /&gt;
 - not so good if you&amp;#039;re wanting to stream video at the same time,&lt;br /&gt;
   VPNs aren&amp;#039;t the fastest&lt;br /&gt;
&lt;br /&gt;
SSH method&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
So to connect to access first, you&lt;br /&gt;
  ssh -L &amp;lt;local port&amp;gt;:&amp;lt;openstack floating IP address&amp;gt;:22 \&lt;br /&gt;
     &amp;lt;mycarletonone username&amp;gt;@access.scs.carleton.ca&lt;br /&gt;
&lt;br /&gt;
type in your password, then&lt;br /&gt;
&lt;br /&gt;
  ssh -p &amp;lt;local port&amp;gt; student@localhost&lt;br /&gt;
&lt;br /&gt;
and you&amp;#039;re on your openstack instance&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
VPN method&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
* connect to the Carleton VPN using Cisco Anyconnect or&lt;br /&gt;
  openconnect (linux)&lt;br /&gt;
&lt;br /&gt;
* then,&lt;br /&gt;
&lt;br /&gt;
  ssh student@&amp;lt;openstack floating IP address&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Just remember ALL your network traffic is going through Carleton while you are VPN&amp;#039;d.  So don&amp;#039;t watch so much youtube :-)  (They log things)&lt;br /&gt;
&lt;br /&gt;
So why does this all matter?&lt;br /&gt;
 - this is actually how things used to work&lt;br /&gt;
 - you&amp;#039;d login to one machine, then remote shell to other machines to do&lt;br /&gt;
   work&lt;br /&gt;
 - ssh stands for &amp;quot;secure shell&amp;quot;, and is a direct descendent of&lt;br /&gt;
   rsh (remote shell)&lt;br /&gt;
     - note the repeated uses of the word &amp;quot;shell&amp;quot;&lt;br /&gt;
     - this is the original interface for UNIX-like systems&lt;br /&gt;
     - GUIs are a MUCH later development&lt;br /&gt;
&lt;br /&gt;
What is SSH actually doing?&lt;br /&gt;
 - it runs a program on the remote systems (another ssh process)&lt;br /&gt;
   - the two ssh processes set up a bidirectional network stream&lt;br /&gt;
 - the remote ssh process starts a shell&lt;br /&gt;
 - then the local ssh forwards keyboard input to the remote ssh,&lt;br /&gt;
   it passes it to the shell&lt;br /&gt;
 - the remote shell outputs data, it sends it to the remote ssh&lt;br /&gt;
   and it forwards it to the local ssh to display&lt;br /&gt;
&lt;br /&gt;
You can use any local port &amp;gt;1023 generally, 1023 and less are reserved&lt;br /&gt;
 - I can talk more about networking later, but just trying to get the basics for now&lt;br /&gt;
&lt;br /&gt;
Note that port 22 is reserved for ssh, so if you ssh localhost or ssh -p 22 localhost, it is the same thing, and you&amp;#039;re logging in to your own computer&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m going to stop talking about SSH now, but I&amp;#039;m happy to discuss further in the forums or in office hours (or later lectures)&lt;br /&gt;
&lt;br /&gt;
But what is interesting about what we&amp;#039;ve been talking about, is it shows what a shell is&lt;br /&gt;
 - character stream in&lt;br /&gt;
 - character stream out&lt;br /&gt;
 - does something in between&lt;br /&gt;
&lt;br /&gt;
In general, this is known as a &amp;quot;read eval print&amp;quot; loop&lt;br /&gt;
 - comes from the LISP world&lt;br /&gt;
 - but is really the same thing here&lt;br /&gt;
&lt;br /&gt;
LISP is a programming language&lt;br /&gt;
 - should be covered in 3007&lt;br /&gt;
 - (+ 2 2) &amp;lt;-- this is what LISP looks like (e.g., Scheme)&lt;br /&gt;
&lt;br /&gt;
(If you want to learn more about LISP, look up LISP machines&lt;br /&gt;
and symbolics.  BTW symbolics.com was the first .com address on the Internet)&lt;br /&gt;
&lt;br /&gt;
Going back to a REPL&lt;br /&gt;
 - primitive way of interacting with a computer&lt;br /&gt;
 - but MUCH better than what came before&lt;br /&gt;
&lt;br /&gt;
Before you&amp;#039;d do things as a batch&lt;br /&gt;
 - give lots of input (often as a deck of punch cards)&lt;br /&gt;
 - WAIT&lt;br /&gt;
 - get lots of output&lt;br /&gt;
 ... ponder the output ...&lt;br /&gt;
 repeat&lt;br /&gt;
&lt;br /&gt;
REPLs are interactive&lt;br /&gt;
 - you type something, and generally something happens in return almost&lt;br /&gt;
   immediately&lt;br /&gt;
&lt;br /&gt;
REPLs are synchronous&lt;br /&gt;
 - you have to wait for one input to be evaluated before giving new input&lt;br /&gt;
&lt;br /&gt;
but there are ways to do asynchronous things in a REPL&lt;br /&gt;
&lt;br /&gt;
The shell IS a REPL, but one designed for interacting with the operating system&lt;br /&gt;
 - its purpose is to run other programs!&lt;br /&gt;
&lt;br /&gt;
The purpose of the default prompt of the shell is so you know you&amp;#039;re talking to the shell&lt;br /&gt;
 - you can run all kinds of other programs&lt;br /&gt;
 - often not clear who you are talking to!&lt;br /&gt;
&lt;br /&gt;
To help you manage running other programs, standard shells give special meaning to certain control key sequences, and most programs don&amp;#039;t override it (but they can)&lt;br /&gt;
 - Ctrl-C: interrupt&lt;br /&gt;
 - Ctrl-Z: suspend/stop&lt;br /&gt;
 - Ctrl-D: end of file&lt;br /&gt;
&lt;br /&gt;
If you enable emacs bindings (which is default on the class vm), you can also do some line editing&lt;br /&gt;
 - Ctrl-A: start of line&lt;br /&gt;
 - Ctrl-E: end of line&lt;br /&gt;
 - Ctrl-K: kill (delete to kill buffer)   &amp;lt;-- cut&lt;br /&gt;
 - Ctrl-Y: Yank (paste from kill buffer)  &amp;lt;-- paste&lt;br /&gt;
&lt;br /&gt;
Also, on modern shells you have access to command history via cursor keys (up and down)&lt;br /&gt;
&lt;br /&gt;
They also support incremental search&lt;br /&gt;
 - Ctrl-S: forward search&lt;br /&gt;
 - Ctrl-R: reverse search&lt;br /&gt;
 - these are also emacs commands&lt;br /&gt;
   - to cancel, hit Ctrl-G&lt;br /&gt;
&lt;br /&gt;
All of these features are supported by the GNU readline library&lt;br /&gt;
 - used by bash and many other programs&lt;br /&gt;
 - so all have the same interface&lt;br /&gt;
 - and also use the same customizations file, so if you have a way&lt;br /&gt;
   you like to interact with command lines, create your config file&lt;br /&gt;
   and many programs will respect it&lt;br /&gt;
&lt;br /&gt;
If we go back in time, often you&amp;#039;d want to pause output coming your way&lt;br /&gt;
 - especially if it was an out of control command&lt;br /&gt;
 - ctrl-S pauses, ctrl-q unpauses&lt;br /&gt;
   - this is &amp;quot;flow control&amp;quot;&lt;br /&gt;
 - and yes, Ctrl-S also is for search, depends on context&lt;br /&gt;
   - basically, are you editing a command line or are you interacting&lt;br /&gt;
     with another program&lt;br /&gt;
&lt;br /&gt;
Why am I telling you all this?&lt;br /&gt;
 - REPLs like the shell offer a sophisticated interface with many&lt;br /&gt;
   nice features to make them efficient to use&lt;br /&gt;
 - but, these features aren&amp;#039;t very discoverable&lt;br /&gt;
    - you have to see them in use or read about them&lt;br /&gt;
 - Not great for newbies, but as you gain experience with them,&lt;br /&gt;
   it pays of in productivity gains&lt;br /&gt;
&lt;br /&gt;
If your terminal gets messed up, you can type &amp;quot;clear&amp;quot; to clear it&lt;br /&gt;
 - and if things are acting really weird, type &amp;quot;reset&amp;quot; to get it back to a sane state&lt;br /&gt;
&lt;br /&gt;
Shells run in terminals&lt;br /&gt;
 - emulate the first interfaces&lt;br /&gt;
 - provide a text &amp;quot;screen&amp;quot; and a &amp;quot;keyboard&amp;quot;&lt;br /&gt;
    - used to be a physical device, now virtual generally in a GUI&lt;br /&gt;
&lt;br /&gt;
You need to reset your terminal if you&amp;#039;ve viewed a file which isn&amp;#039;t pure text directly&lt;br /&gt;
&lt;br /&gt;
Because, how does cursor positioning work in a terminal?&lt;br /&gt;
  - special character sequences&lt;br /&gt;
&lt;br /&gt;
If something isn&amp;#039;t pure text, it has embedded special character sequences&lt;br /&gt;
 (random ones)&lt;br /&gt;
&lt;br /&gt;
Your history of commands is stored in .bash_history (for bash)&lt;br /&gt;
 - erase it if you want to delete your command history&lt;br /&gt;
&lt;br /&gt;
(there are lots of other ways of interacting with the shell, I&amp;#039;m going to stop here)&lt;br /&gt;
&lt;br /&gt;
Lots of interesting files in your main home directory.  By default ls doesn&amp;#039;t show you them all.&lt;br /&gt;
 - &amp;quot;ls -a&amp;quot; to see all files&lt;br /&gt;
 - by default, any file that starts with a period is considered a hidden&lt;br /&gt;
   file and isn&amp;#039;t shown&lt;br /&gt;
    - this is just by convention, no special permissions/restrictions&lt;br /&gt;
&lt;br /&gt;
When we talk about dot files, we are talking about files that start with a period, they are often used to customize how things work&lt;br /&gt;
 - if you want to change how things work when you log in,&lt;br /&gt;
   you have to mess with the dot files in your home directory&lt;br /&gt;
&lt;br /&gt;
By default, every user on UNIX has a home directory&lt;br /&gt;
 - where they are put when they log in&lt;br /&gt;
 - represented by &amp;quot;~&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
pwd tells me the directory I&amp;#039;m currently in&lt;br /&gt;
&lt;br /&gt;
note that the shell is always in a directory&lt;br /&gt;
 - that&amp;#039;s the other job of the shell - interact and manipulate the filesystem&lt;br /&gt;
    - but it does so mostly by running programs&lt;br /&gt;
&lt;br /&gt;
If you look in ~/.bash_aliases  (/home/student/.bash_aliases) you&amp;#039;ll see&lt;br /&gt;
the code that defines the scs-backup command&lt;br /&gt;
 - yes the shell is generally programmable&lt;br /&gt;
 - so you can modify/extend the interface as you wish&lt;br /&gt;
&lt;br /&gt;
When you type a command at a shell, it can either be an internal or external command&lt;br /&gt;
 - internal command: bash understands it&lt;br /&gt;
 - external command: bash runs another program&lt;br /&gt;
&lt;br /&gt;
ls is an external command, as is less, top, etc&lt;br /&gt;
&lt;br /&gt;
which tells you where a command lives&lt;br /&gt;
 - if which says nothing, it is built in&lt;br /&gt;
&lt;br /&gt;
So you see the shell interface is really one for running other programs&lt;br /&gt;
 - but it is a programming language as well, just one optimized for&lt;br /&gt;
   running other programs, e.g. &amp;quot;shell scripts&amp;quot;&lt;br /&gt;
&lt;br /&gt;
If you are curious about a command/program, try&lt;br /&gt;
 - man &amp;lt;command&amp;gt;  &amp;lt;-- full docs&lt;br /&gt;
 - whatis &amp;lt;command&amp;gt; &amp;lt;-- quick summary&lt;br /&gt;
 - &amp;lt;command&amp;gt; --help or -h&lt;br /&gt;
    returns program&amp;#039;s help info&lt;br /&gt;
&lt;br /&gt;
You&amp;#039;re not going to learn everything about the shell in this course, or UNIX&lt;br /&gt;
 - SO rich&lt;br /&gt;
 - I learn new commands all the time (just learned about whatis today!)&lt;br /&gt;
 - It will be clear what I want you to know for this class&lt;br /&gt;
   - but learning more will make your life better&lt;br /&gt;
   - learn what you need to make things easier for yourself&lt;br /&gt;
&lt;br /&gt;
I don&amp;#039;t teach to tests&lt;br /&gt;
 - very limiting&lt;br /&gt;
 - and not so effective&lt;br /&gt;
&lt;br /&gt;
I cover a lot, and then expect you to know a subset&lt;br /&gt;
 - that subset is what is on the assignments&lt;br /&gt;
&lt;br /&gt;
If you teach me something on the test and it works, that&amp;#039;s great!&lt;br /&gt;
 - but mostly you&amp;#039;ll be explaining things, so that won&amp;#039;t come up so much&lt;br /&gt;
&lt;br /&gt;
So what you should be asking yourself is this&lt;br /&gt;
 - if I&amp;#039;m running programs from the shell, how are those programs related to or connected to each other?&lt;br /&gt;
 - which one is in control?  Can more than one be running?&lt;br /&gt;
 - are they all running at the same time?&lt;br /&gt;
 - can they mess with each other?&lt;br /&gt;
&lt;br /&gt;
At least, those are the questions I want you to focus on :-)&lt;br /&gt;
&lt;br /&gt;
A1 will come out shortly after T2, so by early next week&lt;br /&gt;
&lt;br /&gt;
The really cool part about the shell is that you don&amp;#039;t have to just run one program at a time&lt;br /&gt;
 - you can combine many programs together to accomplish a task&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The shell is just another program running in a process&lt;br /&gt;
 - see csimpleshell.c, it is a basic shell&lt;br /&gt;
&lt;br /&gt;
consider this command&lt;br /&gt;
  du | sort -n -r | head&lt;br /&gt;
&lt;br /&gt;
These are three separate programs&lt;br /&gt;
 - How is the output of one being passed to the other?&lt;br /&gt;
 - When are they all running?  one at a time, all at the same time?&lt;br /&gt;
   - if at the same time, how do they coordinate their behavior?&lt;br /&gt;
 - yes the answer is | is a pipe, but what is a pipe actually doing?&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll discuss this next time.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>