Tuesday 15 October 2013

OS ASSIGNMENT CH-02

OS ASSIGNMENT CH-02
---------------------------------------------------------------------------------------------------------
- GAJJAR PREMAL
Q-3. Answer "Review Questions", pg. 103.
Que- (1) What are three objectives of an OS design?
Ans.- three objectives of an OS are...
. Convenience :
An OS makes a computer more convenient to use.
. Efficiency :
An OS allows the computer system resources to be used in an efficient manner.
. Ability to evolve :
An OS should be developed in a such a way that it is reliable and effective for development,
testing and new system function can be can be added easily in that OS.

Que- (2) What is the kernel of an OS?
Ans.- A Kernel is...
. Central component of Operating System.
. Interface between user application & hardware.
. Manage communication between software & hardware.
Types of Kernels :-
1. Monolithic Kernels
2. Microlithic Kernels

Que- (3) What is multiprogramming?
Ans.-
in earlier time... time require
Read one record from file - 15 micro second.
Execute 100 instructions - 1 micro second.
Write one record to file - 15 micro second.
Total ---------------------------- 31 micro second.
Percentage CPU Utilization = 1/31 = 0.032 = 3.2 %
so, CPU idle much as 95 %
Multiple programs in main memory at the same time. That's call multiprogramming
So, When one job needs to wait for I/O, the processor can switch to the other job.
Example 1 ...
Example 2 ¡¦
Effect of Multiprogram...

Que- (4) What is a process?
Ans.- A Process is ¡¦
. A program in execution .
. An instance of a program running on a computer .
. The entity that can be assigned to and executed on a processor.
Three major lines of computer system development contributed to the development of the concept of
the process:
. multiprogramming batch operation,
processor is switched among various processes for maximum efficiency.
. time sharing,
be able to support many users simultaneously.
. real-time transaction systems.
four main causes of errors in programming -
Improper synchronization: input of processor takes value before buffer collect next data.
Failed mutual exclusion: two user wants to edit same document at same time.
Nondeterminate program operation: result of particular programme depend on current input and
also on other program which are very complexes and are goes into unpredicted stage.
Deadlocks: two programmes are hump up waiting for each other response.

Que- (5) How is the execution context of a process used by the OS?
Ans.- Context is the ¡¦
internal data by which the OS is able to supervise and control the process.
. The context includes all of the information that the OS needs to manage the process and that the
processor needs to execute the process properly.
. The context includes the contents of the various processor registers, such as the program
counter and data registers and information of use to the OS, such as the priority of the process
and whether the process is waiting for the completion of a particular I/O event.
. The process index register - the index into the process list of the process currently controlling
the processor.
. The program counter - points to the next instruction in that process to be executed.
. The base and limit registers define the region in memory occupied by the process.
. The base register is the starting address of the region of memory and the limit is the size of the
region.
Figure shows that process B is executing, A process is temp. interrupted. Contains of all reg. At A's
interruption were recorded in context, when os completed task B and resuming to task A, it stores the
context of B and restoring context of A then resume execution of process A.

Que- (6) List and briefly explain five storage management responsibilities of a typical OS.
Ans.-
five storage management responsibilities of a typical OS are...
. Process isolation: The OS must prevent independent processes from interfering with each
other¡¯s memory, both data and instructions.
. Automatic allocation and management: Programs should be dynamically allo cated across
the memory hierarchy as required. Allocation should be transparent to the programmer. Thus,
the programmer is relieved of concerns relating to memory limitations, and the OS can achieve
efficiency by assigning memory to jobs only as needed.
. Support of modular programming: Programmers should be able to define program modules,
and to create, destroy, and alter the size of modules dynamically.
. Protection and access control: Sharing of memory, at any level of the memory hierarchy,
creates the potential for one program to address the memory space of another. This is desirable
when sharing is needed by particular applications. At other times, it threatens the integrity of
programs and even of the OS itself. The OS must allow portions of memory to be accessible in
various ways by various users.
. Long-term storage: Many application programs require means for storing information for
extended periods of time, after the computer has been powered down.
operating systems meet these requirements with virtual memory and file system facilities.
. The file system implements a long-term store, with information stored in named objects, called
files.

