Future Vision BIE Future Vision BIE


ONE STOP FOR ALL STUDY MATERIALS & LAB PROGRAMS


E MENU Whatsapp Share Join Telegram, to get Instant Updates
× NOTE! Click on MENU to Browse between Subjects...

Advertisement

18CS43/17CS64 - OPERATING SYSTEMS

4TH & 6TH SEMESTER ISE & CSE

Answer Script for Module 2

Solved Previous Year Question Paper

CBCS SCHEME


OPERATING SYSTEMS

[As per Choice Based Credit System (CBCS) scheme]

(Effective from the academic year 2017 - 2018)

SEMESTER - IV/VI

Subject Code 18CS43/17CS64

IA Marks 40

Number of Lecture Hours/Week 3

Exam Marks 60



Advertisement

These Questions are being framed for helping the students in the "FINAL Exams" Only (Remember for Internals the Question Paper is set by your respective teachers). Questions may be repeated, just to show students how VTU can frame Questions.

- ADMIN


18CS43/17CS64 - OPERATING SYSTEMS

4TH & 6TH SEMESTER ISE & CSE

Answer Script for Module 2



× CLICK ON THE QUESTIONS TO VIEW ANSWER

Answer:

6.1 Monitors

:

An abstract data type-or ADT-encapsulates data with a set of functions to operate on that data that are independent of any specific implementation of the ADT.

A monitor type is an ADT that includes a set of programmer defined operations that are provided with mutual exclusion within the monitor. The monitor type also declares the variables whose values define the state of an instance of that type, along with the bodies of functions that operate on those variables. The monitor construct ensures that only one process at a time is active within the monitor.

6.2 Dining-Philosophers Solution using Monitor:

We now illustrate monitor concepts by presenting a deadlock-free solution to the dining-philosophers problem. This solution imposes the restriction that a philosopher may pick up her chopsticks only if both of them are available.

Monitor with condition variables.

Fig 6.1 Monitor with condition variables.

To code this solution, we need to distinguish among three states in which we may find a philosopher. For this purpose, we introduce the following data structure:

enum {thinking, hungry, eating} stat e [5] ;

Philosopher i can set the variable stat e [i] = eating only if her two neighbours are not eating: (state [(i+4) % 5] != eating) and (state [(i+1) % 5] != eating).

We also need to declare

condition self [5];

where philosopher i can delay herself when she is hungry but is unable to obtain the chopsticks she needs.

We are now in a position to describe our solution to the dining-philosophers problem. The distribution of the chopsticks is controlled by the monitor dp, whose definition is shown in Figure 6.3. Each philosopher, before starting to eat, must invoke the operation pickup( ). This may result in the suspension of the philosopher process.

After the successful completion of the operation, the philosopher may eat. Following this, the philosopher invokes the putdown( ) operation. Thus, philosopher i must invoke the operations pickup( ) and putdown( ) in the following sequence:

ALgorithm

A monitor solution to the dining-philosopher problem.

Fig 6.3 A monitor solution to the dining-philosopher problem.

It is easy to show that this solution ensures that no two neighbours are eating simultaneously and that no deadlocks will occur. We note, however, that it is possible for a philosopher to starve to death. We do not present a solution to this problem but rather leave it as an exercise for you.



Advertisement

Answer:

7.1 Issues with Multithreaded Program:

There are Multiple Issues with Multithreaded Program & are as follows:

i. Semantics of fork() and exec() system calls

ii. Thread cancellation of target thread

iii. Asynchronous or deferred

iv. Signal handling

v. Thread pools

vi. Thread-specific data

vii. Scheduler activations

7.2

Explanation in Detail:

7.2.1 The fork( ) and exec( ) System Calls

The fork( ) system call is used to create a separate, duplicate process.

When a thread program calls fork( ),

The new process can be a copy of the parent, with all the threads

The new process is a copy of the single thread only (that invoked the process)

If the thread invokes the exec( ) system call, the program specified in the parameter to exec( ) will be executed by the thread created.

7.2.2

Cancellation

Terminating the thread before it has completed its task is called thread cancellation. The thread to be cancelled is called

target thread

.

Example: Multiple threads required in loading a webpage is suddenly cancelled, if the browser window is closed.

Threads that are no longer needed may be cancelled in one of two ways:

i.

Asynchronous Cancellation

- cancels the thread immediately.

ii.

Deferred Cancellation

-

the target thread periodically check whether

it has to terminate, thus gives an opportunity to the thread, to terminate itself in an orderly fashion.

7.2.3

Signal Handling

A signal is used to notify a process that a particular event has occurred.

All signals follow same path-

i. A signal is generated by the occurrence of a particular event.

ii. A generated signal is delivered to a process.

iii. Once delivered, the signal must be handled.

A signal can be invoked in 2 ways : synchronous or asynchronous.

i.

Synchronous signal

-

signal delivered to the same program. Eg

-

illegal memory

access, divide by zero error.

ii.

Asynchronous signal

-

signal is sent to another program. Eg

-

Ctrl C

7.2.4

Thread Pools

In multithreading process, thread is created for every service. Eg - In web server, thread is created to service every client request.

Creating new threads every time, when thread is needed and then deleting it when it is done can be inefficient, as -

Time is consumed in creation of the thread.

A limit has to be placed on the number of active threads in the system. Unlimited thread creation may exhaust system resources.

An alternative solution is to create a number of threads when the process first starts, and put those threads into a

thread pool

.

i. Threads are allocated from the pool when a request comes, and returned to the pool when no longer needed(after the completion of request).

ii. When no threads are available in the pool, the process may have to wait until one becomes available.

7.2.5 Thread-Specific Data

i. Data of a thread, which is not shared with other threads is called thread specific data.

ii. Most major thread libraries ( pThreads, Win32, Java ) provide support for thread-specific data.

Example - if threads are used for transactions and each transaction has an ID. This unique ID is a specific data of the thread.

7.2.6

Scheduler Activations

Scheduler Activation is the technique

used

for communication between the user-thread library and the kernel.

It works as follows:

i. the kernel must inform an application about certain events. This procedure is known as an upcall.

ii. Upcalls are handled by the thread library with an upcall handler, and upcall handlers must run on a virtual processor.

Example - The kernel triggers an upcall occurs when an application thread is about to block. The kernel makes an upcall to the thread library informing that a thread is about to block and also informs the specific ID of the thread.


Answer:

Refer 5th Question & Answer or Click Here



Advertisement

Answer:

9.1 FCFS (First Come First Serve):

FCFS (First Come First Serve)

9.2 Premptive SRTF (Shortest Remaining Time First):

Premptive SRTF (Shortest Remaining Time First)

9.3 Non-Premptive SRTF (Shortest Remaining Time First):

Non-Premptive SRTF (Shortest Remaining Time First)

9.4 RR (Round Robin):

RR (Round Robin)


Answer:

Refer 6th Question & Answer or Click Here


× NOTE: Each Page Provides only 5 Questions & Answer
Below Page NAVIGATION Links are Provided...
All the Questions on Question Bank Is SOLVED

Advertisement



lIKE OUR CONTENT SUPPORT US BY FOLLOWING US ON INSTAGRAM : @futurevisionbie

For immediate Notification Join the Telegram Channel



× SUGGESTION: SHARE WITH ALL THE STUDENTS AND FRIENDS -ADMIN