CPU Scheduling:592901

Question:

There are several goals of this project.  The first goal is to provide the student with a chance to extend the  course material to a specific application outside of the classroom.  The second goal is to have the class exposed to a diverse group of these applications.

 

The project will consist of creating a simulation of an operating system scheduler handling multiple threads or processes.  The student will create a program that launches 6 – 10 worker threads simulating a processor bound, I/O bound and an intermediate of the two types.  The program will schedule the tasks using the First-Come, First-Served (FCFS), Shortest Job First, and Round Robin scheduling algorithms.  The Program should be written in Java and the Round Robin algorithm should employ the suspend() and resume() thread methods (yes I know the methods are depreciated.  Included as an attachment is a sample). The student will take statistics and will write a paper describing what they found.

 

The paper should be approximately 7 – 10 double-spaced typed pages excluding source code listings, figures,  charts, graphs, and tables.  References are to be included, but not counted as part of  the 7 – 10 pages.  The paper should be a complete description of your project, including: the goals of your project, the approach you used, what you did, the statistics you gathered, what lessons you learned (what did not work as originally expected), and a conclusion. On the other hand, excessively long projects will not be favorably received.

 

Here is homework 3 which he references in the email. Here are his comments about homework 3 (the files attached are related to the assignment to be used a reference).

 

Documentation… place the numbers in a table from all 3 runs… show thread run time for each, overall run time for the scheduler, overall average wait time, and wait time for all CPU bound and all IO bound. Then do the lessons learned from the numbers.

 

Code.. you IO and math threads are good…. except you need a module comment header on each file… author, description, etc.

 

The controllers have a good thought process with the abstract class and arrays…. but have a fatal flaw. Solving it will also simplify the code.

 

With the scheduler you are running only one thread at a time. The scheduler algorithm decides which one to run next. What you have done is start all the threads and have them running concurrently.

 

So… use an array and create all the threads. Then in a for loop iterate though each one…. start the current thread and join to it. Then go to the next.

 

I went to another place to have this done and the site failed miserably. This assignment is a do-over of the final needed to pass this class. The original submission did meet requirements. To get an idea of what the instructor is looking for; I include a screenshot of the email from him. (I cannot upload the homework 3 java files for reference or the original files to the final project that I paid you guys to do)

 

 

The paper should be approximately 7 – 10 double-spaced typed pages excluding source code listings, figures,  charts, graphs, and tables.  References are to be included, but not counted as part of  the 7 – 10 pages.  The paper should be a complete description of your project, including: the goals of your project, the approach you used, what you did, the statistics you gathered, what lessons you learned (what did not work as originally expected), and a conclusion. On the other hand, excessively long projects will not be favorably received.

 

The project will consist of creating a simulation of an operating system scheduler handling multiple threads or processes.  The student will create a program that launches 6 – 10 worker threads simulating a processor bound, I/O bound and an intermediate of the two types.  The program will schedule the tasks using the First-Come, First-Served (FCFS), Shortest Job First, and Round Robin scheduling algorithms.  The Program should be written in Java and the Round Robin algorithm should employ the suspend() and resume() thread methods (yes I know the methods are depreciated.  Included as an attachment is a sample). The student will take statistics and will write a paper describing what they found.

 

The project will consist of creating a simulation of an operating system scheduler handling multiple threads or processes.  The student will create a program that launches 6 – 10 worker threads simulating a processor bound, I/O bound and an intermediate of the two types.  The program will schedule the tasks using the First-Come, First-Served (FCFS), Shortest Job First, and Round Robin scheduling algorithms.  The Program should be written in Java and the Round Robin algorithm should employ the suspend() and resume() thread methods (yes I know the methods are depreciated.  Included as an attachment is a sample). The student will take statistics and will write a paper describing what they found.

Answer:

There are three popular scheduling algorithms which are follows

  • FCFS  is nothing but First Come First-Served  Scheduling
  • SJN is nothing but Shortest Job Next Scheduling
  • RR is nothing but Round Robin Scheduling

In this algorithm highest priority process enter into ready state and run first and low priority suspend and after complete highest priority it will start to run low priority.

First Come First Serve (FCFS)

In First come first serve it   considers priority for first process means first process in queue allocate to CPU. It is depend over FIFO queue. First process enters into ready queue. Process control Block is linked onto tail of queue. When CPU is free then CPU has allocated head process of the queue. The running process should be remove form queue.

