harsha(os assign)

harsha(os assign) - Computer and Network Engineering...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer and Network Engineering Lecturer: Prof Marcos Rodrigues Operating systems Assignment : Multitasking and Scheduling System Date of Submission: 19th December 2008 Submitted By: NUTUKURTHI SRIHARSHA (18028918), SAIKRISHNA BADHEY (18035225) INTRODUCTION: The main concepts of operating system are implemented in order to develop a system which contains two processes that continuously generate jobs (in the form of structures) that are sent to the scheduling system. The scheduling system, which is in fact a “scheduler” process that is running concurrently, receives these jobs and inserts them onto a separate queue for processing. The queue is held in a datapool (shared memory). A “processor” process will analyse all the job queues and produces the required output. SCHEDULING: The main concept of computer multitasking is known as scheduling. An operating system is a link between resources and applications. Physical devices and memory can be known as resources. Even a CPU can be considered as a resource in which for a temporary task a scheduler can be allocated. The possibility of executing multiple programs (tasks) simultaneously is only through scheduler. Scheduler is the vital in computer for multi-processing and multi-tasking operating system and also for real-time operating system.CPU is allocated with time slices while providing a responsive user experience. Minimization of response times for real-time tasks when the maximum utilization of CPU is also to be done by the scheduler. Scheduler is of three types. They are • Long term scheduling, • Medium term scheduling and • Short term scheduling. Long term scheduling: It controls the degree of multi-tasking and programming and also decision of addition of the pool of processes to be executed is taken. More the number of processes, the lesser the time for control. If a job terminates then one or more jobs are allocated by the scheduler. Long term scheduling is based on two simple policies. They are • Simple First Come First Served (FCFS): The working of FCFS is similar to First in First out (FIFO).All the job requests are honoured to a certain limit and later on the further job requests are made to out or they are enqueued or lined for further processing. • Simple Priority Schemes: In this there is a choice of executing a program where the choice of ready process is to be executed. High priority processes are scheduled before the low priority processes. Each process is defined with a priority like background, foreground, real-time. Medium term scheduling: It is a part of swapping which is assigned to memory management. Its interaction with short term scheduler makes it very efficient for system performances especially in virtual memory systems. Short time scheduling: Short time scheduling is concerned with CPU time to processes to meet the predefined system performance objectives. The objectives over here are defined as design issue which determines the character from the user’s point of view. MULTITASKING: Multitasking is a process which executes many programs at a particular time in parallel i.e. The ability of the system to execute more than one task at the same time. They are two types of multitasking: Preemptive Multitasking: • • The operating system parcels out CPU time slices to each program. Operating system examples: Windows NT and Windows 95 Cooperative Multitasking: • • Each program can control the CPU for as long as it needs it. Operating system examples: Multi Finder and Microsoft Windows 3.x SEMAPHORE Semaphore is defined as a variable or a data type which is a method used to restrict action of resource like shared memory in multi programming. Semaphore is available in many forms like counting semaphore, binary semaphore. Binary semaphore is called as Mutex which includes extra features like ownership or priority inversion protection. PIPELINING: Pipelining is a key implementation technique used to build fast processors. It allows the execution of multiple instructions to overlap in time. CONCURRENCY: It is the property of the system where several processes are executing at the same time and simultaneously interacting with each other. In multitasking and scheduling system concurrency can be shown using scheduler where scheduler performs different tasks at the same time such as a. b. c. Add new jobs in to Job queue Sending new job to Processor for processing. Update or delete the jobs that are no longer required. Multitasking and Scheduling System Implementation The system mainly consists of (I) Job Generator( Line 2 & Line 3) (II) Scheduler ( Line 1) (III) Processor (In-put process) Flow of events for Multitasking and Scheduling System Implementation LINE 2 LINE 3 SEND JOBS SCHEDULER (LINE 1) ADD NEW JOBS READ DATA & PRODUCE OUTPUT PROCESSOR (INPUT PROCESS) SEND A JOB Explanation for Multitasking and Scheduling System • • • The first step is creation of jobs i.e. the jobs are created in line 2 and line 3 and these jobs are then sent to scheduler, Scheduler inserts them into job queue/pipe (The Scheduler Process uses pipe to access this Jobs). The processor reads the job from the datapool (shared memory)and executes the jobs which are present in job queue and produces the output. The working procedure of the system consists of four processes and they are as shown below: Jobs Creation process (Line2) • The Job Generator are a set of Processes namely line2 line 3 • Line2 process generate jobs in the form of structures which are in the form of struct job { int total_running_time; int remaining_time; int queue_position; }; Where Total_running_time gives the total time required for performing the job. Remaining_time gives the time required for completing the jobs by the processor Queue_position gives the details of job position in the job queue Jobs Creation process (Line3) • Line3 process generate jobs in the form of structures which are in the form of struct job { int total_running_time; int remaining_time; int queue_position; }; Where Total_running_time gives the total time required for performing the job. Remaining_time gives the time required for completing the jobs by the processor Queue_position gives the details of job position in the job queue • They are used for generating the random total time and inserting the Job Structure in the Pipe.( The Scheduler Process uses pipe to access this Jobs) Scheduler • Scheduler performs mainly these operations they are a. The scheduler does a multi-tasking in real time operating system. b. Add new jobs to the job queue which are generated from the generators line2 and line3 c. Request for jobs to the processor for processing d. Display the remaining jobs in the job queue which need to be processed • One more important feature of this Process i.e Scheduler is that , it uses Semaphore for synchronization with the "Processor Process". • Initially the Processer Semaphore is set to 1 and Scheduler Semaphore is set to zero, i.e the Scheduler when waits on the "Processor Semahpore" it is given immediate access and the control flows to the next statement of execution. • Once the Scheduler is done with the required calculations/operations as explained above , it signals the Scheduler Semaphore i.e it calls Scheduler.Signal which indicates that the "Processor Process" which is waiting on the Scheduler Signal can now proceed with the execution. • After the Execution of the required tasks, the "Processor Process" signalsthe Processor Semaphore i.e the Scheduler which is now waiting for the Processor Signal can proceed with its execution. • Thus, binary Semaphore is used for synchronization between the "Schduler Process" and the "Processor Process". Processor Processor is a place where all the jobs are executed/ processed as sent by the scheduler . Processor processes the data that is present in the Job Queue i.e shared memory or DataPool Once the processor compltes one task/job it requests the scheduler for another job , the scheduler then sends the next job to the processor The processor reads the job from the datapool (shared memory) and executes the jobs which are present in job queue and produces the output The algorithm implemented in this is scheduler for processing of jobs is FCFS algorithm i.e. First Come First Serve .FCFS is also called as first in first out algorithm. According to this algorithm process are dispatched according to their arrival. Since it is nonpremptive discipline. Once the processor gets the job it runs till the completion. Program execution in Visual C++ Software and the required output is shown below REFRENCES: Stallings, William (2004). Operating Systems Internals and Design Principles (fifth international edition). Prentice Hall. ISBN 0-13147954-7 Blazewicz, J., Ecker, K.H., Pesch, E., Schmidt, G. und J. Weglarz, Scheduling Computer and Manufacturing Processes, Berlin (Springer) 2001, ISBN 3-540-41931-4 (http://en.wikipedia.org/wiki/Synchronization_(computer_sci ence)#Process_synchronization) (http://wiki.forum.nokia.com/index.php/How_to_communicat e_between_two_threads_or_processes) http://www.webopedia.com/TERM/M/multitasking.html http://en.wikipedia.org/wiki/Scheduling_(computing) http://www.webopedia.com/TERM/M/multitasking.html http://en.wikipedia.org/wiki/Semaphore_(programming) http://www.faqs.org/patents/app/20080256173 http://en.wikipedia.org/wiki/Concurrency_(computer_science) APPENDIX Code for Input process and scheduler // A Win32 C program to demonstrate the creation and use of named Pipes. Error checking has // been ommitted to aid clarity #include #include on your disk #include int { main() CSemaphore protect ("protect1" , 1); struct speed *line1 = (struct speed *)(dp.LinkDataPool()); protect.Wait(); line1->spd2 = 1000; line1->spd3 = 1000; protect.Signal(); <stdio.h> "rt.h" // change the pathlist to rt.h to suit location "F:\\operating _system\\scheduling_system\\shared.h" printf("Parent Process Creating the Pipeline.....\n") ; CPipe pipe1("MyPipe" ,2048) ; // Create a pipe 'p1' with the name "MyPipe" printf("Parent Process Creating Child Process to Read from Pipeline.....\n") ; CProcess p1("F:\\operating _system\\scheduling_system\\line1_process\\Debug\\line1_process.exe", to child program executable NORMAL_PRIORITY_CLASS, // priority OWN_WINDOW, has its own window ACTIVE is active immediately ); while (1) { if (TEST_FOR_KEYBOARD() != 0) { protect.Wait(); line1 -> keyData[0] line1 -> keyData[1] protect.Signal(); if (line1 -> keyData[0] == 'x' && line1 -> keyData[1] == 'x') { break; } } else { Sleep(1000); if(rand()%2 == 0) { object [0] = 'b'; pipe1.Write(&object[0],sizeof(object)); = line1 -> keyData[1]; = getch(); // pathlist // process // process } else { count1++; TEXT_COLOUR(9,0); cout<<" blue " << " " << count1 <<endl; object [0] = 'r'; pipe1.Write(&object[0],sizeof(object)); count1++; TEXT_COLOUR(12,0); cout<<" red " << " " << count1 <<endl; } } } cout << "Waiting for Line1 to Finish" << endl; p1.WaitForProcess() ; } return 0 ; Scheduler // A Win32 C program to demonstrate the creation and use of name pipe. Error checking has // been ommitted to aid clarity #include <stdio.h> #include "rt.h" // change the pathlist to rt.h to suit location on your disk #include "F:\\operating _system\\scheduling_system\\shared.h" s int main() { CPipe pipe1("MyPipe" ,2048); Create a pipe 'p1' with the name "MyPipe" CPipe pipe2("pipe2" ,2048); CPipe pipe3("pipe3" ,2048); struct speed *line1 = (struct speed *)(dp.LinkDataPool()); CSemaphore protect ("protect1" , 1); // CProcess p2("F:\\operating _system\\scheduling_system\\line2_process\\Debug\\line2_process.exe", // pathlist to child program executable NORMAL_PRIORITY_CLASS, // priority OWN_WINDOW, // process has its own window ACTIVE // process is active immediately ); CProcess p3("F:\\operating _system\\scheduling_system\\line3_process\\Debug\\line3_process.exe", // pathlist to child program executable NORMAL_PRIORITY_CLASS, // priority OWN_WINDOW, // process has its own window ACTIVE // process is active immediately ); protect.Wait(); line1 -> keyData[0] = '2'; line1 -> keyData[1] = 'p'; line1 -> keyData3[0] = '3'; line1 -> keyData3[1] = 'p'; protect.Signal(); while(line1 ->keyData[0] != 'x' && line1 ->keyData[1] != 'x') { protect.Wait(); char sema1 char sema2 int speed2 int speed3 = = = = line1 line1 line1 line1 -> -> -> -> keyData[0]; keyData[1]; spd2; spd3; protect.Signal(); if (pipe1.TestForData() >= sizeof(object)) { pipe1.Read(&object[0],sizeof(object)); if (sema1 == '2' && sema2 == 'q') { if (speed2 == 2000) { cout << "This is slowest Speed"<< endl; protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else { protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; line1 -> spd2 = line1 -> spd2 + 100 ; protect.Signal(); } } else if (sema1 == '2' && sema2 == 'w') { if (speed2 == 0) { cout << "This is highest Speed"<< endl; protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else { protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; line1 -> spd2 = line1 -> spd2 - 100 ; protect.Signal(); } } else if (sema1 == '3' && sema2 == 'q') { if (speed3 == 2000) { endl; cout << "This is slowest Speed"<< protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; } else { protect.Signal(); speed3 = speed3 + 100 ; protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; line1 -> spd3 = line1 -> spd3 + protect.Signal(); 100 ; } } else if (sema1 == '3' && sema2 == 'w') { if (speed3 == 0) { cout << "This is highest protect.Wait(); line1 -> keyData[0] = '\0'; '\0'; } else { protect.Wait(); line1 -> keyData[0] = '\0'; '\0'; spd3 - 100 ; } else } if (sema1 == '2' && sema2 == 's') { protect.Wait(); p2.Suspend(); line1 -> keyData[0] = line1 -> keyData[1] = protect.Signal(); } else == 's') if (sema1 == '3' && sema2 { protect.Wait(); p3.Suspend(); line1 -> keyData[0] line1 -> keyData[1] protect.Signal(); line1 -> keyData[1] = line1 -> spd3 = line1 -> line1 -> keyData[1] = protect.Signal(); Speed"<< endl; protect.Signal(); '\0'; '\0'; = '\0'; = '\0'; } else sema2 == 'r') if (sema1 == '3' && { protect.Wait(); p3.Resume(); keyData[0] = '\0'; keyData[1] = '\0'; protect.Signal(); } else == '2' && sema2 == 'r') if (sema1 { protect.Wait(); p2.Resume(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else (sema1 == 'x' && sema2 == 'x') if { protect.Wait(); line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else if (sema1 == '2' && sema2 == 'f') line1 -> line1 -> { cout<< "This is FIFO for line for Line 2" << endl; // // sema3 = sema1; sema4 = sema2; protect.Wait(); line1 -> keyData2[0] = '2'; line1 -> keyData2[1] = 'f'; line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else if (sema1 == '2' && sema2 == 'l') { cout<< "This is LIFO for line for Line 2" << endl; // // // protect.Wait(); sema3 = sema1; sema4 = sema2; protect.Wait(); line1 -> keyData2[0] = '2'; line1 -> keyData2[1] = 'l'; line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; // protect.Signal(); protect.Signal(); } else if (sema1 == '2' && sema2 == 'p') { cout<< "This is Priority Algo for Line 2" << endl; // // sema3 = sema1; sema4 = sema2; protect.Wait(); line1 -> keyData2[0] = '2'; line1 -> keyData2[1] = 'p'; line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else if (sema1 == '3' && sema2 == 'p') { cout<< "This is Priority Algo for line for Line 3" << endl; // // sema5 = sema1; sema6 = sema2; protect.Wait(); line1 -> keyData3[0] = line1 -> keyData[0]; line1 -> keyData3[1] = line1 -> keyData[1]; line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else if (sema1 == '3' && sema2 == 'f') { cout<< "This is FIFO for line for Line 3" << endl; // // sema5 = sema1; sema6 = sema2; protect.Wait(); line1 -> keyData3[0] = line1 -> keyData[0]; keyData[1]; line1 -> keyData3[1] = line1 -> line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } else if (sema1 == '3' && sema2 == 'l') { cout<< "This is LIFO for Line 3" << endl; // // sema5 = sema1; sema6 = sema2; protect.Wait(); line1 -> keyData3[0] = line1 -> keyData[0]; keyData[1]; line1 -> keyData3[1] = line1 -> line1 -> keyData[0] = '\0'; line1 -> keyData[1] = '\0'; protect.Signal(); } if (object[0] == 'b') { count2++; ballP.priority = rand()%3000 + 1; ballP.objects[0] = 'b'; TEXT_COLOUR(9,0); cout<< "blue" << " " << count2 << " " <<speed2 << " " << ballP.priority<< endl; pipe2.Write(&ballP,sizeof(ballP)); } else if (object[0] == 'r') { count3++; %3000 + 1; ballQ.priority = rand() TEXT_COLOUR(12,0); cout<< "red" << " " << count3 << " " <<speed3 << " " << ballQ.priority<< endl; ballQ.objects[0] = 'r'; pipe3.Write(&ballQ,sizeof(ballQ)); } // Sleep(1000); } } cout << "Waiting for Line 2 and Line 3 to Finish" << p2.WaitForProcess() ; p3.WaitForProcess() ; cout << "Line 2 and Line 3 are Finished" << endl; getch(); return 0 ; endl; } ...
View Full Document

Ask a homework question - tutors are online