CS519
Assignment 2
Due 06/30/2008
Part I: Report of Lecture Notes and Textbook studied on Memory Management
(Ch 3), File Systems (Ch 4), and I/O (Ch 5)
Write a Microsoft report to summarize your self-study activities. The report must have the following.
1. The time and date of your study and the topics covered in each study session.
2.
The summary of each topic studied.
3. Questions and answers in each study session
(you may make up the questions or use the problems at the end of each chapter
from the textbook.)
4. Conclusions of knowledge learned.
Email the report to the instructor
on the due day.
Part II: Process Scheduling Project on cs1
Write a C/C++ Process Scheduler program on UNIX
to simulate the round robin priority scheduler (pp 145) with four
queues: TASK_QUEUE, SERVER_QUEUE, POWER_USER_QUEUE, and USER_QUEUE.
The program should create the following processes (or threads) for the
scheduler simulation:
1. The job-generation process (or thread)
that will randomly generate new jobs and put them into the job queues. The new
jobs can be simple arithmetic operations such as +, -, *, /.
The job queues may be stored in an external file so that it can be accessed by other
process (or store in an array of list if threads are used).
2. The scheduler process (or thread) that will select a job from the job queues and create a new work process (or thread) to run the job. The scheduler will use the following scheduling algorithm:
a. Jobs in the TASK_QUEUE have the highest priority. These jobs will be run until finished.
b. Jobs in the SERVER_QUEUE have the second
priority. These jobs will be run using round robin algorithm.
(You should attach a random number from 1 to 3 with the job to indicate the
number of quantum times that the job needed to be run to finish.)
c. Jobs in the POWER_USER_QUEUE have the third
priority. These jobs will be run and then blocked for the input. It will become
ready to run again when user types the interrupt key ^C, then it will be run to
the finish.
(See the signal demo on the third semaphore method on semaphore demo
page for interrupt key implementation.)
d. Jobs in the USER_QUEUE have the lowest priority. These jobs will be run once, and then wait for all the higher priority jobs to be finished, then run to finish.
Before
scheduling the next job, the scheduler will check whether a new higher priority
job is available. It always schedules the next job with the highest priority.
Please don't use infinite loop to generate the processes/threads. You should control the number of processes/threads generated by a counter.
3. Both the job-generation and scheduler processes (or threads) will access the job queues. You must avoid the race condition by put the job queues into a critical region. (You may use semaphores or monitors to protect the critical region.)
4. The main() function should follow the following program structure.
a. A Priority Scheduler using multiple processes
int main() {
…
setJobQueues(); /* Set up the priority job queues with chosen file and data structure */
if (pid=fork() != 0) {/* Parent, jobGenerator process */
jobGenerator(…); /* generate random jobs and put them into the priority queues
The priority queues must be protected in a critical region */
} else {/* Child, job scheduler process */
jobScheduler(…); /* schedule and execute the jobs. */
exit(0);
}
return (1);
}
void jobScheduler(…) {
…
while (i < N) { /* schedule and run maximum N jobs */
n=selectJob(…) /* pick a job from the job priority queues */
if (n>0) { /* valid job id */
if (pid = fork() == 0) { /* child worker process */
executeJob (…); /* execute the job */
exit(0);
}
}
}
b. A Priority Scheduler using multiple threads
int main() {
…
setJobQueues(); /* Set up the priority job queues with chosen file and data structure */
…
pthread_create(&generatorThreadId, NULL, jobGenerator, NULL);
/* a thread generates random jobs and put them into the priority queues
The priority queues must be protected in a critical region */
pthread_create(&schedulerThreadId, NULL, jobScheduler, NULL,);
/* a thread schedules and executes the jobs. */
pthread_join (&generatorThreadId, NULL); /* wait for thread to terminate */
pthread_join (&schedulerThreadId, NULL); /* wait for thread to terminate */
…
pthread_exit(NULL); return (1);
}
void jobScheduler(…) {
…
while (i < N) { /* schedule and run maximum N jobs */
n=selectJob(…) /* pick a job from the job priority queues */
…
if (taskJob) { /* valid task job id */
pthread_create(&jobThreadId[i], &attr, executeJob, (void *)arg); /* execute the job */
}
…
}
}
Testing Requirements:
1. Randomly create jobs for the TASK_QUEUE, SERVER_QUEUE, and USER_QUEUE to test your scheduler.
For example, you may generate random job numbers between 1 to
100 and assign the job with random numbers between 1 to 10 to the task
queue, 11 to 40 to the server queue, and 41 to 100 to the user queue.
Each queue should have a MAX_JOB_QUEUE size to limit the number of jobs.
You should use the sleep() function to control the
speed of the simulation.
2. Print out each step of the job execution.
Assignment Hand-in Policies:
1) Email me a Microsoft word report that describes your program
structure and operations.
Attach the programs source code and test
results (screen shots) on your report.
2) Good program modular design, data structures, algorithms, and
internal documentation are part of the grade.