OSY MSBTE CHP 3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Chp 3 (14M)

1. With neat diagram Explain IPC model (it could be any 1)

Ans. Inter-process communication: Cooperating processes require an Inter-process


communication (IPC) mechanism that will allow them to exchange data and information.

There are two models of IPC

1. Shared memory

• In this, all processes who want to communicate with other processes can access a
region of the memory residing in an address space of a process creating a shared
memory segment.
• All the processes using the shared memory segment should attach to the address
space of the shared memory. All the processes can exchange information by reading
and/or writing data in shared memory segment.
• The form of data and location are determined by these processes who want to
communicate with each other.
• These processes are not under the control of the operating system.
• The processes are also responsible for ensuring that they are not writing to the same
location simultaneously.
• After establishing shared memory segment, all accesses to the shared memory
segment are treated as routine memory access and without assistance of kernel.
2. Message Passing

• In this model, communication takes place by exchanging messages between


cooperating processes.
• It allows processes to communicate and synchronize their action without sharing the
same address space.
• It is particularly useful in a distributed environment when communication process may
reside on a different computer connected by a network.
• Communication requires sending and receiving messages through the kernel.
• The processes that want to communicate with each other must have a communication
link between them. Between each pair of processes exactly one communication link.

2. Describe different scheduling criteria

1. CPU utilization: - In multiprogramming the main objective is to keep CPU as busy as


possible. CPU utilization can range from 0 to 100 percent.
2. Throughput: - It is the number of processes that are completed per unit time. It is a
measure of work done in the system. When CPU is busy in executing processes, then
work is being done in the system. Throughput depends on the execution time required
for any process.
3. Turnaround time: - The time interval from the time of submission of a process to the
time of completion of that process is called as turnaround time. It is the sum of time
period spent waiting to get into the memory, waiting in the ready queue, executing with
the CPU, and doing I/O operations.
4. Waiting time: - It is the sum of time periods spent in the ready queue by a process.
When a process is selected from job pool, it is loaded into the main memory. A process
waits in ready queue till CPU is allocated to it.
User level Thread Kernel level Thread
User level threads are implemented by users Kernel level Thread are implemented by OS
Operating system doesn’t recognise user Kernel level Thread are recognised by
level threads Operating system
User level threads are faster to create and Kernel level Thread are slower to create
manage and manage
User level Thread is generic and run on any Kernel level Thread is specific to the
operating system operating system
Implementation is easy Implementation is complicated
Context switch time is less Context switch time is more
6. Explain ‘PS’ command with any four options

Ans. ps command: It is used to display the characteristics of a process. This command


when execute without options, it lists the processes associated with a user at a particular
terminal.

Syntax: $ ps [options]

Example: $ ps

Each line in the output shows PID, the terminal with which the process is associated, the
cumulative processor time that has been consumed since the process has been started
and the process name.

Options:

1. -f : It is used to display full listing of attributes of a process. It includes UID (user


ID),PPID(Parent ID),C(amount of CPU time consumed by the process) and
STIME(chronological time that has elapsed since the process started).

Example: $ ps -f

2. -u: Shows the activities of any specified user at any time.

Example: $ ps -u abc

3. a: It shows the processes of all users.

Example: $ ps -a

4. -e: It displays processes including user and system processes.

Example: $ ps -e
7. State and describe types of scheduler

Ans. There are three types of scheduler:

1. Long term scheduler

A long-term scheduler determines which programs are admitted to the system for
processing. It selects processes from the queue and loads them into memory for
execution. Process loads into the memory for CPU scheduling. The primary objective of the
job scheduler is to provide a balanced mix of jobs, such as I/O bound and processor
bound. It is also called a job scheduler.

2. Short term scheduler

Its main objective is to increase system performance in accordance with the chosen set of
criteria. It is the change of ready state to running state of the process. CPU scheduler
selects a process among the processes that are ready to execute and allocates CPU to one
of them. Short-term schedulers, also known as dispatchers, make the decision of which
process to execute next. Short-term schedulers are faster than long-term schedulers. It is
also called as CPU scheduler.

3. Medium term scheduler

Medium-term scheduling is a part of swapping. It removes the processes from the memory.
It reduces the degree of multiprogramming. The medium-term scheduler is in-charge of
handling the swapped out-processes. A running process may become suspended if it
makes an I/O request.
8. Draw and explain process state diagram.

Ans. Different process states are as follows:

1. New

2. Ready

3. Running

4. Waiting

5. Terminated

New: When a process enters into the system, it is in new state. In this state a process is
created. In new state the process is in job pool.

Ready: When the process is loaded into the main memory, it is ready for execution. In this
state the process is waiting for processor allocation.

Running: When CPU is available, system selects one process from main memory and
executes all the instructions from that process. So,when a process is in execution, it is in
running state. In single user system, only one process can be in the running state. In
multiuser system, there can be multiple processes which are in the running state.

Waiting State: When a process is in execution, it may request for I/O resources. If the
resource is not available, process goes into the waiting state. When the resource is
available, the process goes back to ready state.

Terminated State: When the process completes its execution, it goes into the terminated
state. In this state the memory occupied by the process is released.
9. Define Process. Draw a Process Control Block and explain the Information in PCB

