Thursday, September 6, 2012 CC-BY-NC
Introduction to the course

Maintainer: admin

Lecture notes for the first COMP 310 class, taught by Xue Liu. These lecture notes are student-generated and any errors or omissions should be assumed to be the fault of the notetaker and not of the lecturer. To correct an error, you have to be registered and logged-in; alternatively, you can contact @dellsystem directly,

The slides for this lecture are available through MyCourses. Slides covered: 1.1-1.27 (approximate).

1Course information

In this course, you will learn about operating systems, which you may have deduced from the course name. You will learn all about how they work and why they work that way. The main operating system studied is Linux (although many of the concepts apply to operating systems in general).

1.1About the professor

Professor Liu's office hours will be on Tuesday from 9:55-11:00 in McConnell 326. If you wish to contact him outside of these hours, send him an email (his first name and his last name, no separator, at the domain). Make sure the subject begins with COMP 310/ECSE 427: . For example: COMP 310/ECSE 427: Question about assignment 1.

1.2Programming language used

The language used in this course is C. If you really want to use something else (e.g. Java, Python), you may, but it is definitely not recommended. For instance, if you use Java to answer a programming question on an exam, your exam may take longer to be marked and whoever marks it may or may not be happy with you. Also, assignment help and the like will only be provided for C.


There will be two written assignments, neither of which will be graded. There will also be random in-class quizzes, worth a total of 10%. There will be 3 programming assignments, worth 5%, 10%, and 15%, chronologically. (Note that if your grade on any assignment is better than your grade for the previous one(s), it will subsume those marks, but only if you got a non-zero grade on them. For example, if you get 90% on assignment 1 and 95% on assignment 2, then your mark on assignment 1 will be treated as if it were 95%.) The midterm exam will be worth 20%, and the final exam will be worth 40%.


Operating Systems Concepts, by A. Silberschatz, P. B. Galvin, and G. Gagne. The latest edition is the 8th edition, but the 6th and 7th versions are acceptable as well.

2Introduction to operating systems

An operating system is a program that acts as an intermediary between the hardware of a computer and the user-facing programs that run on it. Such a program has three main goals:

  • Execute user programs (e.g., music players, web browsers, text editors);
  • Ensure that using the computer is convenient;
  • Use the hardware efficiently.

A computer system can be divided into four components. There is the hardware, which provides the resources needed to perform computing. There is the operating system, which coordinates usage of hardware by applications. There are applications, which are self-explanatory. Then there are "users", which include humans and other computers.

There is no universally-accepted definition of an operating system, but we can say that an operating system has two primary functions. It is a resource allocator, which manages all computing resources and decides how to dole out access efficiently (through resource-sharing and multitasking) and fairly. It is also a control program, which oversees program execution to ensure that applications behave properly, and to catch errors.

2.1The kernel

The kernel, the main component of most operating systems, acts as a bridge between user programs and the hardware. This is the one program running on the computer at all times. Other programs that come with the OS can be thought of as system programs; everything else is an application program.

Some operating systems, such as Mac OS and MINIX, have a microkernel, following the philosophy that one should put as little as possible in the kernel itself and that things like device drivers and file systems should be put in the user space. The opposite extreme is the monolithic kernel, in which the entire operating system runs in kernel space. This method is employed by GNU/Linux and Windows, among others.

2.2Booting up

The first operating system program to be loaded when a computer starts up is a bootstrap program. Such a program is usually stored in read-only memory (ROM, or EPROM for erasable programmable read-only memory - both are non-volatile memory stores). This program will load the operating system kernel into main memory and begin its execution. Through this bootstrapping process, all the other aspects of the operating system will be loaded.

2.3Device controllers and interrupts

Usually, we have one or more CPUs and device controllers connected to each other and to memory through a common bus. One important consequence of this is that I/O devices and the CPU can execute independently, and thus concurrently. Although device controllers compete with each other and with the CPU(s) to use the memory, each has a (small) local buffer that can be used; it is the job of the CPU to move data from local buffers into main memory. Once a device controller has finished its operation (e.g. calculating the new position of the cursor after the mouse has been moved), it indicates this to the CPU by triggering an interrupt.

Once an interrupt has been triggered, the CPU first looks up the memory address of the relevant interrupt handler (or interrupt service routine), based on the type of interrupt, from the interrupt vector table. The address of the instruction that is currently being interrupted is saved, along with its registers, and control is then transferred to the interrupt handler. While this interrupt is being processed, incoming interrupts are ignored to prevent a lost interrupt.

Put a diagram in here one day

Interrupts can be generated by hardware or by software (although terminology can vary; some use the word "interrupt" to refer solely to hardware-generated interrupts, for example). Software-generated interrupts are generally called traps, and can be triggered by runtime errors or exceptions such as division by zero and segmentation faults. When a trap occurs in a user program, control is usually returned to the operating system, with some action being performed in kernel mode. Traps that occur in system programs can be fatal, and may lead to your computer exploding.

Interrupts are a popular way of accomplishing multitasking, and operating systems that use these principles are said to be interrupt-driven.