You are on page 1of 3

Bits &

Bytes

AN OPERATING SYSTEMS COURSE


WITH PROJECTS IN JAVA
Abdul Sattar, Lee Mondshein, and Torben Lorenzen

This paper describes a set of five programming projects in an under- user is sometimes prompted for additional input, and then output may
graduate Operating Systems course. The problems are designed to be printed. Then the shell program loops back to the point where it
reinforce the fundamental concepts that are discussed in most op- prints a command prompt for the user. Although it is not part of the
erating systems textbooks. Students are required to write programs operating system, the shell makes heavy use of many operating system
that will simulate the behavior of the process management, process features and thus serves as a good example of how the system calls
synchronization, memory management, and storage management can be used. The following is an example of executing a dir command
components of an operating system. after a C:\TEMP> prompt in a Windows command window.

1. Introduction
An operating system (OS) is a piece of software that both hides
the complexity and gives a uniform view of the different types of
hardware that constitute a computer. In addition, an OS serves as
a resource manager, managing subsystem resources such as CPU,
memory, and storage. The undergraduate Operating Systems
course at Bridgewater State College revolves around these sub-
systems, covering four different modules: Process Management,
Process Synchronization, Memory Management, and Storage
Management. In general, undergraduate operating systems courses
are taught in many formats. Courses range from the purely theo-
retical, in which students do not use computers at all, to completely
hands-on, in which students design and write an operating system
or modules of an operating system from scratch.
We started using programming in this course with path Pascal,
then C, and have finally moved to Java. Students are required to
write both standalone programming projects and modules in a In this project, students are asked to implement a simple shell
simulated operating system environment. There are several edu- (command interpreter), called MyShell, that behaves similarly (but
cational operating systems available for this purpose in an under- not identically) to the Windows or UNIX shell.
graduate operating system class, including NachOS from Berkeley.
We choose to use a very small simulated operating system called 2.2. Simulating a process scheduling algorithm
miniKernel, developed by Prof. Solomon at the University of Wis- A multiprogramming operating system allows more than one pro-
consin, Madison. We assign three standalone programming projects cess at a time to be loaded into memory for execution, and permits
and two projects focusing on extending miniKernel. the loaded processes to share the CPU. Allocation of the CPU re-
source among the processes is managed by a scheduling algorithm,
2. Projects of which there are several types:
2.1. Writing a shell program ■ First in First out(FIFO)

An OS shell is a program that presents the user with a plain text ■ Round Robin

(character oriented) interaction window in which the user types com- ■ Shortest Job First(SJF)

mands and accompanying input, and where plain-text output may be ■ Priority based

displayed. The shell prints a prompt and then reads a line of charac- ■ Multi-Level Feedback Queue

ters typed by the user, which is interpreted as a command followed


by arguments. The command may be built into the shell or may be Some of the above scheduling algorithms are either Preemptive
a feature installed in the system. After the command is executed, the or Non-Preemptive. Preemptive algorithms are driven by the notion

24 acm Inroads 2010 June • Vol. 1 • No. 2


b it s & bytes

of prioritized computation: the process with the highest prior- ■ Reader preference: That is, when a new reader and a new writer
ity should always be the one currently using the processor. Non- join the system, the reader process is given the higher priority to
preemptive algorithms are designed so that once a process enters the access the database.
running state (i.e., the condition of being executed by the CPU), ■ Strong reader preference: In this strategy, all the waiting reader

it is not removed from that state until it has completed its required processes should be allowed to access the database over all the
task, used up its service time, or explicitly yielded the processor. waiting writer processes. Also, if a new reader process and a
Students are asked to implement a priority-based, preemptive new writer process join the system, the reader process should
round robin scheduling algorithm for a simple operating system. be allowed to join the other readers in reading the database
The virtual computer used for this project has two resources, a immediately, while the arriving writer process enters the writer
central processor and a disk. There are an undetermined number queue waiting for the access to the database.
of jobs in the system. Every job has three attributes: job number, ■ Weak reader preference: In this strategy, we do not explicitly select

priority number, and estimated time for execution. Every job will the reader process but we select the next process between reader
be in exactly one of the following states: and writer randomly.
■ Sitting in the ready queue waiting to run ■ Weaker reader preference: In this strategy, we give a waiting writer

■ Executing on the CPU


process a higher priority than a waiting reader process.
■ Sitting in the wait queue for disk I/O

In this project, students are asked to develop a multi- threaded


