<?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_5</id>
	<title>Operating Systems 2021F 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_2021F_Lecture_5"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_5&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_5&amp;diff=23317&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on September 23, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec05-20210923.m4...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_5&amp;diff=23317&amp;oldid=prev"/>
		<updated>2021-09-23T16:26:14Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on September 23, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec05-20210923.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 23, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec05-20210923.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec05-20210923.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 5&lt;br /&gt;
---------&lt;br /&gt;
- update on Assignment 1 (almost there!)&lt;br /&gt;
- more on Tutorial 1 &amp;amp; 2 material&lt;br /&gt;
&lt;br /&gt;
Assignment 1&lt;br /&gt;
 - almost done! it is incomplete currently&lt;br /&gt;
    - adding more questions&lt;br /&gt;
    - current ones you can go ahead and answer, at most they&amp;#039;ll be renumbered&lt;br /&gt;
 - Due October 1st, by 11:59 PM&lt;br /&gt;
 - Template will be posted when complete, should be by tomorrow (end of today, but my end of today can be late)&lt;br /&gt;
&lt;br /&gt;
October 1 is also the due date for Tutorials 1 &amp;amp; 2&lt;br /&gt;
 - because what&amp;#039;s the point of having them due afterwards, since they are&lt;br /&gt;
   to help you with A1?&lt;br /&gt;
 - brightspace due date is a week after being released, but you can submit with no penalty until the assignment is due&lt;br /&gt;
    - you should try to hit the brightspace deadline to not get behind&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll hold your hand for the tutorials, the assignments are where you show you learned the stuff.&lt;br /&gt;
&lt;br /&gt;
You need to know enough assembly to answer the questions&lt;br /&gt;
 - same with everything else :-)&lt;br /&gt;
 - lots of material in OS, I have to guide you in what to learn,&lt;br /&gt;
   that&amp;#039;s what the tutorials and assignments are for&lt;br /&gt;
&lt;br /&gt;
I&amp;#039;m opening Tutorial 2 submissions after class&lt;br /&gt;
 - sorry, forgot to do that&lt;br /&gt;
