# How to teach operating systems development nowadays?

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.

• How would using the Linux From Scratch project to build an OS not fit into your goals? – Gypsy Spellweaver Mar 6 at 1:11
• Oh, and Welcome! to Computer Science Educators. Always nice to see users from other stacks in the SE-vers. – Gypsy Spellweaver Mar 6 at 1:12
• 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 with which some operating systems have been certified to conform, and it's a trademark that conforming operating systems are allowed to display. – Solomon Slow Mar 7 at 19:54
• Linux never was an operating system. Linux is merely a kernel 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. – Solomon Slow Mar 7 at 19:58
• 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. – Solomon Slow Mar 7 at 20:14

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. 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.

• I generally agree, but also note that a microkernel is amazingly small. – Buffy Mar 12 at 14:45
• 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… – dlu Mar 21 at 3:42

There are two standard texts that have stood the test of time. Both are fairly deep:

XINU 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 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.

• Fantastic. I will make a note of this answer in case I ever develop an OS course! – Ben I. Mar 6 at 20:19

First I would recommend to start by using an operating system, such as Gnu (Debian 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.

• 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... – dlu Mar 21 at 3:49
• 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.) – ctrl-alt-delor Mar 21 at 10:05

You might consider using MIT's xv6 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, it's in it's "2nd edition." The parts on writing the assembler to set up the machine (x86 as well) are particularly good.