The processor and storage access requirements of all jobs are java program to solve the synchronization problem by using the
given via a file. This file describes the movement of jobs between “Weak reader preference” solution.
various states. The scheduling algorithm determines the order of
execution of the jobs. Process-switching operating system overhead 2.4. Extending miniKernel
is ignored. The project code yields the following output: The objective of this project is to introduce miniKernel, its various
■ A message for each scheduling event, including the time of the components, and its working method. Students are asked to add
event and enough information to describe the action of the event the following system calls to miniKernel:
■ Summary statistics describing the number of jobs entered in the 1. sys_local(): Returns the name of the local machine.
system, the number of completed jobs, the average wait time and 2. sys_time(): Returns the current time in standard 12-hour
turn around time for each job, as well as the average turn around time time format(such as 05:13:00 P.M.)

2.3. Synchronization problem of shared resources Even though the above system calls have limited functionality,
The Reader/Writer problem consists of multiple readers that want their implementation helps students to understand the system call
to read from a database, and multiple writers that want to update mechanism, the interaction between user programs and the kernel.
the database. Many readers can read from the database at the same This work also prepares them for the next project.
time, but when a writer is updating the database, no other writer or
reader should be allowed to access the database. That is, the prob- 2.5. File System Implementation
lem is one of managing concurrent readers and mutually exclusive A file system is an integral part of any modern operating system. It
writers, as shown below. is an information storage system that stores system’s contents and
provides access to it through a File System API. Students are asked
to implement a simple disk-based file system on mini-Kernel. The
specification of the problem is that the file system will allow users
to read, write, create, and delete files on the disk. The size of the
disk is 1000 blocks and one block is 512 bytes. The maximum size
of the file is defined as just one block. There is only one directory
(the root) defined by this file system. Users cannot create any direc-
tory, so all files must be stored in this directory.
At startup, the current working directory is defined as the root
directory. Students successfully implemented the following six
system calls:
■ int format();
This method initializes the contents of the disk with any data
structures necessary to represent an “empty” file system. This
method should create an “empty” root directory.
■ int create(String filename);
Creates a new file with the indicated filename. The initial
contents of the file are all null (zero) bytes.
■ int read(String filename, byte[] buffer);
Researchers in this field use this problem as a test case to study Reads the contents of the file indicated by filename into buffer.
different strategies for solving the synchronization problem of ■ int write(String filename, byte[] buffer);
shared resources. The strategies are: Overwrites the file indicated by filename with data from buffer.

2010 June • Vol. 1 • No. 2 acm Inroads 25


Bits &
Bytes
■ int delete(String filename); ment with the concepts and techniques underlying the projects we
Destroys the indicated file. It is an error if the indicated file does describe in this paper.
not exist. Our search to improve student comprehension and completion
■ int readdir(byte[] buffer); rates has led us to use the minKernel simulated operating system.
Reads the contents of the root directory into the buffer. We have found miniKernel to be a good choice for a college course
that aims to convey the inner workings of an operating system via
The file system was described as follows: hands-on programming projects using Java. A zip file containing
project materials can be downloaded from http://webhost.bridgew.
Whole Disk edu/sattar/os.zip Ir

0–13 blocks 14–100 blocks


References
Free Map Files [1] Steven Robbins, A Three Pronged Approach to Teaching Undergradu-
ate Operating Systems” Proc. Twenty-Second Annual IEEE Symposium
on the ACM SIGOPS Operating Systems Review Volume 42
Individual Blocks [2] Abraham Silberschatz, Peter B. Galvin, Greg Gagne - John Wiley &
0–32 bytes 33–512 bytes Sons (2008) Operating System Concepts, Addison-Wesley, 2008.

File Name File Data ABDUL SATTAR, LEE MONDSHEIN, AND


TORBEN LORENZEN
Department of Mathematics and Computer Science
Bridgewater State College
This project helps students to see how the contents of a file are Bridgewater, Massachusetts 02325 USA
laid out on a raw disk. Sattar@bridgew.edu
LMondshein@bridgew.edu
3. Summary Lorenzen@bridgew.edu>
As computer scientists, we have been tempted to build our operat-
ing systems course around Linux. However, the sheer size of the Categories and Subject Descriptors: K.3.2 [Computers and Educations]; Computer and
Information Science Education –Computer Science Education; D.4.9 [Operating Systems];
Linux code and lack of our own specialized lab prevented us from Systems Programs and Utilities-Command and Control languages
doing so. In contrast, NachOS is intended to be educational rather General Terms: Design, Theory
Keywords: Operating systems education, Java
than industrial-strength software, but we found it to be needlessly
complex, leading to very low homework completion rates. Its com-
plexity overwhelmed rather than supported the students’ engage- DOI: 10.1145/1805724.1805734 © 2010 ACM 2153-2184/10/0600 $10.00

◆ ◆ ◆ ◆ ◆

ITiCSE 2010 ◆ ◆ ◆ ◆ ◆

Bilkent University, Ankara, Turkey


http://www.iticse2010.bilkent.edu.tr/

26 acm Inroads 2010 June • Vol. 1 • No. 2

You might also like