Saturday 25 February 2017

MCA4th Sem /MCS-041/Solved Assignment/Operating Systems/2016-2017 New

Q.1.(i)Draw the Gantt charts illustrating the execution of these processes using the FCFS, SJF, Round Robin (with quantum = 1) and Priority Based Scheduling algorithms.

A.1.(i)

A Process Scheduler schedules different processes to be assigned to the CPU based on particular scheduling algorithms. There are six popular process scheduling algorithms which we are going to discuss in this chapter −

  • First-Come, First-Served (FCFS) Scheduling
  • Shortest-Job-Next (SJN) Scheduling
  • Priority Scheduling
  • Shortest Remaining Time
  • Round Robin(RR) Scheduling
  • Multiple-Level Queues Scheduling

These algorithms are either non-preemptive or preemptive. Non-preemptive algorithms are designed so that once a process enters the running state, it cannot be preempted until it completes its allotted time, whereas the preemptive scheduling is based on priority where a scheduler may preempt a low priority running process anytime when a high priority process enters into a ready state.

(i) First Come First Serve (FCFS)

  • Jobs are executed on first come, first serve basis.
  • It is a non-preemptive, pre-emptive scheduling algorithm.
  • Easy to understand and implement.
  • Its implementation is based on FIFO queue.
  • Poor in performance as average wait time is high.

Gantt Chart :-



(ii)  Shortest Job Next (SJN or SJF)

  • This is also known as shortest job first, or SJF
  • This is a non-preemptive, pre-emptive scheduling algorithm.
  • Best approach to minimize waiting time.
  • Easy to implement in Batch systems where required CPU time is known in advance.
  • Impossible to implement in interactive systems where required CPU time is not known.
  • The processer should know in advance how much time process will take.

  • (iii) Round Robin Scheduling

    • Round Robin is the preemptive process scheduling algorithm.
    • Each process is provided a fix time to execute, it is called a quantum.
    • Once a process is executed for a given time period, it is preempted and other process executes for a given time period.
    • Context switching is used to save states of preempted processes.

    • (iv)Priority Based Scheduling

      • Priority scheduling is a non-preemptive algorithm and one of the most common scheduling algorithms in batch systems.
      • Each process is assigned a priority. Process with highest priority is to be executed first and so on.
      • Processes with same priority are executed on first come first served basis.
      • Priority can be decided based on memory requirements, time requirements or any other resource requirement.

      • Q.1.(ii)Also calculate the average turn around time, average waiting time, processor utilization and throughput for each of the algorithms mentioned in (i).

      • A.1.(ii) FCFS:-
      • (ii)SJF:-

                                    

                                    (iii) Round Robin:-



  • (iv) Priority Based Algorithm:-


Q.2. Consider the following page-reference string: 

1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6

A.2.
 Page replacement algorithms are the techniques using which an Operating System decides which memory pages to swap out, write to disk when a page of memory needs to be allocated. Paging happens whenever a page fault occurs and a free page cannot be used for allocation purpose accounting to reason that pages are not available or the number of free pages is lower than required pages.
When the page that was selected for replacement and was paged out, is referenced again, it has to read in from disk, and this requires for I/O completion. This process determines the quality of the page replacement algorithm: the lesser the time waiting for page-ins, the better is the algorithm.
A page replacement algorithm looks at the limited information about accessing the pages provided by hardware, and tries to select which pages should be replaced to minimize the total number of page misses, while balancing it with the costs of primary storage and processor time of the algorithm itself. There are many different page replacement algorithms. We evaluate an algorithm by running it on a particular string of memory reference and computing the number of page faults.
First In First Out (FIFO) algorithm
  • Oldest page in main memory is the one which will be selected for replacement.
  • Easy to implement, keep a list, replace pages from the tail and add new pages at the head.
  • Optimal Page algorithm
    • An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms. An optimal page-replacement algorithm exists, and has been called OPT or MIN.
    • Replace the page that will not be used for the longest period of time. Use the time when a page is to be used.
    • Least Recently Used (LRU) algorithm

      • Page which has not been used for the longest time in main memory is the one which will be selected for replacement.
      • Easy to implement, keep a list, replace pages by looking back into time.