&lt;br /&gt;
Do the tutorials first, then do the assignments&lt;br /&gt;
 - but don&amp;#039;t spend too much time trying to get the tutorials &amp;quot;perfect&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Most of these questions can be asked in the forums&lt;br /&gt;
 - try to limit it to pressing matters&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Tutorial 2&lt;br /&gt;
 - if you compile with &amp;quot;-z lazy&amp;quot;, regular ltrace will work with the binary&lt;br /&gt;
   (show calls to standard library functions&lt;br /&gt;
 - without this option, ltrace won&amp;#039;t show much&lt;br /&gt;
 - if you add &amp;#039;-x &amp;quot;*&amp;quot;&amp;#039;, you&amp;#039;ll get way too much&lt;br /&gt;
    - many function calls inside of the library&lt;br /&gt;
    - you can limit it in various ways, the * is for pattern matching&lt;br /&gt;
 - ltrace used to work on default binaries, but they were &amp;quot;hardened&amp;quot; to prevent certain attacks.  The hardening also broke default ltrace&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ltrace is for library calls&lt;br /&gt;
strace is for system calls&lt;br /&gt;
&lt;br /&gt;
Remember, library calls are function calls&lt;br /&gt;
 - code is in your process&amp;#039;s address space, you just didn&amp;#039;t write it&lt;br /&gt;
&lt;br /&gt;
System calls leave your process and go to the kernel&lt;br /&gt;
 - strace is almost always showing system calls that were made by library functions&lt;br /&gt;
 - you can&amp;#039;t make system calls in regular C code, it requires special&lt;br /&gt;
   assembly code (&amp;quot;syscall&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
command line arguments and environment variables&lt;br /&gt;
 - data that is given to a process when a new program is run with&lt;br /&gt;
   the execve system call&lt;br /&gt;
 - execvp is a library call that later makes the execve system call&lt;br /&gt;
 - this data is in the address space of the process, just like other variables&lt;br /&gt;
    - but they don&amp;#039;t come from the executable file&lt;br /&gt;
&lt;br /&gt;
command line argument &amp;amp; environment variables can be passed to main&lt;br /&gt;
 - but who passes it to main?&lt;br /&gt;
 - directly, the kernel via the execve system call that loaded the program&lt;br /&gt;
 - indirectly, the previous code that made the execve system call&lt;br /&gt;
&lt;br /&gt;
(Chat history is all on brightspace, along with the lecture video&lt;br /&gt;
  - just go to Zoom/class lectures, cloud recordings)&lt;br /&gt;
&lt;br /&gt;
I don&amp;#039;t post the chat on my wiki because it has your names in it&lt;br /&gt;
 - I don&amp;#039;t want that to be public&lt;br /&gt;
&lt;br /&gt;
What sort of data structures are environment variables &amp;amp; command line arguments stored in?&lt;br /&gt;
 - arrays of strings&lt;br /&gt;
&lt;br /&gt;
But there&amp;#039;s one problem.  These arrays can be arbitrarily sized.  And we don&amp;#039;t have a count of how many entries are in them.  (well, we do for arguments, but not for environment variable)&lt;br /&gt;
 - note that the execve system call doesn&amp;#039;t have a length parameter for&lt;br /&gt;
   the argv array or the envp array&lt;br /&gt;
 - array length is like strings in C, they are NULL-terminated&lt;br /&gt;
&lt;br /&gt;
Question: what is actually stored in the environment variable array?  How is it organized (beyond being an array of strings)?  Note that it associates names with values.&lt;br /&gt;
&lt;br /&gt;
So let&amp;#039;s start talking about system calls&lt;br /&gt;
 - you all know read &amp;amp; write, but to review&lt;br /&gt;
    - read &amp;amp; write takes a file descriptor, a buffer, and a count, and returns a count&lt;br /&gt;
 - what&amp;#039;s the buffer? &amp;lt;-- just memory in the process&lt;br /&gt;
 - what is the file descriptor argument?&lt;br /&gt;
&lt;br /&gt;
A file descriptor identifies a file, but it is just a number&lt;br /&gt;
 - the number is returned by the open system call&lt;br /&gt;
    - so, it corresponds to the file passed in to open&lt;br /&gt;
&lt;br /&gt;
The numbers start at 0 and go up&lt;br /&gt;
&lt;br /&gt;
who interprets file descriptors?&lt;br /&gt;
 - they are for the kernel&lt;br /&gt;
 - they are per process, every process has an array of open files&lt;br /&gt;
    - the file descriptor is an index into that array in the kernel&lt;br /&gt;
 - when I say an array of open files, we don&amp;#039;t know yet what&lt;br /&gt;
   that is an array of&lt;br /&gt;
     (but it is a complex struct)&lt;br /&gt;
&lt;br /&gt;
Can I see what files are currently open by a process from the shell?&lt;br /&gt;
 - YES&lt;br /&gt;
&lt;br /&gt;
The kernel has a lot of interesting information, and it exposes most of this information through special filesystems&lt;br /&gt;
 - /proc and /sys&lt;br /&gt;
 - example: info on current processes is in /proc/&amp;lt;PID&amp;gt;&lt;br /&gt;
    - directory with many files and directories of info&lt;br /&gt;
 - when you run ps, it is just looking through /proc&lt;br /&gt;
&lt;br /&gt;
Question: are the files in /proc &amp;quot;real&amp;quot;?&lt;br /&gt;
 - are they on disk taking up space?&lt;br /&gt;
 - NO, they are representations of kernel data structures&lt;br /&gt;
&lt;br /&gt;
Are argv and envp kernel data structures?&lt;br /&gt;
 - NO&lt;br /&gt;
 - they are part of the process, they are process-level data structures&lt;br /&gt;
    - kernel can see them, because the kernel can see everything&lt;br /&gt;
 - kernel data structures cannot be seen or directly manipulated&lt;br /&gt;
   by a process&lt;br /&gt;
&lt;br /&gt;
We can&amp;#039;t find the address of a file, a file descriptor is just a small number&lt;br /&gt;
 - they are NOT pointers&lt;br /&gt;
 - they are indices into an array that the process cannot directly access&lt;br /&gt;
    - an array of file structs that belong to the kernel,&lt;br /&gt;
      outside the process&amp;#039;s address space&lt;br /&gt;
    - (the process cannot get a pointer to it)&lt;br /&gt;
&lt;br /&gt;
(When you are in the kernel, you have to manipulate pointers to open file data structures.  But regular processes can&amp;#039;t, they just have file descriptors that are passed to system calls, e.g., read, write, close)&lt;br /&gt;
&lt;br /&gt;
So what is close?&lt;br /&gt;
 - it is request to destroy/free the file struct associated with the open file&lt;br /&gt;
   - to prevent resource usage leaks&lt;br /&gt;
&lt;br /&gt;
C library has file pointers&lt;br /&gt;
 - these are wrappers around file descriptors&lt;br /&gt;
 - nothing to do with kernel-level file data structures&lt;br /&gt;
&lt;br /&gt;
How else can you release the resources associated with an open file, other than close?&lt;br /&gt;
 - terminate the process :-)&lt;br /&gt;
&lt;br /&gt;
So what about standard in, out, and error?&lt;br /&gt;
 - they are file descriptors 0, 1, and 2 respectively&lt;br /&gt;
&lt;br /&gt;
Does the kernel treat file descriptors 0, 1, and 2 differently?&lt;br /&gt;
 - by default, printf writes to 1&lt;br /&gt;
 - by default, scanf reads from 0&lt;br /&gt;
 - and errors are directed to 2&lt;br /&gt;
&lt;br /&gt;
The kernel treats fd 0, 1, and 2 exactly like any other open file&lt;br /&gt;
 - standard in, out, and error are pure conventions for how those&lt;br /&gt;
   file descriptors are used&lt;br /&gt;
 - userspace convention, kernel has nothing to do with it and&lt;br /&gt;
   in fact doesn&amp;#039;t care&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>