Osy Chapter 03
Osy Chapter 03
Osy Chapter 03
Process
A running instance of a program is called as a process
A process is defined as “an entity which represents the basic unit of work to
be implemented in the system” OR “a program under execution, which
competed for the CPU time and other resources”
Process States:
In a Multiprogramming system, many processes are executed by the OS. But
at any instance of time, only one process executes at a time other processes
will wait for their turn
The current activity of a process is known as its state. As the process
executes its changes the states
The following figure shows the process state diagram it represents the
different states in which a process can be at different time,along with the
transitions from one state to another that are possible in OS.
New state: A process that has just been created but has not been admitted to
the pool of execution processes by the OS.Every new operation which is
requested to the system is known as the new born process.
Ready state: When the process is ready to execute but it is waiting for the
CPU to execute then it is called as the ready state.The processes which are
ready for the execution and reside in the main memory are called ready state
processes.
Running state:The process that is currently being executed is present in the
running state. One of the processes from the ready state will be chosen by
the OS depending upon the scheduling algorithm. Hence, if we have only one
CPU in our system, the number of running processes for a particular time
will always be one. If we have n processors in the system then we can have n
processes running simultaneously.
Waiting or Blocked:When a process waits for a certain resource to be
assigned or for the input from the user then the OS move this process to the
block or wait state and assigns the CPU to the other processes.
Terminated state:The OS moves a process from running state to terminated
state if the process finishes execution or if it aborts.Whenever the execution
of a process is completed in running state, it will exit to terminate state,
which is the completion of process.
1. Process state: The state may be new, ready and halted and running, and
waiting and so on.
2. Program counter: The counter shows the address of the next instruction to
be executed for such process.
3. CPU registers: The registers vary in number and category, depending upon
the computer architecture. They contain accumulators, stack pointers, index
registers and general- purpose registers, plus some condition-code
information.
7. I/O status information: The information contains the list of I/O devices
allocated to such process, a list of open files etc
Operation on Processes:
Process creation:
Processes need to be created in the system for different operations. This can be
done by the following events −
Schedulers:
Switching the CPU from one process to another process requires saving the
state of the old process and loading the save state for the new process.This
task is known as context switch
Context switching enables all processes to share a single CPU to finish their
execution and store the status of the system’s tasks.
1. One process does not directly switch to another within the
system. Context switching makes it easier for the operating system to use
the CPU’s resources to carry out its tasks and store its context while
switching between multiple processes.
When switching perform in the system, it stores the old running process's
status in the form of registers and assigns the CPU to a new process to
execute its tasks.
While a new process is running in the system, the previous process must
wait in a ready queue. The execution of the old process starts at that point
where another process stopped it.
Example of Context Switching
Suppose that multiple processes are stored in a Process Control Block (PCB). One
process is running state to execute its task with the use of CPUs. As the process is
running, another process arrives in the ready queue, which has a high priority of
completing its task using CPU. Here we used context switching that switches the
current process with the new process requiring the CPU to finish its tasks. While
switching the process, a context switch saves the status of the old process in
registers. When the process reloads into the CPU, it starts the execution of the
process when the new process stops the old process. If we do not save the state
of the process, we have to start its execution at the initial level. In this way,
context switching helps the operating system to switch between the processes,
store or reload the process when it requires executing its tasks.
Inter-process Communication(IPC)
Process executing concurrently in the operating system might be either
independent processes or co-operating processes.
Inter-process communication (IPC) is a set of programming interfaces that
allow a programmer to coordinate activities among different program
processes that can run concurrently in an operating system.
Since even a single user request may result in multiple processes running in
the operating system on the user’s behalf, the processes need to
communicate with each other.The IPC make this possible.
The IPC is a set of techniques for the exchange of data among multiple
processes
IPC enables one application to control another application, and for several
applications to share the same data without interfering with one another.
Purpose of IPC: Data transfer,sharing data,event notification, Resources
sharing and synchronization and process control
THREADS
User Threads:
The threads implemented at the user level are known as user threads.In
user level thread, thread management is done by the application; the kernel
is not aware of existence of threads.
User threads are supported above the kernel and are implemented by a
thread library at the user level.
User level threads are generally fast to create and manage as there is no
interference of kernel is involved.
Advantages:
1.User level thread can run on any operating system
2.It does not required modification in the OS
3.User thread library is easy to portable.
4.User level thread are fast to create and manage
Disadvantages:
Multithreaded applications in user-level threads cannot use multiprocessing
to their advantage.
The entire process is blocked if one user-level thread performs blocking
operation.
Kernel Threads:
The threads implemented at kernel level are known as kernel threads.
Kernel threads are generally slower to create and manage because thread
maangement is done by OS
Advantages:
Multiple threads of the same process can be scheduled on different
processors in kernel-level threads.
If a kernel-level thread is blocked, another thread of the same process can be
scheduled by the kernel.
Disadvantages:
A mode switch to kernel mode is required to transfer control from one
thread to another in a process.
Kernel-level threads are slower to create as well as manage as compared to
user-level threads.
Multithreading:
A multithreaded program contains two or more parts of the program that
can run concurrently.
Each part of such a program is called a thread and each thread defines a
separate path of excecution.
Multithreading is a process of executing multiple threads simultaneously.
Multithreading Models:
One-to-One Model:
Many-to-One Model:
In this model, multiple user threads are mapped to one single kernel thread.
In this model when a user thread makes a blocking system call entire
process blocks.
Only one thread can access the kernel at a time, multiple threads are unable
to run in parallel on multiprocessors.
Advantages:
Totally portable
One kernel thread controls multiple user threads
Disadvantages:
Cannot perform parallel processing
One block call blocks all user threads
Many-to-Many Model:
In this type of model, there are several user-level threads and several kernel-
level threads.
The number of kernel threads may be specific to either a particular
application or a particular machine
Advanatages:
Many threads can be created as per user’s requirement
Multiple kernel or equal to user threads can be created
Disadvanatges:
Overhead for Operating system
Performance and management is less.