This is non-preemptive& pre-emptive scheduling algorithm.

  • Relaxed & simple to understand and execution.
  • Its operation has depended on FIFO queue.
  • Reduced in efficiency when average wait time is high.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Wait time for process as below

Process ID Wait Time = Service Time – Arrival Time
P0 0 – 0 = 0
P1 15 – 1 = 14
P2 18 – 2 = 16
P3 16 – 13 = 2

AWT (Average Wait Time)

AWT= (0+14+16+3) / 4 = 8.25

 

Shortest Job First (SJF)

  • Unbearable to implement & shared systems .It need processing time is unknown.
  • How much time take process should be known by processor

 

 

 

 

 

 

 

Wait time for process as below −

Process Wait Time

WT= Service Time – Arrival Time

P0 13 – 0 = 13
P1 0 – 0 = 0
P2 16 – 3 = 13
P3 18 – 3 = 15

AWT (Average Wait Time)

AWT= (13+0+13+15) / 4 = 10.25

 

Round Robin Scheduling

  • Each process execute in fix time which also called as quantum
  • After complete execution in fix time & preempted then next process start execution in given period of time.
  • States of preempted processes save by Context switching

 

 

 

 

Wait time for process as below −

Process Wait Time (WT)

WT= Service Time – Arrival Time

P0 (0 – 0) + (12 – 11) = 2
P1 (13 – 1) = 12
P2 (16 – 2) + (11 – 9) + (20 – 17) = 19
P3 (19 – 3) + (15 – 12) = 19

AWT (Average Wait Time)

AWT= (2+12+19+19) / 4 = 13

 

 

 

 

CPU Scheduling

CPU Scheduling mean one process execute by processor while another one keep o waiting until resources available like I/O & other resources. This is one for increases utilization of CPU and makes full use processor. System can be made faster, efficient & fair by CPU scheduling.

 

 

 

Scheduling Criteria

Best scheduling algorithm can be check by various criteria’s

  • CPU utilization

Without waste any CPU cycle we can make best use of resources. It should be work 100% of time & increase CPU utilization. It should be 40% in lightly loaded and 90% in heavily loaded.

  • Throughput

Throughput means per unit of time how many process completed or we can say that per unit of time how many wok done. The range will be 10/s to 1/hr. and depends on process

  • Turnaround time

A particular process takes amount of time for process. It is nothing but the time interval for load the process from amount of time takes by process for complete.

  • Waiting time

Waiting time mean show much time spent in ready queue to get control of CPU.

  • Load average

How much process in ready queue waiting for available resources (CPU)

  • Response time

It is amount of time take for produce first response.

Shortest-Job-First (SJF) Scheduling

  • Finest method to reduce waiting time.
  • Processor has already know the actual time which is taken by process
  • Incredible to implement.

 

Priority Scheduling

  • Priority is allocated for every process.
  • Processes with maximum priority are run first & so on.
  • Processes with similar priority run in FCFS fashion.
  • Priority has decided depends on memory necessities, amount of time require .

Round Robin (RR) Scheduling

  • Each process execute in fix time which also called as quantum
  • After complete execution in fix time & preempted then next process start execution in given period of time.
  • States of preempted processes save by Context switching

Multilevel Queue Scheduling

  • Multiple queues are preserved for job.
  • Every queue has own scheduling algorithms.
  • Priorities are allocated for every queue.

Occasionally, suspending the running of a thread is valuable. For example, a discrete thread can be utilized to show the period of day. If worker does not need a watch, then thread can be postponed. At all the case, postponing thread is a modest stuff. Once postponed, resuming the thread is too modest stuff. The mechanisms to postponed restart, and end threads vary among initial versions.

Java suspend Thread

The suspend process of Thread class has condemned by Java 2 few years ago. This has done for the suspend method can now and again cause system failures.

Consider thread has got locks in critical condition. If thread has postponed at that situation, such locks are not resigned. On the other hand threads will be waiting for resources and may create deadlocked.

Resume Thread

The resume () method has condemned. It will not effect and cause serious problem. Résumé method cannot be used without suspend method

Stop Thread

The stop () method has condemned by Java. This method cause serious system failures.

Consider thread has wait for critically significant data structure & has finished only portion of its changes. If thread has stop execution at that situation, data structure may be degraded state. The worry, the stop () origins any lock the running thread& it is holds to be free. Therefore, the degraded data has utilized by another thread and it is waiting for lock

 