Que- (7) Explain the distinction between a real address and a virtual address.
Ans.-
. The Virtual memory is a facility that allows programs to address memory from a logical point
of view, without regard to the amount of main memory physically available.
. It meet the requirements of having multiple user jobs.
. There would not be a hiatus between the execution of successive processes while one process
was written out to secondary store and the successor process was read in. Because processes
vary in size.
. So, here processor switches among a number of processes, it is difficult to peak it in main
memory.
. Then paging system introduces, that allow process to comprised of no. of fixed size block,
called page. It located anywhere in the main memory.
. Virtual address consist of page number & offset within page.
. Paging system provides for dynamic mapping between the virtual address used in main
programme and real address in main memory.

Que- (8) Describe the round-robin scheduling technique.
Ans.-
The short-term queue consists of processes that are in main memory (or at least an essential minimum
portion of each is in main memory) and are ready to run as soon as the processor is made available
A common strategy is to give each process in the queue some time in turn; this is referred to as a
round-robin technique.

Que- (9) Explain the difference between a monolithic kernel and a micro kernel.
Ans.-
1. Monolithic Kernels
. All OS services operate in kernel space
Advantages -
. Good performance
Disadvantages -
. Dependencies between system component (same address space provided)
. Complex & huge (millions of lines of code)
. Larger size makes it hard to maintain
E.g.- Multics, Unix, Linux
2. Microlithic Kernels
. assign only few functions
i. IPC (interprocess communication)
ii. virtual memory
iii. thread scheduling
Put the rest into user space (Device drivers, networking, file system, user interface)
Advantages -
. More stable with less services in kernel space
Disadvantages -
. Lots of system calls and context switches
E.g. Mach, L4, Minix, K42

Que- (10) What is multithreading?
Ans.-
Multithreading is a ¡¦
. technique in which a process, executing an application, is divided into threads that can run
concurrently.
. A dispatchable unit of work.
. It includes a processor context (which includes the program counter and stack pointer) and its
own data area for a stack (to enable subroutine branching).
. A thread executes sequentially and is interrupt able so that the processor can turn to another
thread.
. perform a number of essentially independent tasks that do not need to be serialized.
. An example is a database server.
4. Answer the following Problems:

2.1, 2.2, 2.4
Que- (2.1)
Suppose that we have a multiprogrammed computer in which each job has identical
characteristics. In one computation period, T, for a job, half the time is spent in I/O and the other
half in processor activity. Each job runs for a total of N periods. Assume that a simple
round-robin scheduling is used, and that I/O operations can overlap with processor operation.
Define the following quantities:
. Turnaround time = actual time to complete a job
. Throughput = average number of jobs completed per time period T
. Processor utilization = percentage of time that the processor is active (not waiting)
Compute these quantities for one, two, and four simultaneous jobs, assuming that the
period T is distributed in each of the following ways:
a. I/O first half, processor second half
b. I/O first and fourth quarters, processor second and third quarter
Ans.-
a. )
1. FOR 1 SIMULTANEOUS
Turn Around Time = Total Periods * Computation Time
= N*T
Now in case of 1 ,
processor sits idle for half of its allotted time,
Processor utilization = 50%
2. FOR 2 SIMULTANEOUS
Turn Around Time = N*T
Processor utilization = 100%
FOR 4 SIMULTANEOUS
Turn Around Time = (2N . 1) * T
Processor utilization = 100%
b)
Same as previous part,
1 Job TA Time = NT Processor utilization = 50%
2 Jobs TA Time = NT Processor utilization = 100%
4 Jobs TA Time = (2N . 1)*T Processor utilization = 100%

Que- (2.2)
An I/O-bound program is one that, if run alone, would spend more time waiting for I/O than
using the processor. A processor-bound program is the opposite.
Suppose a short-term scheduling algorithm favors those programs that have used little processor
time in the recent past. Explain why this algorithm favors I/O-bound programs.
Ans.
I/O . bound program Is spend more time waiting for I/O at starting programme and
takes less time for process upon the I/O at past of programme.
And short-term scheduling algorithm perform same work as required by I/O process that it used
little time in resent past of processor . So algorithm favors I/O-bound programs.

