<?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_7</id>
	<title>Operating Systems 2022F Lecture 7 - 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_7"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_7&amp;action=history"/>
	<updated>2026-04-05T22:41:23Z</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_7&amp;diff=24082&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on September 29, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&gt;Zoom meeting-&gt;Cloud Recordings tab)  ==Notes==  &lt;pre&gt; Lecture 7 ---------  Covered A1 solutions, walked throug...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_7&amp;diff=24082&amp;oldid=prev"/>
		<updated>2022-09-29T20:21:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on September 29, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.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 7 ---------  Covered A1 solutions, walked throug...&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 29, 2022 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec07-20220929.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 7&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Covered A1 solutions, walked through gdb a bit&lt;br /&gt;
&lt;br /&gt;
File descriptors&lt;br /&gt;
----------------&lt;br /&gt;
&lt;br /&gt;
When you run &amp;quot;printf&amp;quot;, what is that function doing?&lt;br /&gt;
 - it is writing to &amp;quot;standard out&amp;quot;&lt;br /&gt;
 - stdin, stdout, stderr are C concepts, supported on all platforms&lt;br /&gt;
   C runs on&lt;br /&gt;
 - but what is stdin, stdout, stderr on UNIX?&lt;br /&gt;
   (FILE * is not a thing on UNIX, it is a C thing)&lt;br /&gt;
 - but on UNIX, we have file descriptors&lt;br /&gt;
    - small numbers associated with open files&lt;br /&gt;
&lt;br /&gt;
the system call open returns a file descriptor, and open, read, write, close&lt;br /&gt;
all take a file descriptor as an argument&lt;br /&gt;
&lt;br /&gt;
So what is stdin, stdout, and stderr in terms of file descriptors?&lt;br /&gt;
&lt;br /&gt;
0 = stdin&lt;br /&gt;
1 = stdout&lt;br /&gt;
2 = stderr&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s it&lt;br /&gt;
&lt;br /&gt;
Note that a file descriptor is a reference to an OPEN file.  So someone has to open it.&lt;br /&gt;
&lt;br /&gt;
When a process starts on UNIX, by convention file descriptors 0, 1, and 2 are valid.  0 can be read from, and 1 and 2 can be written to.  What they point to...can be any file!&lt;br /&gt;
&lt;br /&gt;
(So what this means is that before you do an execve you make sure file descriptors 0, 1, and 2 point to where you want them for the program you&amp;#039;re exec&amp;#039;ing)&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t do anything, the new program will just get the same file descriptors that you had (memory is wiped but files that were open stay open)&lt;br /&gt;
&lt;br /&gt;
There is a maximum, it is defined by the kernel&lt;br /&gt;
&lt;br /&gt;
Files are accessed through file descriptors&lt;br /&gt;
Most other I/O is also accessed through file descriptors, they just are&lt;br /&gt;
file descriptors referring to &amp;quot;special files&amp;quot; (i.e., device files)&lt;br /&gt;
&lt;br /&gt;
/dev/tty, /dev/pts/0, /dev/null, etc are all special files&lt;br /&gt;
&lt;br /&gt;
Normally open just opens the file on the next available file descriptor.  But you can use dup2 to copy it to another file descriptor (like 0, 1, or 2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>