Multithreading is nothing but the executing several threads concurrently.

Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking.

Because thread are share common memory we mostly use multithreading than multiprocessing. There no separate area which is use it and save memory &and context-switching among the threads & it will takes short time than job.

Games & animation is mostly use Multithreading.

Advantages of Multithreading

  • By performing many operation together and it help to save time
  • Thread is lightweight and run independent that’s why user does not block and un multiple thread at same time

3) Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking.

Multitasking

Various tasks executing concurrently is called as Multitasking. We can maximum utilize cup by using Multitasking.

Multitasking can be attained by two ways:

  • Process based Multitasking(Multiprocessing)
  • Thread based Multitasking(Multithreading)

1) Process-based Multitasking (Multiprocessing)

  • Every process has its individual address in memory i.e. every process assigns distinct memory area.
  • Process has heavy than thread.
  • Price of message among the processes is maximum.
  • Exchanging from one job to another need time for saving & memory maps, load in registers, editing lists etc.

2) Thread-based Multitasking (Multithreading)

  • Threads segment the similar address space.
  • Thread is light weight than process
  • Price of message among the processes is minimum

Java is object oriented programming language and multi-threading programming language .In multi-threaded program consist of two segment which is run simultaneously and ever segment handle different job. It increase CPU utilization and increase efficiency, make faster and fair

 

Multithreading is nothing but the executing several threads concurrently. Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking. Because thread are share common memory we mostly use multithreading than multiprocessing. There no separate area which is using it and save memory & context-switching among the threads & it will takes short time than job. In multitasking job share common memory for processing resources .In this concept single application divided into sub parts an each parts allocated to thread. Thread is simultaneously and it increase CPU utilization and increase efficiency, make faster and fair. There is separated thread use common memory which save time &context-switching between the threads. It takes short time than other. In Multithreading tread are run parallel which increase execution speed and reduce time for execution. There no separate area which is using it and save memory & context-switching among the threads & it will takes short time than job.

Life Cycle of a Thread

The below diagram you can see the complete life cycle of a thread.

Following are the stages of the life cycle −

  • New–In this phase new thread is born.
  • Runnable–Once new thread start t run it become runnable.
  • Waiting –It is waiting until the completion of another thread.
  • Timed Waiting– A running thread is waiting for specific interval of time.
  • Terminated (Dead)A thread will terminated after complete running

Thread Priorities

Priority is allocated for every process. Processes with maximum priority are run first & so on. Processes with similar priority run in FCFS fashion. Priority has decided depends on memory necessities, amount of time require .MAX_PRIORITY thread allocated first to CPU .All process allocated time before execution. Multithreading is nothing but the executing several threads concurrently. Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking. Because thread are share common memory we mostly use multithreading than multiprocessing. There no separate area which is use it and save memory &and context-switching among the threads & it will takes short time than job. Because thread are share common memory we mostly use multithreading than multiprocessing. There no separate area which is use it and save memory &and context-switching among the threads & it will takes short time than job. In multitasking job share common memory for processing resources .Every process has its individual address in memory i.e. every process assigns distinct memory area. Process has heavy than thread. Price of message among the processes is maximum. Exchanging from one job to another need time for saving & memory maps, load in registers, editing lists. Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking. Process requests the CPU initially and CPU should be allocated first. It is based on queue. Fist process enters into ready queue. Process control Block is linked onto tail of queue. When CPU is free then CPU has allocated head process of the queue. The running process should be remove form queue. There no separate area which is use it and save memory &and context-switching among the threads & it will takes short time than job. In multitasking job share common memory for processing resources .In this concept single application divided into sub parts an each parts allocated to thread. Thread are simultaneously and it increase CPU utilization and increase efficiency, make faster. In First come first serve it   considers priority for first process means first process in queue allocate to CPU. It is depend over FIFO queue. Fist process enters into ready queue. Process control Block is linked onto tail of queue. When CPU is free then CPU has allocated head process of the queue. The running process should be remove form queue. By performing much operation together and it help to save time. Thread is lightweight and run independent that’s why user does not block and multiple threads at same time. Thread is fundamentally a lightweight & smallest unit of dealing out. Multiprocessing and multithreading, both are used for attain multitasking. Because thread are share common memory we mostly use multithreading than multiprocessing. There no separate area which is use it and save memory &and context-switching among the threads & it will takes short time than job.

In below you can see screenshot of Output

First come First Served Sheduling Algorithm

 

Round Robin Algoithm