Que- (2.4)
What is the purpose of system calls, and how do system calls relate to the OS and to
the concept of dual-mode (kernel mode and user mode) operation?
Ans.
A system call is used by an application program to invoke a function provided by the
operating system.
The system call is the means by which a process requests a specific kernel service.
Seven Categories of System Calls
1. File system,
2. Process,
3. Scheduling,
4. Inter process
5. Communication,
6. Socket (networking) and
7. Miscellaneous
OS is an interface in between of user and computer hardware, Whereas system call is
interface in between of user mode processes & kernel (system) mode processes

7. Answer "Review Questions", pg. 153.
Que- (1) What is an instruction trace?
Ans.-
. Instruction trace is used to store/display the sequence of all executed instructions
. Due to the limited size of the trace buffer, it is not possible to record a very long
sequence of instructions in real time.

Que- (2) What common events lead to the creation of a process?
Ans.-
Que- (3) For the processing model of Figure 3.6, briefly define each state.
Ans.-
. Running: The process that is currently being executed. For this chapter, we will assume a
computer with a single processor, so at most one process at a time can be in this state.
. Ready: A process that is prepared to execute when given the opportunity.
. Blocked/Waiting: A process that cannot execute until some event occurs, such as the
completion of an I/O operation.
. New: A process that has just been created but has not yet been admitted to the pool of
executable processes by the OS. Typically, a new process has not yet been loaded into main
memory, although its process control block has been created.
. Exit: A process that has been released from the pool of executable processes by the OS, either
because it halted or because it aborted for some reason.

Que- (4) What does it mean to preempt a process?
Ans.
. A process is returning from kernel to user mode, but the kernel blocks it and prepares
process switch to schedule another process. This is called preempting of process.
. It is happens when the current process is in blocked state & other process is ready and of higher
priority

Que- (5) What is swapping and what is its purpose?
Ans.
. When the physical memory in the system runs out and a process needs to bring a page into
memory then the operating system must decide what to do.
. It must fairly share the physical pages in the system between the processes running
in the system, therefore it may need to remove one or more pages from the system to make
room for the new page to be brought into memory.
. How virtual pages are selected for removal from physical memory affects the
efficiency of the system.
. This scheme involves every page in the system having an age which changes as the
page is accessed.
. The more that a page is accessed, the younger it is; the less that it is accessed the older it
becomes. Old pages are good candidates for swapping.
. Purpose: The purpose of swapping, or paging, is to access data being stored in hard disk and to
bring it into the RAM so that it can be used by the application program.
. Remember that swapping is only necessary when that data is not already in the RAM.

Que- (6) Why does Figure 3.9b have two blocked states?
Ans.
In figure 3.9, there are two suspended states instead of one suspended state. So, there are
two blocked states in fig. 3.9.
Blocked: The process is in main memory and awaiting an event.
Blocked/Suspend: The process is in secondary memory and awaiting an event.

Que- (7) List four characteristics of a suspended process.
Ans.
Four characteristics of suspended process are listed below.
. The process is not immediately available for execution.
. The process may or may not be waiting on an event. If it is, this blocked condition is
independent of the suspend condition, and occurrence of the blocking event does not enable the
process to be executed immediately.
. The process was placed in a suspended state by an agent: either its self a parent
process, or the OS, for the purpose of preventing its execution.
. The process may not be removed from this state until the agent explicitly orders the
removal.

Que- (8) For what types of entities does the OS maintain tables of information for
management purposes?
Ans.
. The OS constructs and maintains tables of information about each entity that it is managing.
Although the details will differ from one OS to another.
. Fundamentally, all operating systems maintain information in these four categories.
A general idea of the scope of this effort is indicated in Figure 3.11, which shows four
different types of tables maintained by the OS:
. Memory
. I/O
. File
. Process.

