OSY MSBTE CHP 3
OSY MSBTE CHP 3
OSY MSBTE CHP 3
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
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:
Example: $ ps -f
Example: $ ps -u abc
Example: $ ps -a
Example: $ ps -e
7. State and describe types of 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.
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.
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.
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
Kill command is used to stop execution of particular process by sending an interrupt signal
to the process
ii) Sleep
The sleep command pauses the execution for specified time in command.
iii) Wait
Wait command waits for running process to complete and return the exit status.
iv) Exit
Syntax: exit[n]
Ans. Many systems provide support for both user and kernel threads, resulting in different
multithreading models.
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
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 :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.
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:
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.