Answers.Body: <p>Implementing a whole OS may not be the best approach if you want your students to learn operating system concepts. This is specially true if your students are not proficient in C and Assembly, since major parts like booting, context switching and virtual memory need to be coded in Assembly. This might be daunting for students that have experience only with Python.  </p>
  
  <p>An alternative approach is presented in <a href="http://csapp.cs.cmu.edu/" rel="noreferrer">Computer Systems: A programmers perspective</a>. It is a very in depth book, but instead of implementing everything the authors decided to study the System Calls in the POSIX specification as a way to illustrate Operating System Concepts. IMHO it maintains a very good balance between the abstract concepts and their concrete implementations. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T14:45:23.763Z
Answers.Text: I generally agree, but also note that a microkernel is amazingly small.
Answers.UserDisplayName: Buffy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T03:42:08.510Z
Answers.Text: Some are, some aren't :-) IIRC the Mach "microkernel" was bigger than the BSD/OS "macrokernel" as we would configure it for a fairly typical server. Wish I could remember the actual numbers, but it's been like 20 years…
Answers.UserDisplayName: dlu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T14:33:06.507Z
Answers.LastActivityDate: 2019-03-12T14:33:06.507Z
Answers.UserDisplayName: igordsm
Answers.Body: <p>You might consider using <a href="https://github.com/mit-pdos/xv6-public" rel="nofollow noreferrer">MIT's xv6</a> which they describe as "xv6 is a reimplementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is implemented for a modern x86-based multiprocessor using ANSI C." It can be run in a VM.</p>
  
  <p>Phillip Opperman has a very accessible set of blog posts, <a href="https://os.phil-opp.com" rel="nofollow noreferrer">Writing an OS in Rust</a>, it's in it's "2nd edition." The parts on writing the assembler to set up the machine (x86 as well) are particularly good.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T03:33:31.890Z
