12
$\begingroup$

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.

$\endgroup$
6
  • 1
    $\begingroup$ How would using the Linux From Scratch project to build an OS not fit into your goals? $\endgroup$ Mar 6, 2019 at 1:11
  • 1
    $\begingroup$ Oh, and Welcome! to Computer Science Educators. Always nice to see users from other stacks in the SE-vers. $\endgroup$ Mar 6, 2019 at 1:12
  • $\begingroup$ 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. $\endgroup$ Mar 7, 2019 at 19:54
  • $\begingroup$ 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. $\endgroup$ Mar 7, 2019 at 19:58
  • 2
    $\begingroup$ 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. $\endgroup$ Mar 7, 2019 at 20:14

4 Answers 4

6
$\begingroup$

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.

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

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.

$\endgroup$
3
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Fantastic. I will make a note of this answer in case I ever develop an OS course! $\endgroup$
    – Ben I.
    Mar 6, 2019 at 20:19
3
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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... $\endgroup$
    – dlu
    Mar 21, 2019 at 3:49
  • $\begingroup$ 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.) $\endgroup$ Mar 21, 2019 at 10:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.