CS625                                     Assignment 2
Due 11/02/2017 

Do either part I or Part II

Part I: MINIX OS Process, memory, file system, and I/O

Read Appendices B MINIX 3 Source Code Listing. Reverse engineer the source code to identify the programs that implement the following process operations:

1. Internal structure

2. Process management

3. Interprocess communication

4. Process scheduling.

 

Draw the detailed diagrams to show the implementations of the above. Write a report to further descript these details.

Assignment Hand-in Policies:
   1) Email me a Microsoft word report with the diagrams and details of the MINIX OS implementation of processes.
   2) Demo your work in a power-point presentation in the class 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 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) will randomly generate new jobs and put them into the job queues. The new jobs can be simple print and sleep/usleep operations.
The job queues may be stored in an external file so that it can be accessed by other process if processes are used (or store in an array of list if threads are used).

2. The scheduler process (or thread) 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 the round robin algorithm.
(You should attach a random number from 1 to 4 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 sleep for 5 seconds and 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.)

Testing Requirements:

1. Randomly create jobs for the TASK_QUEUE, SERVER_QUEUE, POWER_USER_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 30 to the server queue, 31 to 50 to the power user queue, and 51 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.

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 */

    }

   

 }

}

Assignment Hand-in Policies:
 1) Submit a Microsoft word report in the dropbox on the class Sakai web site that describes your program structure and operations.
     Attach the programs source code and test results (screen shots) on your report.
     Demonstrate your program in the class on the due day.
 2) Good program modular design, data structures, algorithms, and internal documentation are part of the grade.
 3) Non-working program will have at most 50% of the total grade.