Use man and info to find out about ps, top, kill, nice and other Unix commands that allow you to inspect and manage processes. If you're running cgywin on Windows machine, you'll only see the processes that are running under cygwin. On a machine running Microsoft Windows, you might try the Windows Task Manager to see the systems processes. On an Apple computer running OS X, top will provide a pretty comprehensive view of the system processes, but you might try the Apple Process Viewer for a somewhat nicer interface.
We're going to explore a metaphor for thinking about how operating systems handle processes. Imagine a bureaucrat managing a bunch of tasks and trying to be fair in allocating time to each one. This bureaucrat, we'll call him Gort, has a desk on which are the following items:
a timer with an alarm; if the timer is stopped and you hit its start button, it starts counting down from some specified interval, say one minute; when the timer reaches zero, a bell rings and the timer stops,
a telephone with which Gort can call other bureaucrats,
a small chalk board on which Gort can jot down a few numbers corresponding to intermediate results in his calculations, and
a pad of yellow stickies that can be affixed to papers so that Gort can remember items associated with tasks.
Each task consists of one or more pages of paper stapled together containing numbered instructions. The instructions involve collecting information (call so-and-so and find out the total sales for July) and performing mathematical calculations (compute the difference between the July sales and the July expenses). Think of the forms as similar to the ones you get from the IRS for filing in your income tax returns; however, in this case, we'll assume that Gort can't write on the forms and that the final output of each task can be summarized by Gort making a short phone call to the person for whom the task is being performed.
The tasks are arranged in two stacks; those tasks that are ready to be worked on and those that are awaiting additional information before more progress can be made. If Gort is in the midst of working on a task and there's a piece of information he needs, he'll pick up the phone and call the relevant bureaucrat. If the bureaucrat is busy (the usual circumstances), then Gort will ask him to call back when he gets the information. Since he can't make any additional progress on that task, it goes on the stack awaiting additional information.
If the alarm goes off when Gort is in the midst of working on a task, he records any information on the chalk board on a sticky, attaches it to the task right where he left off, erases the chalk board and then places the task at the bottom of the pile of tasks ready to be worked on. Gort then takes the top task off the pile of ready tasks, finds the yellow sticky marking where he left off, transfers the information on the sticky to the chalk board, hits the button on the timer and sets to work on the task.
What do you think should happen when Gort gets interrupted by a phone call? What would happen if tasks could generate other tasks? Note that making a phone call is one way that tasks can already generate other tasks. Can you imagine a way in which tasks could interact by sharing information?
How would Gort's management of tasks differ if the tasks were given priorities so that tasks from the president would get priority over those from a vice president and those from a vice president would get priority over those from a clerk? What would happen if a task for the president depended on a task from a clerk? Does your task management strategy deal with this situation gracefully?
Imagine whole collections of bureaucrats working simultaneously. What if two bureaucrats want to execute the same task, say for different vice presidents, but there is only one copy? In this case, what would happen if one bureaucrat writes on or replaces the sticky being used by another bureaucrat?
See if you can characterize the differences between current operatings systems. Consider Apple OS X, Linux, Microsoft Windows, Solaris and Unix. Are these even distinct operating systems? Perhaps these names really correspond to classes of operating systems, e.g., Windows 2000 versus Windows XP. How can Apple, RedHat and Sun sell operating systems that are based on freely available code? What features of operating systems do you think are most important?
Download all the code fragments in this chapter as a file in zip format.