Que- (9) List three general categories of information in a process control block.
Ans.
Process identification: In virtually all operating systems, each process is assigned a
unique numeric identifier, otherwise there must be a mapping that allows the OS to
locate the appropriate tables based on the process identifier. This identifier is useful
in several ways
Process state information: consists of the contents of processor registers. While a
process is running, of course, the information is in the registers. When a process is
interrupted, all of this register information must be saved so that it can be restored
when the process resumes execution.
Process control information: This is the additional information needed by the OS to
control and coordinate the various active processes.

Que- (10) Why are two modes (user and kernel) needed?
Ans.
Kernel mode: In Kernel mode, the executing code has complete and unrestricted
access to the underlying hardware. It can execute any CPU instruction and reference
any memory address. Kernel mode is generally reserved for the lowest-level, most
trusted functions of the operating system. Crashes in kernel mode are catastrophic;
they will halt the entire PC.
User mode: In User mode, the executing code has no ability to directly access
hardware or reference memory. Code running in user mode must delegate to system
APIs to access hardware or memory. Due to the protection afforded by this sort of
isolation, crashes in user mode are always recoverable. Most of the code running on
your computer will execute in user mode.

Que- (11) What are the steps performed by an OS to create a new process?
Ans.
. Assign a unique process identifier to the new process.
. Allocate space for the process.
. Initialize the process control block.
. Set the appropriate linkages.
. Create or expand other data structures.

Que- (12) What is the difference between an interrupt and a trap?
Ans.
interrupts are hardware invoked interrupts, while traps are software-invoked
interrupts.
Occurrences of hardware interrupts usually disable other hardware interrupts, but
this is not true for traps.
If you need to disallow hardware interrupts until a trap is served, you need to
explicitly clear the interrupt flag. And usually the interrupt flag on the computer
affects (hardware) interrupts as opposed to traps.
This means that clearing this flag will not prevent traps. Unlike traps, interrupts
should preserve the previous state of the CPU.

Que- (13) Give three examples of an interrupt.
Ans.
Clock interrupt: The OS determines whether the currently running process has been
executing for the maximum allowable unit of time, referred to as a time slice. That
is, a time slice is the maximum amount of time that a process can execute before
being interrupted.
I/O interrupt: The OS determines what I/O action has occurred. If the I/O action
constitutes an event for which one or more processes are waiting, then the OS
moves all of the corresponding blocked processes to the Ready state.
Memory fault: The processor encounters a virtual memory address reference for a
word that is not in main memory.

Que- (14) What is the difference between a mode switch and a process switch?
Ans.
process switch is switch the process state between the statuses like read, blocked,
suspend.
Mode switch is the switch the process privilege between the mode like use mode,
kernel mode. Generally a mode switch is considered less expensive compared to a
process switch.

PROBLEMS
Q.1 Name five major activities of an OS with respect to process management, and briefly
describe why each is required.
Ans:
The following are the major activities of an OS w.r.t. to process management
1. Creation and deletion of both user and system processes
The processes in the system can execute concurrently for information sharing,
computation speedup, modularity, and convenience.
Concurrent execution requires a mechanism for process creation and deletion. The
required resources are given to the process when it is created, or allocated to it
while it is running. When the process terminates, the OS needs to reclaim any
reusable resources.
2. Suspension and resumption of processes
In process scheduling, the OS needs to change the process's state to waiting or
ready state when it is waiting for some resources. When the required resources are
available, OS needs to change its state to running state to resume its execution.
3. Provision of mechanism for process synchronization
Cooperating processes may share data. Concurrent access to shared data may
result in data inconsistency. OS has to provide mechanisms for processes
synchronization to ensure the orderly execution of cooperating processes, so that
data consistency is maintained.
4. Provision of mechanism for process communication
The processes executing under the OS may be either independent processes or
cooperating processes. Cooperating processes must have the means to
communicate with each other.
5. Provision of mechanisms for deadlock handling
In a multiprogramming environment, several processes may compete for a finite
number of resources. If a deadlock occurs, all waiting processes will never change
their waiting state to running state again, resources are wasted and jobs will never
be completed.

