<?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_2020W_Lecture_6</id>
	<title>Operating Systems 2020W 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_2020W_Lecture_6"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_6&amp;action=history"/>
	<updated>2026-06-02T22:24:21Z</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_2020W_Lecture_6&amp;diff=22571&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  The video for the lecture given on January 24, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec06-20200124.m4v is now available]...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_6&amp;diff=22571&amp;oldid=prev"/>
		<updated>2020-03-20T02:32:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  The video for the lecture given on January 24, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec06-20200124.m4v is now available]...&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;
The video for the lecture given on January 24, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec06-20200124.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
===Topics===&lt;br /&gt;
* highlight relevant chapters from textbook&lt;br /&gt;
* gdb&lt;br /&gt;
** [https://sourceware.org/gdb/onlinedocs/gdb/Forks.html follow-fork-mode] (parent, child)&lt;br /&gt;
** detach-on-fork (on, off)&lt;br /&gt;
** follow-exec-mode (new, same)&lt;br /&gt;
** [https://sourceware.org/gdb/onlinedocs/gdb/Set-Catchpoints.html catch] exec&lt;br /&gt;
** catch syscall&lt;br /&gt;
** [https://sourceware.org/gdb/onlinedocs/gdb/TUI-Commands.html#TUI-Commands layout regs]&lt;br /&gt;
** layout split&lt;br /&gt;
** layout src&lt;br /&gt;
** layout asm&lt;br /&gt;
** [https://sourceware.org/gdb/onlinedocs/gdb/Data.html print]&lt;br /&gt;
** explore&lt;br /&gt;
&lt;br /&gt;
===Textbook chapters===&lt;br /&gt;
&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-intro.pdf&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-api.pdf&lt;br /&gt;
  http://pages.cs.wisc.edu/~remzi/OSTEP/vm-intro.pdf&lt;br /&gt;
&lt;br /&gt;
===In Class===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 6&lt;br /&gt;
---------&lt;br /&gt;
&lt;br /&gt;
Running gdb&lt;br /&gt;
 - problem: want to run gdb in a separate window from program we are debugging&lt;br /&gt;
 - solution: run two terminals, use gdb -p &amp;lt;PID&amp;gt; to attach to process&lt;br /&gt;
   (or attach command inside gdb)&lt;br /&gt;
&lt;br /&gt;
 - problem: won&amp;#039;t work in standard configuration, can only run gdb on child&lt;br /&gt;
   processes&lt;br /&gt;
 - solution:&lt;br /&gt;
    sudo su -  (to become root)&lt;br /&gt;
    echo 0 &amp;gt; /proc/sys/kernel/yama/ptrace_scope    &amp;lt;-- lost on reboot&lt;br /&gt;
&lt;br /&gt;
   or&lt;br /&gt;
    sudo nano /etc/sysctl.d/10-ptrace.conf&lt;br /&gt;
    change &amp;quot;kernel.yama.ptrace_scope = 0&amp;quot;          &amp;lt;-- persistent&lt;br /&gt;
&lt;br /&gt;
 - problem: how do I debug the child process?  by default it debugs only&lt;br /&gt;
   the parent&lt;br /&gt;
 - solution: &amp;quot;set follow-fork-mode child&amp;quot; in gdb&lt;br /&gt;
&lt;br /&gt;
 - problem: I want to see what system calls a process is making&lt;br /&gt;
 - solution: catch syscall&lt;br /&gt;
        also can specify specific syscalls to stop on&lt;br /&gt;
&lt;br /&gt;
 - problem: I want to follow an execve (change the program that is being&lt;br /&gt;
    followed)&lt;br /&gt;
 - solution: set follow-exec-mode new  (rather than same)&lt;br /&gt;
&lt;br /&gt;
 - problem: I set a breakpoint for a function, how did we get to that&lt;br /&gt;
   breakpoint?&lt;br /&gt;
 - solution: bt (backtrace) to see the call stack&lt;br /&gt;
 &lt;br /&gt;
Why am I showing you all this stuff with gdb?&lt;br /&gt;
 - I want you to understand how the programs we cover in the course run,&lt;br /&gt;
   particularly the system calls they run&lt;br /&gt;
 - strace can help with this, but sometimes you need to see things go down&lt;br /&gt;
   one line at a time.  Hence gdb.&lt;br /&gt;
&lt;br /&gt;
Note that gdb uses a special system call to control other processes: ptrace&lt;br /&gt;
 - ptrace isn&amp;#039;t always the most reliable&lt;br /&gt;
 - you don&amp;#039;t want to ptrace processes in production; there are other tools&lt;br /&gt;
   which we will cover later in the term&lt;br /&gt;
&lt;br /&gt;
*Note* that if you want strace to follow forks, you need to specify the -f option&lt;br /&gt;
&lt;br /&gt;
Differences of fork versus execve&lt;br /&gt;
 - with fork&lt;br /&gt;
   - you start with one process (one PID)&lt;br /&gt;
   - you end with two processes: parent (with original PID) and&lt;br /&gt;
     child (with new PID)&lt;br /&gt;
   - parent and child are identical right after fork except for return&lt;br /&gt;
     value of fork().  Hence they are running the same program binary&lt;br /&gt;
 - with execve&lt;br /&gt;
   - only one process at start and end&lt;br /&gt;
   - before, running program that makes the execve call&lt;br /&gt;
   - after, running new program *specified* by the execve call&lt;br /&gt;
   - note that code after an execve call NEVER RUNS...unless&lt;br /&gt;
     execve fails (e.g., you tried to run a program and that file&lt;br /&gt;
     doesn&amp;#039;t exist or you don&amp;#039;t have permission to run it)&lt;br /&gt;
&lt;br /&gt;
In a normal shell, execve is run in a child (so after a fork)&lt;br /&gt;
  - otherwise the shell would terminate&lt;br /&gt;
&lt;br /&gt;
/proc and /sys&lt;br /&gt;
 - direct interfaces into kernel state&lt;br /&gt;
 - provide a file interface because, what would be better?&lt;br /&gt;
    - if you made a system call to get these, how would you have&lt;br /&gt;
      so many options?  You&amp;#039;d have to pass in magic numbers or strings&lt;br /&gt;
    - if you&amp;#039;re passing in strings, why not make them filenames&lt;br /&gt;
      - then you get a hierarchy of strings!&lt;br /&gt;
 - big idea: a filesystem is just a mapping of filenames to data,&lt;br /&gt;
   doesn&amp;#039;t have to correspond to &amp;quot;real&amp;quot; files (i.e., files stored on disk)&lt;br /&gt;
   - really, a file is just something that can be used with the&lt;br /&gt;
     filesystem API (open, read, write, close, etc)&lt;br /&gt;
&lt;br /&gt;
 - view of processes in /proc is mostly read-only&lt;br /&gt;
    - can&amp;#039;t kill a process by deleting files in /proc&lt;br /&gt;
    - but this is just a historical artifact of us already having a way&lt;br /&gt;
      of killing processes (with signals)&lt;br /&gt;
&lt;br /&gt;
Note that /etc is system configuration stored in persistent files&lt;br /&gt;
 - preserved across reboots&lt;br /&gt;
&lt;br /&gt;
Data in /proc and /sys is ephemeral&lt;br /&gt;
 - destroyed when system is rebooted&lt;br /&gt;
 - just reflects state of current kernel&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>