operating system module
operating system module
MODULE 1
1. What is PCB?
A process control block (PCB) is a data structure used by computer operating
systems to store all the information about a process
2. What is time sharing operating system?
Start
This is the initial state when a process is first started/created.
Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have the
processor allocated to them by the operating system so that they can run. Process may come into this
state after Start state or while running it by but interrupted by the scheduler to assign CPU to some
other process.
Running
Once the process has been assigned to a processor by the OS scheduler, the process state is set to
running and the processor executes its instructions.
Waiting
Process moves into the waiting state if it needs to wait for a resource, such as waiting for user input,
or waiting for a file to become available.
Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating system, it is moved to the
terminated state where it waits to be removed from main memory.
When the first electronic computer was developed in 1940, it was created without any
operating system. In early times, users have full access to the computer machine and
write a program for each task in absolute machine language. The programmer can
perform and solve only simple mathematical calculations during the computer generation,
and this calculation does not require an operating system.
The first operating system (OS) was created in the early 1950s and was known
as GMOS. General Motors has developed OS for the IBM computer. The second-
generation operating system was based on a single stream batch processing system
because it collects all similar jobs in groups or batches and then submits the jobs to the
operating system using a punch card to complete all jobs in a machine. At each
completion of jobs (either normally or abnormally), control transfer to the operating
system that is cleaned after completing one job and then continues to read and initiates
the next job in a punch card. After that, new machines were called mainframes, which
were very big and used by professional operators.
During the late 1960s, operating system designers were very capable of developing a new
operating system that could simultaneously perform multiple tasks in a single computer
program called multiprogramming. The introduction of multiprogramming plays a very
important role in developing operating systems that allow a CPU to be busy every time
by performing different tasks on a computer at the same time. During the third
generation, there was a new development of minicomputer's phenomenal growth starting
in 1961 with the DEC PDP-1. These PDP's leads to the creation of personal computers in
the fourth generation.
The fourth generation of operating systems is related to the development of the personal
computer. However, the personal computer is very similar to the minicomputers that were
developed in the third generation. The cost of a personal computer was very high at that
time; there were small fractions of minicomputers costs. A major factor related to
creating personal computers was the birth of Microsoft and the Windows operating
system. Microsoft created the first window operating system in 1975. After introducing
the Microsoft Windows OS, Bill Gates and Paul Allen had the vision to take personal
computers to the next level. Therefore, they introduced the MS-DOS in 1981; however, it
was very difficult for the person to understand its cryptic commands. Today, Windows
has become the most popular and most commonly used operating system technology.
And then, Windows released various operating systems such as Windows 95, Windows
98, Windows XP and the latest operating system, Windows 7. Currently, most Windows
users use the Windows 10 operating system. Besides the Windows operating system,
Apple is another popular operating system built in the 1980s, and this operating system
was developed by Steve Jobs, a co-founder of Apple. They named the operating system
Macintosh OS or Mac OS.
Now, let us see how it implements mutual exclusion. Let there be two processes P1 and P2 and a
semaphore s is initialized as 1. Now if suppose P1 enters in its critical section then the value of
semaphore s becomes 0. Now if P2 wants to enter its critical section then it will wait until s > 0,
this can only happen when P1 finishes its critical section and calls V operation on semaphore s.
This way mutual exclusion is achieved. Look at the below image for details which is Binary
semaphore.
6. What is deadlock? Explain necessary condition and sufficient conditions for the
occurrence of deadlock.
A process in operating systems uses different resources and uses resources in the following
way.
1)Requests a resource
2) Use the resource
2) Releases the resource
Deadlock is a situation where a set of processes are blocked because each process is
holding a resource and waiting for another resource acquired by some other process.
Consider an example when two trains are coming toward each other on the same track and
there is only one track, none of the trains can move once they are in front of each other. A
similar situation occurs in operating systems when there are two or more processes that
hold some resources and wait for resources held by other(s). For example, in the below
diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by
process 2, and process 2 is waiting for resource 1.
Deadlock can arise if the following four conditions hold simultaneously (Necessary
Conditions)
Mutual Exclusion: One or more than one resource are non-shareable (Only one process
can use at a time)
Hold and Wait: A process is holding at least one resource and waiting for resources.
No Preemption: A resource cannot be taken from a process unless the process releases the
resource.
Circular Wait: A set of processes are waiting for each other in circular form.
Methods for handling deadlock
There are three ways to handle deadlock
1) Deadlock prevention or avoidance: The idea is to not let the system into a deadlock
state.
One can zoom into each category individually, Prevention is done by negating one of above
mentioned necessary conditions for deadlock.
Avoidance is kind of futuristic in nature. By using strategy of “Avoidance”, we have to
make an assumption. We need to ensure that all information about resources which process
will need are known to us prior to execution of the process. We use Banker’s algorithm
(Which is in-turn a gift from Dijkstra) in order to avoid deadlock.
2) Deadlock detection and recovery: Let deadlock occur, then do preemption to handle it
once occurred.
3) Ignore the problem altogether: If deadlock is very rare, then let it happen and reboot
the system. This is the approach that both Windows and UNIX take.
Time-sharing enables many people, located at various terminals, to use a particular computer
system at the same time. Multitasking or Time-Sharing Systems is a logical extension of
multiprogramming. Processor’s time is shared among multiple users simultaneously is termed as
time-sharing.
The main difference between Time-Sharing Systems and Multiprogrammed Batch Systems is
that in case of Multiprogrammed batch systems, the objective is to maximize processor use,
whereas in Time-Sharing Systems, the objective is to minimize response time.
Multiple jobs are implemented by the CPU by switching between them, but the switches occur so
frequently. So, the user can receive an immediate response. For an example, in a transaction
processing, the processor executes each user program in a short burst or quantum of
computation, i.e.; if n users are present, then each user can get a time quantum. Whenever the
user submits the command, the response time is in few seconds at most.
An operating system uses CPU scheduling and multiprogramming to provide each user with a
small portion of a time. Computer systems which were designed primarily as batch systems have
been modified to time-sharing systems.
Advantages of Timesharing operating systems are −
Deadlock Detection
1. If resources have single instance:
In this case for Deadlock detection we can run an algorithm to check for cycle in the
Resource Allocation Graph. Presence of cycle in the graph is the sufficient condition for
deadlock.
In the above diagram, resource 1 and resource 2 have single instances. There is a cycle R1
→ P1 → R2 → P2. So, Deadlock is Confirmed.
2. If there are multiple instances of resources:
Detection of the cycle is necessary but not sufficient condition for deadlock detection, in
this case, the system may or may not be in deadlock varies according to different
situations.
Deadlock Recovery
A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is time
and space consuming process. Real-time operating systems use Deadlock recovery.
Recovery method
1. Killing the process: killing all the process involved in the deadlock. Killing process one
by one. After killing each process check for deadlock again keep repeating the process till
system recover from deadlock.
2. Resource Preemption: Resources are preempted from the processes involved in the
deadlock, preempted resources are allocated to other processes so that there is a possibility
of recovering the system from deadlock. In this case, the system goes into starvation.
14. With a neat diagram explain process states
The process, from its creation to completion, passes through various states. The
minimum number of states is five.
The names of the states are not standardized although the process may be in one of the
following states during execution.
1. New
A program which is going to be picked up by the OS into the main memory is called a
new process.
2. Ready
Whenever a process is created, it directly enters in the ready state, in which, it waits for
the CPU to be assigned. The OS picks the new processes from the secondary memory and
put all of them in the main memory.
The processes which are ready for the execution and reside in the main memory are
called ready state processes. There can be many processes present in the ready state.
3. Running
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.
4. Block or wait
From the Running state, a process can make the transition to the block or wait state
depending upon the scheduling algorithm or the intrinsic behavior of the process.
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.
5. Completion or termination
When a process finishes its execution, it comes in the termination state. All the context of the
process (Process Control Block) will also be deleted the process will be terminated by the
Operating system.
6. Suspend ready
A process in the ready state, which is moved to secondary memory from the main
memory due to lack of the resources (mainly primary memory) is called in the suspend
ready state.
If the main memory is full and a higher priority process comes for the execution then the
OS have to make the room for the process in the main memory by throwing the lower
priority process out into the secondary memory. The suspend ready processes remain in
the secondary memory until the main memory gets available.
7. Suspend wait
Instead of removing the process from the ready queue, it's better to remove the blocked
process which is waiting for some resources in the main memory. Since it is already
waiting for some resource to get available hence it is better if it waits in the secondary
memory and make room for the higher priority process. These processes complete their
execution once the main memory gets available and their wait is finished.
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
Memory Management
Processor Management
In multiprogramming environment, the OS decides which process gets the processor when and
for how much time. This function is called process scheduling. An Operating System does the
following activities for processor management −
• Keeps tracks of processor and status of process. The program responsible for this task is
known as traffic controller.
• Allocates the processor (CPU) to a process.
• De-allocates processor when a process is no longer required.
Device Management
An Operating System manages device communication via their respective drivers. It does the
following activities for device management −
• Keeps tracks of all devices. Program responsible for this task is known as the I/O
controller.
• Decides which process gets the device when and for how much time.
• Allocates the device in the efficient way.
• De-allocates devices.
File Management
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions.
An Operating System does the following activities for file management −
• Keeps track of information, location, uses, status etc. The collective facilities are often
known as file system.
• Decides who gets the resources.
• Allocates the resources.
• De-allocates the resources.
Following are some of the important activities that an Operating System performs −
• Security − By means of password and similar other techniques, it prevents unauthorized
access to programs and data.
• Control over system performance − Recording delays between request for a service
and response from the system.
• Job accounting − Keeping track of time and resources used by various jobs and users.
• Error detecting aids − Production of dumps, traces, error messages, and other
debugging and error detecting aids.
• Coordination between other softwares and users − Coordination and assignment of
compilers, interpreters, assemblers and other software to the various users of the
computer systems.
NO DEADLOCK:
Deadlock: Prevention
1. break mutual exclusion:
2. read-only files are shareable
3. but some resources are intrinsically nonshareable (printers)
4. break hold and wait:
5. request all resources in advance
6. request (tape, disk, printer) 7. release all resources before requesting new batch
8. request (tape,disk), release (tape,disk), request (disk,printer)
9. disadvantages: low resource utilization, starvation
19. Explain pcb with neat diagram
A Process Control Block is a data structure maintained by the Operating System for
every process. The PCB is identified by an integer process ID (PID). A PCB keeps all
the information needed to keep track of a process as listed below in the table −
1 Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
2 Process privileges
This is required to allow/disallow access to system resources.
3
Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this process.
6 CPU registers
Various CPU registers where process need to be stored for execution for running state.
9 Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
10 IO status information
This includes a list of I/O devices allocated to the process.
Deadlock Characteristics
deadlock has following characteristics.
1. Mutual Exclusion
2. Hold and Wait
3. No preemption
4. Circular wait
Deadlock Prevention
We can prevent Deadlock by eliminating any of the above four conditions.
• It is very difficult to guess or know the time required for any job to complete. Processors of
the batch systems know how long the job would be when it is in queue
• Multiple users can share the batch systems
• The idle time for the batch system is very less
• It is easy to manage large work repeatedly in batch systems
Disadvantages of Batch Operating System:
• The computer operators should be well known with batch systems
• Batch systems are hard to debug
• It is sometimes costly
• The other jobs will have to wait for an unknown time if any job fails
Examples of Batch based Operating System: Payroll System, Bank Statements, etc.
2. Time-Sharing Operating Systems –
Each task is given some time to execute so that all the tasks work smoothly. Each user gets the
time of CPU as they use a single system. These systems are also known as Multitasking
Systems. The task can be from a single user or different users also. The time that each task gets
to execute is called quantum. After this time interval is over OS switches over to the next task.
Scheduling can be defined as a set of policies and mechanisms which controls the order in
which the work to be done is completed. The scheduling program which is a system software
concerned with scheduling is called the scheduler and the algorithm it uses is called the
scheduling algorithm.
Various criteria or characteristics that help in designing a good scheduling algorithm are:
• CPU Utilization − A scheduling algorithm should be designed so that CPU remains
busy as possible. It should make efficient use of CPU.
• Throughput − Throughput is the amount of work completed in a unit of time. In other
words throughput is the processes executed to number of jobs completed in a unit of
time. The scheduling algorithm must look to maximize the number of jobs processed per
time unit.
• Response time − Response time is the time taken to start responding to the request. A
scheduler must aim to minimize response time for interactive users.
• Turnaround time − Turnaround time refers to the time between the moment of
submission of a job/ process and the time of its completion. Thus how long it takes to
execute a process is also an important factor.
• Waiting time − It is the time a job waits for resource allocation when several jobs are
competing in multiprogramming system. The aim is to minimize the waiting time.
• Fairness − A good scheduler should make sure that each process gets its fair share of the
CPU.
Process State
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
Process privileges
This is required to allow/disallow access to system resources.
Process ID
Unique identification for each of the process in the operating system.
Pointer
A pointer to parent process.
Program Counter
Program Counter is a pointer to the address of the next instruction to be executed for this process.
CPU registers
Various CPU registers where process need to be stored for execution for running state.
Accounting information
This includes the amount of CPU used for process execution, time limits, execution ID etc.
IO status information
This includes a list of I/O devices allocated to the process.
Transparency :
An important goal of a distributed system is to hide the fact that its process and
resources are physically distributed across multiple computers. A distributed system
that is capable of presenting itself to users and applications such that it is only a single
computer system is called transparent.
Openness :
Another important goal of distributed systems is openness. An open distributed system is a
system that offers services in standards that describable the syntax and semantics of those
service instances, standard rules in computer networks control the format, content, and
meaning of messages sent and received. Such rules are formalized in the protocols. In
distributed systems, services are typically specified through interfaces, often called
interface definition languages (IDL). Interface definitions written in IDL almost always
capture only the syntax of services. They accurately specify the names of functions that are
available with the types of parameters, return values, possible exceptions that can be raised
and so on.
Scalability :
The uncertain trend in distributed systems is towards larger systems. This observation has
implications for distributed file system design. Algorithms that work well for systems with
100 machines can work for systems with 1000 machines and none at all for systems with
10, 000 machines. for starters, the centralized algorithm does not scale well. If opening a
file requires contacting a single centralized server to record the fact that the file is open
then the server will eventually become a bottleneck as the system grows.
Reliability :
The main goal of building distributed systems was to make them more reliable than single
processor systems. The idea is that if some machine goes down, some other machine gets
used to it. In other words, theoretically the reliability of the overall system can be a
Boolean OR of the component reliability. For example, with four file servers, each with a
0.95 chance of being up at any instant, the probability of all four being down
simultaneously is 0.000006, so the probability of at least one being available is (1-
0.000006)= 0.999994, far better than any individual server.
Performance :
Building a transparent, flexible, reliable distributed system is useless if it is slow like
molasses. In particular application on a distributed system, it should not deteriorate better
than running some application on a single processor. Various performance metrics can be
used. Response time is one, but so are throughput, system utilization, and amount of
network capacity consumed. Furthermore, The results of any benchmark are often highly
dependent on the nature of the benchmark. A benchmark involves a large number of
independent highly CPU-bound computations which give radically different results than a
benchmark that consists of scanning a single large file for same pattern.
1. Creation
Once the process is created, it will be ready and come into the ready queue (main memory)
and will be ready for the execution.
2. Scheduling
Out of the many processes present in the ready queue, the Operating system chooses one
process and start executing it. Selecting the process which is to be executed next, is known as
scheduling.
3. Execution
Once the process is scheduled for the execution, the processor starts executing it. Process
may come to the blocked or wait state during the execution then in that case the processor
starts executing the other processes.
4. Deletion/killing
Once the purpose of the process gets over then the OS will kill the process. The Context of the
process (PCB) will be deleted and the process gets terminated by the Operating system.