Answers.LastActivityDate: 2019-03-21T03:33:31.890Z
Answers.UserDisplayName: dlu
Answers.Body: <p>First I would recommend to start by using an operating system, such as Gnu (<a href="https://www.debian.org/" rel="nofollow noreferrer">Debian</a> etc), but any Unix will do. Most people have not used an OS: Most people just run applications, but don't interact with the OS. Microsoft's Windows, does not provide anything much to interact with (a file manager, and some config tools). It is mostly just a platform to write stand-alone applications.</p>
  <p>Implementing, threading, memory management, etc. without having used them, will be a very abstract activity. Pupils will see the complexity, without seeing the use.</p>
  <p>Therefore, do this after
  writing non-kernel parts of the OS. e.g. re-implement <code>cat</code>, <code>ls</code>, <code>grep</code>, etc.  in python.
  (In first year of Uni we did this in C. But I thing that python will be easier, and nothing will be lost.)</p>
  <p>You could even implement a shell, and/or play with <code>exec</code> and <code>fork</code>. e.g.</p>
  <pre><code>#!/usr/bin/python3
  
  import os
  stdout_id=1
  
  pipe_out,pipe_in = os.pipe()
  print (&quot;pipe is: &quot;,(pipe_in,pipe_out))
  
  pid=os.fork()
  print(&quot;forked&quot;)
  
  if pid&lt;0:
      print (&quot;fork error&quot;)
      exit()
  elif pid == 0:
      print (&quot;I am child:&quot;, str(os.getpid()))
      os.close(pipe_out)
      del pipe_out
      os.write(pipe_in,b&quot;hello1&quot;)
      #pipe=os.fdopen(pipe_in,&quot;w&quot;)
      #pipe.write(&quot;hello2&quot;)
      #os.write(pipe_in,&quot;hello3&quot;)
      #exit()
      #pipe.flush()
      #os.write(pipe_in,b&quot;world&quot;)
      #os.dup2(pipe_in,stdout_id)
      #os.execvp(&quot;ls&quot;,(&quot;ls&quot;,&quot;-l&quot;))
      print(&quot;child here again&quot;)
  else:
      print (&quot;I am parent:&quot;, str(os.getpid()))
      print (&quot;parent: child's pid=&quot;+str(pid))
      os.close(pipe_in)
      del pipe_in
      pipe=os.fdopen(pipe_out,&quot;r&quot;)
      for l in pipe:
          print(&quot;parent recieved: &quot;, l )
  
  print( &quot;done: &quot;+str(os.getpid()))
  </code></pre>
  <p>You can play with this code, by selectively removing <code>#</code>s.
  This will probably not run on Microsoft's Windows (It may in WSL).</p>
  <p>“are there any kind of emulators or tools that could help…?”</p>
  <p>If you don't have some sort of Unix on you computer (Gnu/Linux, BSD, UNIX, MacOS, WSL), then you can install Gnu/Linux inside Virtual Box.</p>
  <h1>On writing the kernel</h1>
  <p>Do this last. Choose a good architecture (x86 is a mess, ARM is easier). The raspberry-pi is a cheep (≈£30 + box + power + SD card) computer that uses the ARM CPU. You will also have to do parts of the kernel in assembler: The dispatcher (part of the thread scheduler), and parts of the Memory Manager, can not be done in C.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T03:49:06.093Z
Answers.Text: I'm with you on the "x86 in a mess" front, but it is widely enough used that there is a wealth of material and resources that use it as their example. Personally I'd be inclined to build one of the PDP-11/70 models and use the Lions book - only half in jest...
Answers.UserDisplayName: dlu
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-21T10:05:20.920Z
Answers.Text: x86 is not a popular as you may think. The ARM out sells it by about 5:1 (this data may be out of date, it is from before smart phones, with an ARM chip in each). However there may be more learning material for x86, created by misguided people, that think there is a good reason that we use x86. (We use it because of an historical accident: IBM used it in a dead-end project, that got popular, because it was cheaper than Unix, and had spread-sheets.)
Answers.UserDisplayName: ctrl-alt-delor
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-09T11:48:57.873Z
Answers.LastActivityDate: 2019-03-09T15:06:33.427Z
Answers.LastEditDate: 2020-06-18T08:36:57.023Z
Answers.UserDisplayName: ctrl-alt-delor
Answers.Body: <p>There are two standard texts that have stood the test of time. Both are fairly deep:</p>
  
  <p><a href="https://rads.stackoverflow.com/amzn/click/com/1498712436" rel="nofollow noreferrer" rel="nofollow noreferrer">XINU</a> shows how to build an OS that externally resembles UNIX, but isn't (XINU = Xinu Is Not Unix), using a microkernel architecture (unlike Linux). </p>
  
  <p><a href="https://rads.stackoverflow.com/amzn/click/com/1118063333" rel="nofollow noreferrer" rel="nofollow noreferrer">Operating Systems Concepts</a> is more of an overview of OS concepts and how they interrelate. </p>
  
  <p>The first book can be used if you want students to do a lot of programming and experimentation. The second if you are more interested in concepts with less programming. The second can also be used more as a reference backing up your own lectures and course outline. </p>
  
  <p>Both have been updated recently, though earlier editions are classics. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T20:19:07.680Z
Answers.Text: Fantastic.  I will make a note of this answer in case I ever develop an OS course!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-06T13:19:03.473Z
Answers.LastActivityDate: 2019-03-06T13:19:03.473Z
Answers.UserDisplayName: Buffy
Body: <p>I have been appointed to change the contents of an Operating Systems course, because it was too IT oriented. I mean the lectures were oriented only to know the differences between some OS like Windows, Linux or Unix. From my perspective, and considering the recommendations of the ACM Computing Curricula, I believe that the course should include some hands-on programming in the development of some parts of an operating system. The problems that I am currently facing are the following:</p>
  
  <ul>
  <li>The students that I will teach they had only an introductory Python course, so I was planning to teach some C at the beginning of the term.</li>
  <li>I remember that in the old-good days with the use of floppy disks it was "fun" to give a skeleton of an OS for the students to modify and that it could boot on a computer. How can I emulate the same behavior in modern computers?</li>
  </ul>
  
  <p>Actually, are there any kind of emulators or tools that could help the student to learn the concepts of OS by using some C programming? I do not want them to become experts in the field of OS, but at least that they do know what is happening inside an OS and not see it like a black box.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-06T01:11:32.780Z
Comments.Text: How would using the [Linux From Scratch](http://www.linuxfromscratch.org/lfs/) project to build an OS not fit into your goals?
Comments.UserDisplayName: Gypsy Spellweaver
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-06T01:12:48.987Z
Comments.Text: Oh, and Welcome! to [cseducators.se]. Always nice to see users from other stacks in the SE-vers.
Comments.UserDisplayName: Gypsy Spellweaver
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-07T19:54:53.847Z
Comments.Text: Unix once was _an_ operating system, way long ago, and then it branched out to become a family of operating systems, but that's all history. Unix today is a _[proprietary specification](https://www.opengroup.org/membership/forums/platform/unix)_ with which some operating systems have been certified to conform, and it's a trademark that conforming operating systems are allowed to display.
Comments.UserDisplayName: Solomon Slow
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-07T19:58:59.293Z
Comments.Text: Linux never was an operating system.  Linux is merely a _[kernel](https://en.wikipedia.org/wiki/Kernel_(operating_system))_ upon which an operating system can be built. The majority of operating systems that incorporate the Linux kernel (e.g., Debian, Ubuntu, Red Hat) strive to be as Unix-like as possible, although very few of those actually have received the certification that would allow them to actually use the word "Unix" in their names.
Comments.UserDisplayName: Solomon Slow
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-07T20:14:36.520Z
Comments.Text: Re, "students...[have] had only an introductory Python course." If that's true, then they won't have much of a clue about the kinds of services that an operating system provides. It's a pretty big step from knowing how to write and run simple Python programs to understanding things like demand-paged virtual memory, shared library modules, inter-process communication, thread scheduling, device drivers, network protocol stacks,... It's hard for me to imagine teaching somebody how those things are implemented if the student doesn't even know what they _are_.
Comments.UserDisplayName: Solomon Slow
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-09T11:36:04.433Z
Comments.Text: @SolomonSlow UNIX is the trademark, not Unix. But you bring up a good point about Linux being just the kernel, so not a full operating system, I will add an answer.
Comments.UserDisplayName: ctrl-alt-delor
Tags: <operating-systems>
Title: How to teach operating systems development nowadays?
ThreadText: # How to teach operating systems development nowadays?
  
  (Asked by: username_0 on 2019-03-06)
  
  I have been appointed to change the contents of an Operating Systems course, because it was too IT oriented. I mean the lectures were oriented only to know the differences between some OS like Windows, Linux or Unix. From my perspective, and considering the recommendations of the ACM Computing Curricula, I believe that the course should include some hands-on programming in the development of some parts of an operating system. The problems that I am currently facing are the following:
  
  * The students that I will teach they had only an introductory Python course, so I was planning to teach some C at the beginning of the term.
  * I remember that in the old-good days with the use of floppy disks it was "fun" to give a skeleton of an OS for the students to modify and that it could boot on a computer. How can I emulate the same behavior in modern computers?
  
  Actually, are there any kind of emulators or tools that could help the student to learn the concepts of OS by using some C programming? I do not want them to become experts in the field of OS, but at least that they do know what is happening inside an OS and not see it like a black box.
  
  **Tags:** operating-systems
  
  > **Comments:**
  > **username_1**: How would using the [Linux From Scratch](http://www.linuxfromscratch.org/lfs/) project to build an OS not fit into your goals?  
  > **username_1**: Oh, and Welcome! to [cseducators.se]. Always nice to see users from other stacks in the SE-vers.  
  > **username_2**: Unix once was _an_ operating system, way long ago, and then it branched out to become a family of operating systems, but that's all history. Unix today is a _[proprietary specification](https://www.opengroup.org/membership/forums/platform/unix)_ with which some operating systems have been certified to conform, and it's a trademark that conforming operating systems are allowed to display.  
  > **username_2**: Linux never was an operating system.  Linux is merely a _[kernel](https://en.wikipedia.org/wiki/Kernel_(operating_system))_ upon which an operating system can be built. The majority of operating systems that incorporate the Linux kernel (e.g., Debian, Ubuntu, Red Hat) strive to be as Unix-like as possible, although very few of those actually have received the certification that would allow them to actually use the word "Unix" in their names.  
  > **username_2**: Re, "students...[have] had only an introductory Python course." If that's true, then they won't have much of a clue about the kinds of services that an operating system provides. It's a pretty big step from knowing how to write and run simple Python programs to understanding things like demand-paged virtual memory, shared library modules, inter-process communication, thread scheduling, device drivers, network protocol stacks,... It's hard for me to imagine teaching somebody how those things are implemented if the student doesn't even know what they _are_.  
  > **username_3**: @username_2 UNIX is the trademark, not Unix. But you bring up a good point about Linux being just the kernel, so not a full operating system, I will add an answer.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_4 on 2019-03-12. Score: 6
  
  Implementing a whole OS may not be the best approach if you want your students to learn operating system concepts. This is specially true if your students are not proficient in C and Assembly, since major parts like booting, context switching and virtual memory need to be coded in Assembly. This might be daunting for students that have experience only with Python.
  
  An alternative approach is presented in [Computer Systems: A programmers perspective](http://csapp.cs.cmu.edu/). It is a very in depth book, but instead of implementing everything the authors decided to study the System Calls in the POSIX specification as a way to illustrate Operating System Concepts. IMHO it maintains a very good balance between the abstract concepts and their concrete implementations.
  
  > **Comments:**
  > **username_5**: I generally agree, but also note that a microkernel is amazingly small.  
  > **username_6**: Some are, some aren't :-) IIRC the Mach "microkernel" was bigger than the BSD/OS "macrokernel" as we would configure it for a fairly typical server. Wish I could remember the actual numbers, but it's been like 20 years…  
  
  ---
  
  ### Answer by username_6 on 2019-03-21. Score: 4
  
  You might consider using [MIT's xv6](https://github.com/mit-pdos/xv6-public) which they describe as "xv6 is a reimplementation of Dennis Ritchie's and Ken Thompson's Unix Version 6 (v6). xv6 loosely follows the structure and style of v6, but is implemented for a modern x86-based multiprocessor using ANSI C." It can be run in a VM.
  
  Phillip Opperman has a very accessible set of blog posts, [Writing an OS in Rust](https://os.phil-opp.com), it's in it's "2nd edition." The parts on writing the assembler to set up the machine (x86 as well) are particularly good.
  
  
  ---
  
  ### Answer by username_3 on 2019-03-09. Score: 3
  
  First I would recommend to start by using an operating system, such as Gnu ([Debian](https://www.debian.org/) etc), but any Unix will do. Most people have not used an OS: Most people just run applications, but don't interact with the OS. Microsoft's Windows, does not provide anything much to interact with (a file manager, and some config tools). It is mostly just a platform to write stand-alone applications.
  
  Implementing, threading, memory management, etc. without having used them, will be a very abstract activity. Pupils will see the complexity, without seeing the use.
  
  Therefore, do this after
  writing non-kernel parts of the OS. e.g. re-implement `cat`, `ls`, `grep`, etc. in python.
  (In first year of Uni we did this in C. But I thing that python will be easier, and nothing will be lost.)
  
  You could even implement a shell, and/or play with `exec` and `fork`. e.g.
  
  ```
  #!/usr/bin/python3
  
  import os
  stdout_id=1
  
  pipe_out,pipe_in = os.pipe()
  print ("pipe is: ",(pipe_in,pipe_out))
  
  pid=os.fork()
  print("forked")
  
  if pid<0:
      print ("fork error")
      exit()
  elif pid == 0:
      print ("I am child:", str(os.getpid()))
      os.close(pipe_out)
      del pipe_out
      os.write(pipe_in,b"hello1")
      #pipe=os.fdopen(pipe_in,"w")
      #pipe.write("hello2")
      #os.write(pipe_in,"hello3")
      #exit()
      #pipe.flush()
      #os.write(pipe_in,b"world")
      #os.dup2(pipe_in,stdout_id)
      #os.execvp("ls",("ls","-l"))
      print("child here again")
  else:
      print ("I am parent:", str(os.getpid()))
      print ("parent: child's pid="+str(pid))
      os.close(pipe_in)
      del pipe_in
      pipe=os.fdopen(pipe_out,"r")
      for l in pipe:
          print("parent recieved: ", l )
  
  print( "done: "+str(os.getpid()))
  
  ```
  
  You can play with this code, by selectively removing `#`s.
  This will probably not run on Microsoft's Windows (It may in WSL).
  
  “are there any kind of emulators or tools that could help…?”
  
  If you don't have some sort of Unix on you computer (Gnu/Linux, BSD, UNIX, MacOS, WSL), then you can install Gnu/Linux inside Virtual Box.
  
  # On writing the kernel
  
  Do this last. Choose a good architecture (x86 is a mess, ARM is easier). The raspberry-pi is a cheep (≈£30 + box + power + SD card) computer that uses the ARM CPU. You will also have to do parts of the kernel in assembler: The dispatcher (part of the thread scheduler), and parts of the Memory Manager, can not be done in C.
  
  > **Comments:**
  > **username_6**: I'm with you on the "x86 in a mess" front, but it is widely enough used that there is a wealth of material and resources that use it as their example. Personally I'd be inclined to build one of the PDP-11/70 models and use the Lions book - only half in jest...  
  > **username_3**: x86 is not a popular as you may think. The ARM out sells it by about 5:1 (this data may be out of date, it is from before smart phones, with an ARM chip in each). However there may be more learning material for x86, created by misguided people, that think there is a good reason that we use x86. (We use it because of an historical accident: IBM used it in a dead-end project, that got popular, because it was cheaper than Unix, and had spread-sheets.)  
  
  ---
  
  ### Answer by username_5 on 2019-03-06. Score: 3
  
  There are two standard texts that have stood the test of time. Both are fairly deep:
  
  [XINU](https://rads.stackoverflow.com/amzn/click/com/1498712436) shows how to build an OS that externally resembles UNIX, but isn't (XINU = Xinu Is Not Unix), using a microkernel architecture (unlike Linux).
  
  [Operating Systems Concepts](https://rads.stackoverflow.com/amzn/click/com/1118063333) is more of an overview of OS concepts and how they interrelate.
  
  The first book can be used if you want students to do a lot of programming and experimentation. The second if you are more interested in concepts with less programming. The second can also be used more as a reference backing up your own lectures and course outline.
  
  Both have been updated recently, though earlier editions are classics.
  
  > **Comments:**
  > **username_7**: Fantastic.  I will make a note of this answer in case I ever develop an OS course!  
  
  ---
  
  