Q.3.Write a monitor solution to the dinning-philosopher problem.

A.3.The dining philosophers problem is another classic synchronization problem which is used to evaluate situations where there is a need of allocating multiple resources to multiple processes.

Problem Statement:

Consider there are five philosophers sitting around a circular dining table. The dining table has five chopsticks and a bowl of rice in the middle as shown in the below figure.
Dining Philosophers Problem
Dining Philosophers Problem

At any instant, a philosopher is either eating or thinking. When a philosopher wants to eat, he uses two chopsticks - one from their left and one from their right. When a philosopher wants to think, he keeps down both chopsticks at their original place.

Solution:

From the problem statement, it is clear that a philosopher can think for an indefinite amount of time. But when a philosopher starts eating, he has to stop at some point of time. The philosopher is in an endless cycle of thinking and eating.
An array of five semaphores, stick[5], for each of the five chopsticks.

The code for each philosopher looks like:
while(TRUE) {
wait(stick[i]);
wait(stick[(i+1) % 5]);  // mod is used because if i=5, next 
                    // chopstick is 1 (dining table is circular)
/* eat */
signal(stick[i]);
signal(stick[(i+1) % 5]); 
/* think */
}
When a philosopher wants to eat the rice, he will wait for the chopstick at his left and picks up that chopstick. Then he waits for the right chopstick to be available, and then picks it too. After eating, he puts both the chopsticks down.
But if all five philosophers are hungry simultaneously, and each of them pickup one chopstick, then a deadlock situation occurs because they will be waiting for another chopstick forever. The possible solutions for this are:
  • A philosopher must be allowed to pick up the chopsticks only if both the left and right chopsticks are available.
  • Allow only four philosophers to sit at the table. That way, if all the four philosophers pick up four chopsticks, there will be one chopstick left on the table. So, one philosopher can start eating and eventually, two chopsticks will be available. In this way, deadlocks can be avoided.

Q.4.Study and implement the Lamport’s Bakery Algorithm for Interprocess synchronization using C/C++ programming language?

A.4.

The Bakery Algorithm

  • Generalization for n processes.
  • Each process has an id. Ids are ordered.

  • Before entering its critical section, a process receives a number. The holder of the smallest number enters its critical section

  • Tie breaker is done using the process id: if processes i and j hold the same number and i < j then. i enters first.

Introduction

This algorithm solves the critical section problem for n processes in software. The basic idea is that of a bakery; customers take numbers, and whoever has the lowest number gets service next. Here, of course, "service" means entry to the critical section.

Algorithm

 1 var choosing: shared array[0..n-1] of boolean;
 2     number: shared array[0..n-1] of integer;
          ...
 3 repeat
 4     choosing[i] := true;
 5     number[i] := max(number[0],number[1],...,number[n-1]) + 1;
 6     choosing[i] := false;
 7     for j := 0 to n-1 do begin
 8         while choosing[j] do (* nothing *);
 9         while number[j] <> 0 and
10                    (number[j], j) < (number[i],i) do
11              (* nothing *);
12    end;
13    (* critical section *)
14    number[i] := 0;
15    (* remainder section *)
16    until false;


Q.5.Discuss in detail the features, Process management, Memory management, I/O and File management and Security and Protection in Windows 10 Operating System.

A.5. 
An operating system provides the environment within which programs are executed. To construct such an environment, the system is partitioned into small modules with a well defined interface. The design of a new operating system is a major task. It is very important that the goals of the system be will defined before the design begins. The type of system desired is the foundation for choices between various algorithms and strategies that will be necessary.