Q. 2 Consider a computer with N processors in a multiprocessor configuration.
1. How many processes can be in each of the Ready, Running, and Blocked states at
one time?
2. What is the minimum number of processes that can be in each of the Ready,
Running, and Blocked states at one time?
Ans:
There can be N processes in running state. The number of processes in ready and
blocked state depends on the size of "ready list" and "blocked list".
The minimum number of processes can be 0, if the system is idle and there are no
blocked jobs or no ready jobs.

Q.3 In [PINK89], the following states are defined for processes: Execute (running), Active
(ready), Blocked, and Suspend. A process is blocked if it is waiting for permission to
use a resource, and it is suspended if it is waiting for an operation to be completed on
a resource it has already acquired. In many operating systems, these two states are
lumped together as the blocked state, and the suspended state has the definition we
have used in this chapter. Compare the relative merits of the two sets of definitions.
Ans:
Concept of Blocked state: A process is put in the Blocked state if it requests something for
which it must wait.
Merit of Blocked State: The blocked state allow continuous execution of another
process for which OS is prepared.
For example, a process may request a service from the OS that the OS is not
prepared to perform immediately. It can request a resource, such as a file or a
shared section of virtual memory that is not immediately available
Concept of Suspended state: In a uni-programming I/O activities are much slower than
computation and therefore the processor and hence system is idle most of the time. But
the arrangement of multiple block queue does not entirely solve the problem.
It is true that, in this case, memory holds multiple processes and that the processor can
move to another process when one process is blocked. But the processor is so much faster
than I/O that it will be common for all of the processes in memory to be waiting for I/O.
Thus, even with multiprogramming, a processor could be idle most of the time.
Solution:
1. Main memory could be expanded to accommodate more processes. But there are
two flaws in this approach.
There is a cost associated with main memory, which, though small on a per-byte
basis, begins to add up as we get into the gigabytes of storage.
The appetite of programs for memory has grown as fast as the cost of memory has
dropped. So larger memory results in larger processes, not more processes.
2. Another solution is swapping, which involves moving part or all of a process from
main memory to disk. When none of the processes in main memory is in the Ready
state, the OS swaps one of the blocked processes out onto disk into a suspend
queue. This is a queue of existing processes that have been temporarily kicked out
of main memory, or suspended. The OS then brings in another process from the
suspend queue. Execution then continues with the newly arrived process.
Merit of Suspended State: When all of the processes in main memory are in the
Blocked state, the OS can suspend one process by putting it in the Suspend state
and transferring it to disk. The space that is freed in main memory can then be used
to bring in another process.

Q.4 In Section 3.4, it was stated that UNIX is unsuitable for real-time applications
because a process executing in kernel mode may not be pre-empt. Elaborate.
Ans:
Real-time operating systems can be characterized as having unique requirements in five
general areas:
Determinism
Responsiveness
User control
Reliability
Fail-soft operation
Concept of Pre-emption in UNIX:
When a process is running in kernel mode (as a result of a supervisor call, clock
interrupt, or I/O interrupt), there will come a time when the kernel has completed
its work and is ready to return control to the user program.
At this point, the kernel may decide to pre-empt the current process in favour of
one that is ready and of higher priority. In that case, the current process moves to
the pre-empted state. However, for purposes of dispatching, those processes in the
pre-empted state and those in the Ready to Run, in Memory state form one queue.
Pre-emption can only occur when a process is about to move from kernel mode to
user mode. While a process is running in kernel mode, it may not be pre-empted.
This makes UNIX unsuitable for real-time processing

3 comments:

Anonymous said...

Everythіng is very openn with a very clear clarification of thе chаllengеs.

It was truly informative. Your website is veгy helpful.
Many thanks for sharing!

My site køЬ zippo llighter online (www.nyttigbras.dk)

Anonymous said...

Thanks for the good writeup. It in reality used to be a
enjoyment account it. Glance complicated to more delivered agreeable from you!
By the way, how could we be in contact?

Also visit my web blog - home improvement diy ideas ()

Anonymous said...

Pretty! This has been an extremely wonderful post.
Thank you for supplying this information.

Here is my site: pirater un compte facebook