Ans. Process: A process is defined as, a program under execution, which competes for the
CPU time and other resources. A process is a program in execution. Process is also called
as job, task and unit of work.

Process State: It indicates current state of a process. Process state can be new, ready,
running, waiting and terminated.

Process number: Each process is associated with a unique number which is known
process identification number.

Program Counter: It indicates the address of the next instruction to be executed for the
process.

CPU Registers: The registers vary in number and type depending on the computer
architecture. Register includes accumulators, index registers, stack pointers and general
purpose registers plus any condition code information.

Memory Management Information: It includes information such as value of base and limit
registers, page tables, segment tables, depending on the memory system used by OS.

Accounting Information: This information includes the amount of CPU used, time limits,
account holders, job or process number and so on. It also includes information about
listed I/O devices allocated to the process such as list of open files.

Each PCB gives information about a particular process for which it is designed.
10. Explain following commands with their syntax

i. Kill
ii. Sleep
iii. Wait
iv. Exit

Ans. i) kill

Syntax: kill pid

Kill command is used to stop execution of particular process by sending an interrupt signal
to the process

ii) Sleep

Syntax: sleep NUMBER[SUFFIX]

The sleep command pauses the execution for specified time in command.

iii) Wait

Syntax: wait [pid]

Wait command waits for running process to complete and return the exit status.

iv) Exit

Syntax: exit[n]

The terminal window will close and return a status of n


1. *Explain Multithreading model in detail

Ans. Many systems provide support for both user and kernel threads, resulting in different
multithreading models.

Following are three multithreading model:

1. Many-to-One Model
• The many-to-one model maps many user-level threads to one kernel
thread.
• Thread management is done by the thread library in user space, so it is
efficient; but the entire process will block if a thread makes a blocking
system call.
• Also, because only one thread can access the kernel at a time, multiple
threads are unable to nm in parallel on multiprocessors.
2. One-to-One Model
• The one-to-one model maps each user thread to a kernel thread.
• It provides more concurrency than the many-to-one model by allowing
another thread to run when a thread makes a blocking system call; it also
allows multiple threads to run in parallel on multiprocessors.
• The only drawback to this model is that creating a user thread requires
creating the corresponding kernel thread.
• Because the overhead of creating kernel threads can burden the
performance of an application, most implementations of this model
restrict the number of threads supported by the system.
3. Many-to-Many Model
• The many-to-many model multiplexes many user-level threads
to a smaller or equal number of kernel threads.
• The number of kernel threads may be specific to either a particular
application or a particular machine.
• The one-to-one model allows for greater concurrency, but the developer has
to be careful not to create too many threads within an application
• The many-to-many model suffers from neither of these shortcomings:
developers can create as many user threads as necessary, and the
corresponding kernel threads can run in parallel on a multiprocessor.
• Also, when a thread performs a blocking system call, the kernel can
schedule another thread for execution.
2. *Explain user level thread and Kernel level thread with its Advantages and
disadvantages

Ans. User Level Thread

1. In a user thread, all of the work of thread management is done by the application and
the kernel is not aware of the existence of threads.
2. The thread library contains code for creating and destroying threads, for passing
message and data between threads, for scheduling thread execution and for saving and
restoring thread contexts.
3. The application begins with a single thread and begins running in that thread.
4. User level threads are generally fast to create and manage.

• Advantages:Thread switching does not require Kernel mode privileges.


• Disadvantages : Blocking: If a user-level thread blocks due to I/O or other reasons, all
threads in the same process can be blocked, leading to poor utilization of resources.

Kernel Level Threads

1. In Kernel level thread, thread management done by the Kernel.


2. There is no thread management code in the application area.
3. Kernel threads are supported directly by the operating system.
4. Any application can be programmed to be multithreaded.
5. All of the threads within an application are supported within a single process.

• Advantages :Kernel can simultaneously schedule multiple threads from the same
process on multiple process.
• Disadvantages: Kernel threads are generally slower to create and manage than the
user threads.

3. *Writer the outputs of following commands


(i) Wait 2385018 (ii) Sleep 09 (iii) PS –u Asha

Ans. i) Wait command waits until the termination of specified process ID 2385018

ii) Sleep command is used to delay for 9 seconds during the execution of a processi.e. it
will pause the terminal for 9 seconds.

iii) ps command with -u is used to display data/processes for the specific user Asha.
4. *Differentiate between process and thread (any two Points). Also Discuss the
benefits of multithreaded programming

Benefits of Multithreading:

Responsiveness: Multithreading an interactive application may allow a program to


continue running even if part of it is blocked or is performing a lengthy operation, thereby
increasing responsiveness to the user.

Resource sharing: Processes may only share resources through techniques such as
shared memory or message passing. Such techniques must be explicitly arranged by the
programmer. However, threads share the memory and the resources of the process to
which they belong by default

Economy: Allocating memory and resources for process creation is costly. Because
threads share the resources of the process to which they belong, it is more economical to
create and context-switch threads.

Scalability: The benefits of multithreading can be greatly increased in a multiprocessor


architecture, where threads may be running in parallel on different processors. A single-
threaded process can only run on one processor, regardless how many are available.
Multithreading on a multi-CPU machine increases parallelism.

You might also like