1 Process Management
The CPU executes a large number of programs. While its main concern is the execution of user programs, the CPU is also needed for other system activities. These activities are called processes. A process is a program in execution. Typically, a batch job is a process. A timeshared user program is a process. A system task, such as spooling, is also a process. For now, a process may be considered as a job or a time-shared program, but the concept is actually more general. In general, a process will need certain resources such as CPU time, memory, files, I/O devices, etc., to accomplish its task. These resources are given to the process when it is created. In addition to the various physical and logical resources that a process obtains when its is created, some initialization data (input) may be passed along. For example, a process whose function is to display on the screen of a terminal the status of a file, say F1, will get as an input the name of the file F1 and execute the appropriate program to obtain the desired information. We emphasize that a program by itself is not a process; a program is a passive entity, while a process is an active entity. It is known that two processes may be associated with the same program, they are nevertheless considered two separate execution sequences. A process is the unit of work in a system. Such a system consists of a collection of processes, some of which are operating system processes, those that execute system code, and the rest being user processes, those that execute user code. All of those processes can potentially execute concurrently. The operating system is responsible for the following activities in connection with processes managed. o The creation and deletion of both user and system processes o The suspension are resumption of processes. o The provision of mechanisms for process synchronization o The provision of mechanisms for deadlock handling.


2 Memory Management 
Memory is central to the operation of a modern computer system. Memory is a large array of words or bytes, each with its own address. Interaction is achieved through a sequence of reads or writes of specific memory address. The CPU fetches from and stores in memory. In order for a program to be executed it must be mapped to absolute addresses and loaded in to memory. As the program executes, it accesses program instructions and data from memory by generating these absolute is declared available, and the next program may be loaded and executed. In order to improve both the utilization of CPU and the speed of the computer's response to its users, several processes must be kept in memory. There are many different algorithms depends on the particular situation. Selection of a memory management scheme for a specific system depends upon many factor, but especially upon the hardware design of the system. Each algorithm requires its own hardware support. The operating system is responsible for the following activities in connection with memory management. o Keep track of which parts of memory are currently being used and by whom. o Decide which processes are to be loaded into memory when memory space becomes available. o Allocate and deallocate memory space as needed.

3 I/O System

 One of the purposes of an operating system is to hide the peculiarities of specific hardware devices from the user. For example, in Unix, the peculiarities of I/O devices are hidden from the bulk of the operating system itself by the I/O system. The I/O system consists of: o A buffer caching system o A general device driver code o Drivers for specific hardware devices. Only the device driver knows the peculiarities of a specific device. We will discuss the I/O system in great length in section 7.

 4 File Management

 File management is one of the most visible services of an operating system. Computers can store information in several different physical forms; magnetic tape, disk, and drum are the most common forms. Each of these devices has it own characteristics and physical organization. For convenient use of the computer system, the operating system provides a uniform logical view of information storage. The operating system abstracts from the physical properties of its storage devices to define a logical storage unit, the file. Files are mapped, by the operating system, onto physical devices. A file is a collection of related information defined by its creator. Commonly, files represent programs (both source and object forms) and data. Data files may be numeric, alphabetic or alphanumeric. Files may be free-form, such as text files, or may be rigidly formatted. In general a files is a sequence of bits, bytes, lines or records whose meaning is defined by its creator and user. It is a very general concept. The operating system implements the abstract concept of the file by managing mass storage device, such as types and disks. Also files are normally organized into directories to ease their use. Finally, when multiple users have access to files, it may be desirable to control by whom and in what ways files may be accessed. The operating system is responsible for the following activities in connection with file management: o The creation and deletion of files o The creation and deletion of directory o The support of primitives for manipulating files and directories o The mapping of files onto disk storage. o Backup of files on stable (non volatile) storage. 

5 Protection System 

The various processes in an operating system must be protected from each other’s activities. For that purpose, various mechanisms which can be used to ensure that the files, memory segment, cpu and other resources can be operated on only by those processes that have gained proper authorization from the operating system. For example, memory addressing hardware ensure that a process can only execute within its own address space. The timer ensure that no process can gain control of the CPU without relinquishing it. Finally, no process is allowed to do it’s own I/O, to protect the integrity of the various peripheral devices. Protection refers to a mechanism for controlling the access of programs, processes, or users to the resources defined by a computer controls to be imposed, together with some means of enforcement. Protection can improve reliability by detecting latent errors at the interfaces between component subsystems. Early detection of interface errors can often prevent contamination of a healthy subsystem by a subsystem that is malfunctioning. An unprotected resource cannot defend against use (or misuse) by an unauthorized or incompetent user.   





No comments:

Post a Comment