CS354 – Operating Systems
Fall 1997 -- Dickinson College
Topic:Which Process Gets To Run Next?
We talked about the project cycle last time.
There is a document linked to from the project assignment that more fully describes the project cycle and what is expected.
Change the user process scheduler in Minix from a round robin scheme to a shortest job first scheme.
We'll see SJF later today.
Design Review Document Due: 10/2/97
Schedule the design review meeting between 10/3 & 10/8.
The sooner the better so you can get on with the implementation.
Project Report Due: 10/16/97
Your CD has a complete listing of all of the Minix code in text format
Do Not Print These Out!! The are about 1000 pages long.
The green bar is an index to these files.
Gives the line numbers of every procedure/variable/file in the Minix system.
It is immensely helpful in tracing code.
I put a copy of all of the minix source code on my zax account so that you can look at & print individual files.
The files are in /export/home/fac/braught/OSF97/Minix/…
You hear this from me every time - but I'd get started early.
There are also a few more system administration tasks for you to perform.
Every project will have a few of these.
Representing a Process:
We decided that the fork() function does the following:
Makes a copy of the process that calls it.
Creates a child process that is a copy of the parent process.
Changes the PID of the child process (it changes some other stuff to…)
Puts the child process in the ready queue.
What does it mean to make a copy of the process?
I.e. What needs to be copied?
What information does the OS keep about the processes?
Lots of stuff…
Info about what memory the process is using.
Info about what files the process is using
Info about how much CPU time the process has uesd.
The global data for the process.
Everything that is needed to stop & restart and track a process + some accounting information.
How does it store this information?
How would you store this information if you were writing the program?
It uses a structure. The proc structure.
Every OS has some structure similar to this that holds information about all of the processes in the system.
The Proc Structure:
There is a proc structure for each process in the system.
In Minix this includes all of the servers/tasks and user processes.
Everything that shows up when you type ps -a -x
Note: The -x parameter is Minix specific. But -a is not.
The Process Table:
The OS keeps track of all of these proc structures by using a process table:
Again every OS has some equivalent to the process table.
This is an array of pointers to proc structures:
struct proc *pproc_addr[NR_TASKS + NR_PROCS];
The number of processes the system can run is limited by the number of entries in the process table.
As long as the process has not exited it will have a proc structure and that structure will be pointed to by an entry in the process table.
The Process Table:
Changing the Process ID number:
So changing the PID and other stuff. How is this done and what other information might be changed?
The PID is just changed in the proc structure. Other things that are changed are:
The Accounting information is cleared.
The memory information is updated to indicate the location of the child's image.
The File information is cleared.
The child does not inherit the open files of the parent.
The Ready Queue:
What does it mean to put the process in the ready queue?
How might the OS keep track of the ready queue?
The ready queue is a linked list of proc structures. Adding a process to the ready queue just means inserting it in this linked list.
To do this, of course, a pointer to the next ready process must be added to the proc structure:
In Minix the user queue is scheduled using a round robin scheme:
This means that each process gets a turn with equal priority:
New processes are added at the rdy_tail.
The next process to run is taken from rdy_head.
Just like a normal queue.
Processes in the Running or Blocked State:
Not every process in the process table is in the ready state. What other states are there and how does the OS keep track of them?
There are two other states running and blocked. Lets deal with them one at a time:
The process that is currently in the running state remains in the ready queue but also has an additional pointer to it:
The proc_ptr points to the process that is in the running state.
When it leaves the running state it either stays in the ready queue or goes into the blocked state or exits.
If it stays in the ready state it will be moved to the end of the queue (if round robin scheduling is used.)
If it exits it is removed from the queue and from the process table.
So what happens to a process when it enters the blocked state?
What can happen in Minix to cause a process to enter the blocked state?
In general processes block because they are forced to wait for something that is beyond their control. Processes in minix can only block for 2 reasons:
They are waiting for a message from another process.
Here the proc is just hanging out in the process table. It is not in the ready queue and it is not linked to by anything. It is just waiting for another process to call on it.
They are waiting for another process to receive their message.
Here when the sending proc sends the message it will be put on a queue that has its head in the proc structure of the destination process.
As an example in the previous process table:
the FS, the MM and the DISK task are all blocked waiting for a message from another process.
In the case of the FS & MM they are probably waiting for a message from ANY process.
In the case of the DISK task it is waiting for a message from the FS.
More of an Example:
Suppose P10 (the currently running process) has made a request to write something to a file.
At this point P10 would block on the pending message queue of the FS server.
The FS server would move into the ready queue and eventually run.
When the FS runs it receives the message from P10 which removes P10 from the pending message queue and leaves it waiting for a reply from the FS telling it that the I/O is finished.
The FS sends a message to the DISK task which puts the FS on the pending message queue for the DISK task.
The DISK task is moved into the ready queue and eventually runs.
When the DISK task is run it receives the message from FS which removes P10 from the pending message queue and leaves it waiting for a reply from the DISK task telling it that the I/O is finished.
The DISK task sets up and generates and interrupt and blocks waiting for an interrupt from the hard disk telling it that the file I/O has finished.
The hard disk does its thing and generates an interrupt.
Through the process of vectored interrupts the DISK task is notified and begins running again.
It sends a message to the FS telling it that the I/O is finished. This blocks the DISK task on the FS and moves the FS to the ready queue.
The FS runs and receives the message and the DISK task goes back to waiting for a message from the FS.
The FS sends a message to P10 and blocks. This moves P10 to the ready queue.
P10 is run and receives the message. The FS blocks waiting for a message from any process.
The Moral of the Story:
Processes that are waiting for a message just hang out in the process table until the message finds them.
Processes that are waiting for a process to receive one of their messages are blocked on a queue associated with the process that is the destination of the message.
Having said all that Minix isn't quite that simple:
Minix ready queues:
Minix has 3 ready queues:
One for tasks
One for servers
One for user processes.
Each is scheduled using a round robin scheme.
The scheduler looks at the task queue first and runs any processes there.
If there are no ready tasks it looks at the server queue and runs any processes it finds there.
If there are no servers it looks at the user queue and runs any processes it finds there.
If there are no user processes it runs a task called IDLE.
Minix Process table and proc structure:
The minix proc structure is broken into 3 parts.
This separates the stuff having to do with the memory manager, the file system and the more general system stuff.
So each process has 3 proc structures (proc, m_proc, f_proc)
Minix also keeps 3 process tables:
One in the system server, one in the file system and one in the memory manager.
The proc, m_proc and f_proc for a given process are located at the same index in all 3 process tables.
The ready and blocked queues are only maintained in the proc structure in the system server.
Process Scheduling Issues:
What is the job of the scheduler?
To pick the next process that will run from the ready queue.
What is the best way for the scheduler do this?
Tough question that depends on what the goals of the system are!
What should a good scheduler do?
Ensure Fairness - all processes get a "fair" share of CPU time.
What is fair?
Depends on what you are using the system for!
Increase Efficiency - Keep the CPU busy 100% of the time.
How can you do this?
Easy let an infinite loop run all the time! Not a good solution.
Is this productive work?
No - so maybe a better definition would be to keep the CPU doing productive work as close to 100% of the time as possible.
Minimize Response Time - make sure users don't need to wait very long for response to their commands.
How can you do this?
By using time sharing.
What will determine how responsive your time sharing system is?
The length of the time slice.
What happens between each time slice?
The OS must run the scheduler to pick the next process.
Is the CPU time used by the scheduler productive work? What does this do to efficiency?
Any time the scheduler runs it is taking CPU time away from useful processes.
What does that say about the scheduler?
It should run as infrequently as possible and be as fast as possible!
What is the penalty for running the scheduler infrequently?
The responsiveness of the system will suffer!
Should you favor response time or efficiency?
Depends on what your system is doing.
Minimize Turnaround Time - The time it takes for a process that requires no user input to finish.
How can you accomplish this?
What happens if you increase the duration of the time slice?
These processes will use up their entire time slice and will require fewer time slices to finish. This will let them finish faster thus reducing the turnaround time.
What is the problem with that?
It increases the response time.
Do you favor Turnaround time or response time?
Maximize Throughput - the number of processes completed per time (i.e. sec/min/hour/day).
Several times we decided that it depends on the goals of your system what the scheduler should do about particular issues.
What kinds of processes are there in a typical unix/Minix system?
What types of things do your processes do?
There are several different classifications:
Interactive -vs- Batch
What is an interactive process?
Requires constant input from the user to tell it what to do
Text editor, shell, game.
What is a batch process?
Process that does not require any interaction from the user after it is started.
Sorting a data file
Getting information (who/finger/ps/ls etc…)
I/O Bound -vs- CPU Bound
What is an I/O bound process?
One that spends most of its time waiting for I/O.
What is a CPU bound process?
A process that spends most of its time doing computations that require the CPU.
Given a system that uses time sharing which type of process is likely to use the most CPU time, an I/O bound process or a CPU Bound process?
The CPU bound process since the I/O bound process will block each time it has to wait for input. Like the text editor waiting for the next keystroke to display on the screen.
Will Interactive or Batch systems be CPU bound or I/O bound?
Either kind can be I/O bound. An Interactive process will always be I/O bound. Where as a batch process may not be I/O bound. Similarly an interactive process will not be CPU bound where as a batch process might be CPU bound.
Given a system that will be running batch processes that read data files and print out reports all day what might be the primary criterion for evaluating the scheduler?
What about a system that is designed for multi-player games?
What about a system like Minix, or unix on zax or alpha?
That is a harder question. These systems run both types of processes so there needs to be some kind of balance.