OS Programming Center



Introduction to Multitasking

To explain what multitasking is, I'll use an example. Imagine that there is program "A". That program "A" reads numbers from a file, does some calculations with them and writes the results in another file.

- beginning of program "A"
---- read a file
---- do the calculations
---- write the results
- end of program "A"

Now imagine that also there is a program "B". That program waits until you type a line and prints what you typed in the printer.

- beginning do program "B"
---- wait for a line of text
---- print text in the printer
- end of program "B"

In a simpler operating system (and probably an older one), you run program "A" and wait until it has finished its job. When program "A" ends, you run "B" and wait again. This certainly isn't efficient. And if we could run both programs at the same time?

If you use an operating system that supports multitasking, you run program "A" and program "B". While program "A" reads the file program "B" waits for the text. At the same time program "A" does the calculations, "B" prints the line in the printer.

Becouse the actions use different parts of the computer they can be runned at the same time.


Program "A"Program "B"Is using
***disk
***processor
***keyboard
***printer

This way the computer is used effciently and the programs need few time to complete its tasks.

How multitasking occurs

Real multitasking can only be present in computers with more than one processor. In computers with only one (most of them) is only possible to pretend multitasking.

The way OSs do that is simple. When there are two or more programs being runned at the same time, the control is passed to one program. After some time, the OS stops the execution of the program and passes the control to another. That happens very fast, so we have the ilusion that the programs are running at the same time.


Program "A"Program "B"Program "C"
running
running
running
running
......

By Diogo Kollross


Click here to come back to the homepage.
Click here to come back to the texts area.
Click Here!