Operating System Introduction and Process Concepts
Operating System Introduction and Process Concepts
UNIT – I
A computer system has many resources (hardware and software), which may be required to
complete a task. The commonly required resources are input/output devices, memory, file storage
space, CPU, etc. The operating system acts as a manager of the above resources and allocates them
to specific programs and users, whenever necessary to perform a particular task. Therefore the
operating system is the resource manager i.e. it can manage the resource of a computer system
internally. The resources are processor, memory, files, and I/O devices.
In simple terms, an operating system is an interface between the computer user and the machine.
It is very important for you that every computer must have an operating system in order to run other
programs. The operating system mainly coordinates the use of the hardware among the various
system programs and application programs for various users.
An operating system acts similarly like government means an operating system performs no useful
function by itself; though it provides an environment within which other programs can do useful
work.
Below we have an abstract view of the components of the computer system:
2
Types of Operating System
Given below are different types of Operating System:
1. Simple Batch System
2. Multi programmed
3. Time-Shared
4. Personal Computer
5. Parallel
6. Distributed Systems
7. Real Time Systems
Advantages:
1. The overall time taken by the system to execute all the programmes will be reduced.
2. The Batch Operating System can be shared between multiple users.
Disadvantages:
1. Manual interventions are required between two batches.
2. The CPU utilization is low because the time taken in loading and unloading of batches is very
high as compared to execution time.
3
2. Multiprogramming
Sharing the processor, when two or more programs reside in memory at the same time, is referred
as multiprogramming. Multiprogramming assumes a single shared processor. Multiprogramming
increases CPU utilization by organizing jobs so that the CPU always has one to execute. The follow
in figure shows the memory layout for a multiprogramming system.
4
Advantages:
1. Since equal time quantum is given to each process, so each process gets equal opportunity to
execute.
2. The CPU will be busy in most of the cases and this is good to have case.
Disadvantages:
1. Process having higher priority will not get the chance to be executed first because the equal
opportunity is given to each process.
4. Personal Computers
Personal computer operating system provides a good interface to a single user.
Personal computer operating systems are widely used for word processing, spreadsheets and Internet
access.
Personal computer operating system are made only for personal. You can say that your laptops,
computer systems, tablets etc. are your personal computers and the operating system such as
windows 7, windows 10, android, etc. are your personal computer operating system.
And you can use your personal computer operating system for your personal purposes, for example,
to chatting with your friends using some social media sites, reading some articles from internet,
making some projects through Microsoft PowerPoint or any other, designing your website,
programming something, watching some videos and movies, listening to some songs and many
more.
5. Parallel Processing
Parallel processing requires multiple processors and all the processor works simultaneously in
the system. Here, the task is divided into subparts and these subparts are then distributed
among the available processors in the system. Parallel processing completes the job on the
shortest possible time.
All the processors in the parallel processing environment should run on the same operating system.
All processors here are tightly coupled and are packed in one casing. All the processors in the
5
system share the common secondary storage like the hard disk. As this is the first place where the
programs are to be placed.
There is one more thing that all the processors in the system share i.e. the user terminal (from
where the user interact with the system). The user need not to be aware of the inner architecture of
the machine. He should feel that he is dealing with the single processor only and his interaction with
the system would be the same as in a single processor,
Advantages
1. It saves time and money as many resources working together will reduce the time and cut
potential costs.
2. It can be impractical to solve larger problems on Serial Computing.
3. It can take advantage of non-local resources when the local resources are finite.
4. Serial Computing ‘wastes’ the potential computing power, thus Parallel Computing makes better
work of the hardware.
Disadvantages
1. It addresses such as communication and synchronization between multiple sub-tasks and
processes which is difficult to achieve.
2. The algorithms must be managed in such a way that they can be handled in a parallel mechanism.
3. The algorithms or programs must have low coupling and high cohesion. But it’s difficult to
create such programs.
4. More technically skilled and expert programmers can code a parallelism-based program well.
6
6. Distributed Operating System
These types of the operating system is a recent advancement in the world of computer technology
and are being widely accepted all over the world and, that too, with a great pace. Various
autonomous interconnected computers communicate with each other using a shared communication
network. Independent systems possess their own memory unit and CPU. These are referred to as
loosely coupled systems or distributed systems. These system’s processors differ in size and
function. The major benefit of working with these types of the operating system is that it is always
possible that one user can access the files or software which are not actually present on his system
but some other system connected within this network i.e., remote access is enabled within the
devices connected in that network.
It is developed for real-time applications where data should be processed in a fixed, small duration
of time. It is used in an environment where multiple processes are supposed to be accepted and
processed in a short time. RTOS requires quick input and immediate response, e.g., in a petroleum
refinery, if the temperate gets too high and crosses the threshold value, there should be an immediate
response to this situation to avoid the explosion. Similarly, this system is used to control scientific
instruments, missile launch systems, traffic lights control systems, air traffic control systems, etc.
This system is further divided into two types based on the time constraints:
Hard Real-Time Systems:
These are used for the applications where timing is critical or response time is a major factor; even a
delay of a fraction of the second can result in a disaster. For example, airbags and automatic
parachutes that open instantly in case of an accident. Besides this, these systems lack virtual
memory.
Soft Real-Time Systems:
These are used for application where timing or response time is less critical. Here, the failure to
meet the deadline may result in a degraded performance instead of a disaster. For example, video
surveillance (cctv), video player, virtual reality, etc. Here, the deadlines are not critical for every
task every time.
Advantages of real-time operating system:
o The output is more and quick owing to the maximum utilization of devices and system
o Task shifting is very quick, e.g., 3 microseconds, due to which it seems that several tasks are
executed simultaneously
o Gives more importance to the currently running applications than the queued application
o It can be used in embedded systems like in transport and others.
o It is free of errors.
8
o Memory is allocated appropriately.
Disadvantages of real-time operating system:
o A fewer number of tasks can run simultaneously to avoid errors.
o It is not easy for a designer to write complex and difficult algorithms or proficient programs
required to get the desired output.
o Specific drivers and interrupt signals are required to respond to interrupts quickly.
o It may be very expensive due to the involvement of the resources required to work.
An operating system is an interface which provides services to both the user and to the
programs. It provides an environment for the program to execute. It also provides users with the
services of how to execute programs in a convenient manner. The operating system provides some
services to program and also to the users of those programs. The specific services provided by the
OS are off course different.
1) Program Execution
An operating system must be able to load many kinds of activities into the memory and to run it.
The program must be able to end its execution, either normally or abnormally.
A process includes the complete execution of the written program or code. There are some of the
activities which are performed by the operating system:
9
o The operating system Loads program into memory
o It also Executes the program
o It Handles the program’s execution
o It Provides a mechanism for process synchronization
o It Provides a mechanism for process communication
2) I/O Operations
The communication between the user and devices drivers are managed by the operating system.
I/O devices are required for any running process. In I/O a file or an I/O device can be involved.
I/O operations are the read or write operations which are done with the help of input-output
devices.
Operating systems give the access to the I/O devices when it required.
3) File system manipulation
The collection of related information which represent some content is known as a file. The
computer can store files on the secondary storage devices. For long-term storage purpose. examples
of storage media include magnetic tape, magnetic disk and optical disk drives like CD, DVD.
A file system is a collection of directories for easy understand and usage. These directories
contain some files. There are some major activities which are performed by an operating system
with respect to file management.
o The operating system gives an access to the program for performing an operation on the
file.
o Programs need to read and write a file.
o The user can create/delete a file by using an interface provided by the operating system.
o The operating system provides an interface to the user creates/ delete directories.
o The backup of the file system can be created by using an interface provided by the
operating system.
4) Communication
In the computer system, there is a collection of processors which do not share memory peripherals
devices or a clock, the operating system manages communication between all the processes.
Multiple processes can communicate with every process through communication lines in the
network. There are some major activities that are carried by an operating system with respect to
communication.
Two processes may require data to be transferred between the process.
10
Both the processes can be on one computer or a different computer, but are connected through a
computer network.
5) Error handling
An error is one part of the system that may cause malfunctioning of the complete system. The
operating system constantly monitors the system for detecting errors to avoid some situations. This
give relives to the user of the worry of getting an error in the various parts of the system causing
malfunctioning.
The error can occur anytime and anywhere. The error may occur anywhere in the computer system
like in CPU, in I/O devices or in the memory hardware. There are some activities that are performed
by an operating system:
The OS continuously checks for the possible errors.
The OS takes an appropriate action to correct errors and consistent computing.
6) Resource management
When there are multiple users or multiple jobs running at the same time resources must be allocated
to each of them. There are some major activities that are performed by an operating system:
The OS manages all kinds of resources using schedulers.
CPU scheduling algorithm is used for better utilization of CPU.
7) Protection
The owners of information stored in a multi-user computer system want to control its use. When
several disjoints processes execute concurrently it should not be possible for any process to interfere
with another process. Every process in the computer system must be secured and controlled.
Operating system can be implemented with the help of various structures. The structure of the OS
depends mainly on how the various common components of the operating system are
interconnected and melded into the kernel. Depending on this we have following structures of the
operating system:
Simple structure:
Such operating systems do not have well defined structure and are small, simple and limited
systems. The interfaces and levels of functionality are not well separated. MS-DOS is an example
of such operating system. In MS-DOS application programs are able to access the basic I/O
routines. These types of operating system cause the entire system to crash if one of the user
programs fails.
Diagram of the structure of MS-DOS is shown below.
11
Advantages of Simple structure:
It delivers better application performance because of the few interfaces between the application
program and the hardware.
Easy for kernel developers to develop such an operating system.
Disadvantages of Simple structure:
The structure is very complicated as no clear boundaries exists between modules.
It does not enforce data hiding in the operating system.
Layered structure:
An OS can be broken into pieces and retain much more control on system. In this structure the OS
is broken into number of layers (levels). The bottom layer (layer 0) is the hardware and the
topmost layer (layer N) is the user interface. These layers are so designed that each layer uses the
functions of the lower level layers only. This simplifies the debugging process as if lower level
layers are debugged and an error occurs during debugging then the error must be on that layer only
as the lower level layers have already been debugged.
The main disadvantage of this structure is that at each layer, the data needs to be modified and
passed on which adds overhead to the system. Moreover careful planning of the layers is necessary
as a layer can use only lower level layers. UNIX is an example of this structure.
12
Advantages of Layered structure:
Layering makes it easier to enhance the operating system as implementation of a layer can be
changed easily without affecting the other layers.
It is very easy to perform debugging and system verification.
Disadvantages of Layered structure:
In this structure the application performance is degraded as compared to simple structure.
It requires careful planning for designing the layers as higher layers use the functionalities of
only the lower layers.
Introduction to Linux:
Linux is a Unix-like computer operating system assembled under the model of free and open source
software development and distribution. The defining component of Linux is the Linux kernel, an
operating system kernel first released 5 October 1991 by Linus Torvalds.
Linux was originally developed as a free operating system for Intel x86-based personal computers.
It has since been ported to more computer hardware platforms than any other operating system. It is
a leading operating system on servers and other big iron systems such as mainframe computers and
supercomputers more than 90% of today's 500 fastest supercomputers run some variant of Linux,
including the 10 fastest. Linux also runs on embedded systems (devices where the operating system
is typically built into the firmware andhighly tailored to the system) such as mobile phones, tablet
computers, network routers, televisions and video game consoles; the Android system in wide use
on mobile devices is built on the Linux kernel.
Basic Features
Following are some of the important features of Linux Operating System.
Portable - Portability means software‘s can works on different types of hardware‘s in same
way. Linux kernel and application programs support their installation on any kind of hardware
platform.
Open Source - Linux source code is freely available and it is community based development
project. Multiple Teams works in collaboration to enhance the capability of Linux operating system
and it is continuously evolving.
Multi-User - Linux is a multiuser system means multiple users can access systemresources like
memory/ ram/ application programs at same time.
Multiprogramming - Linux is a multiprogramming system means multiple applicationscan run
at same time.
Hierarchical File System - Linux provides a standard file structure in which system
13
files/ user files are arranged.
Shell - Linux provides a special interpreter program which can be used to execute
commands of the operating system. It can be used to do various types of operations, callapplication
programs etc.
Security - Linux provides user security using authentication features like password
protection/ controlled access to specific files/ encryption of data.
Linux Advantages
1. Low cost: You don‘t need to spend time and money to obtain licenses since Linux and
much of its software come with the GNU General Public License. You can start to work
immediately without worrying that your software may stop working anytime because the free trial
version expires. Additionally, there are large repositories from which you can freely download high
quality software for almost any task you can think of.
2. Stability: Linux doesn‘t need to be rebooted periodically to maintain performance levels.It
doesn‘t freeze up or slow down over time due to memory leaks and such. Continuous up- times of
hundreds of days (up to a year or more) are not uncommon.
3. Performance: Linux provides persistent high performance on workstations and on
networks. It can handle unusually large numbers of users simultaneously, and can make old
computers sufficiently responsive to be useful again.
4. Network friendliness: Linux was developed by a group of programmers over the Internet
and has therefore strong support for network functionality; client and server systems can be easily
set up on any computer running Linux. It can perform tasks such as network backups faster and
more reliably than alternative systems.
5. Flexibility: Linux can be used for high performance server applications, desktop
applications, and embedded systems. You can save disk space by only installing the components
needed for a particular use. You can restrict the use of specific computers by installing for example
only selected office applications instead of the whole suite.
6. Compatibility: It runs all common UNIX software packages and can process all common
file formats.
7. Choice: The large number of Linux distributions gives you a choice. Each distribution is
developed and supported by a different organization. You can pick the one you like best; the core
functionalities are the same; most software runs on most distributions.
8. Fast and easy installation: Most Linux distributions come with user-friendly installation
14
OPERATING SYSTEMS NOTES II YEAR/I SEM
and setup programs. Popular Linux distributions come with tools that make installation of additional
software very user friendly as well.
9. Full use of hard disk: Linux continues work well even when the hard disk is almost full.
Multi-tasking: Linux is designed to do many things at the same time; e.g., a large printing
job in the background won‘t slow down your other work.
10. Security: Linux is one of the mo st secure operating systems. ―Walls‖ and flexible
file access permission systems prevent access by unwanted visitors or viruses. Linux users have to
option to select and safely download software, free of charge, from online repositories containing
thousands of high quality packages. No purchase transactions requiring credit card numbers or other
sensitive personal information are necessary.
11. Open Source: If you develop software that requires knowledge or modification of the
operating system code, LINUX‘s source code is at your fingertips. Most Linux applications are
Open Source as well.
Layered Architecture:
15
OPERATING SYSTEMS NOTES II YEAR/I SEM
root entry "/". That part of the directory tree is left out of the below diagram.
1. / – Root
Every single file and directory starts from the root directory.
Only root user has write privilege under this directory.
Please note that /root is root user‘s home directory, which is not same as /.
2. /bin – User Binaries
Contains binary executables.
Common linux commands you need to use in single-user modes are located under this
directory.
Commands used by all the users of the system are located here.
For example: ps, ls, ping, grep, cp.
3. /sbin – System Binaries
Just like /bin, /sbin also contains binary executables.
But, the linux commands located under this directory are used typically by system
administrator, for system maintenance purpose.
For example: iptables, reboot, fdisk, ifconfig, swapon
4. /etc – Configuration Files
(/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp
files needed across reboots (/var/tmp);
8. /tmp – Temporary Files
Directory that contains temporary files created by system and users.
Files under this directory are deleted when system is rebooted.
9. /usr – User Programs
Contains binaries, libraries, documentation, and source-code for second level
programs.
/usr/bin contains binary files for user programs. If you can‘t find a user binary under
/bin, look under /usr/bin. For example: at, awk, cc, less, scp
/usr/sbin contains binary files for system administrators. If you can‘t find a system
binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel
/usr/lib contains libraries for /usr/bin and /usr/sbin
/usr/local contains users programs that you install from source. For example, when
youinstall apache from source, it goes under /usr/local/apache2
10. /home – Home Directories
Home directories for all users to store their personal files.
For example: /home/john, /home/nikita
11. /boot – Boot Loader Files
Contains boot loader related files.
Kernel initrd, vmlinux, grub files are located under /boot
For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic
12. /lib – System Libraries
Contains library files that supports the binaries located under /bin and /sbin
Library filenames are either ld* or lib*.so.*
For example: ld-2.11.1.so, libncurses.so.5.7
13. /opt – Optional add-on Applications
opt stands for optional.
Contains add-on applications from individual vendors.
17
OPERATING SYSTEMS NOTES II YEAR/I SEM
1. Files Listing
2. Creating Files
touch command can be used to create a new file. It will create and open a new blank file if the
file with a filename does not exist. And in case the file already exists then the file will not be
affected.
$touch filename
18
OPERATING SYSTEMS NOTES II YEAR/I SEM
cat command can be used to display the contents of a file. This command will display the contents
of the ‘filename’ file. And if the output is very large then we could use more or less to fit the output
on the terminal screen otherwise the content of the whole file is displayed at once.
$cat filename
4. Copying a File
cp command could be used to create the copy of a file. It will create the new file in destination with
the same name and content as that of the file ‘filename’.
$cp source/filename destination/
5. Moving a File
mv command could be used to move a file from source to destination. It will remove the file filename
from the source folder and would be creating a file with the same name and content in the destination
folder.
$mv source/filename destination/
6. Renaming a File
mv command could be used to rename a file. It will rename the filename to new_filename or in other
words, it will remove the filename file and would be creating a new file with the new_filename with
the same content and name as that of the filename file.
$mv filename new_filename
7. Deleting a File
rm command could be used to delete a file. It will remove the filename file from the directory.
$rm filename
Process Utilities
A program/command when executed, a special instance is provided by the system to the process.
This instance consists of all the services/resources that may be utilized by the process under
execution.
Whenever a command is issued in Unix/Linux, it creates/starts a new process. For example, pwd
when issued which is used to list the current directory location the user is in, a process starts.
Through a 5 digit ID number Unix/Linux keeps an account of the processes, this number is call
process ID or PID. Each process in the system has a unique PID.
Used up pid’s can be used in again for a newer process since all the possible combinations are
used.
At any point of time, no two processes with the same pid exist in the system because it is the pid
that Unixusestotrackeachprocess.
Initializing a process
A process can be run in two ways:
19
OPERATING SYSTEMS NOTES II YEAR/I SEM
Method 1: Foreground Process : Every process when started runs in foreground by default,
receives input from the keyboard, and sends output to the screen. When issuing pwd command
$ ls pwd Output:
$ /home/geeksforgeeks/root
When a command/process is running in the foreground and is taking a lot of time, no other processes
can be run or started because the prompt would not be available until the program finishes
processing and comes out.
Method 2: Background Process: It runs in the background without keyboard input and waits till
keyboard input is required. Thus, other processes can be done in parallel with the process running in
the background since they do not have to wait for the previous process to
be completed. Adding & along with the command starts it as a background process
$ pwd &
Since pwd does not want any input from the keyboard, it goes to the stop state until moved to the
foreground and given any data input. Thus, on pressing Enter: Output:
[1] + Done pwd
$
That first line contains information about the background process – the job number and the
process ID. It tells you that the ls command background process finishes successfully. The second
is a prompt for another command.
Tracking ongoing processes
ps (Process status) can be used to see/list all the running processes.
$ ps
19 pts/1 00:00:00 sh
For a running program (named process) Pidof finds the process id’s (pids)
Fields described by ps are described as:
UID: User ID that this process belongs to (the person running it)
PID: Process ID
PPID: Parent process ID (the ID of the process that started it)
C: CPU utilization of process
STIME: Process start time
TTY: Terminal type associated with the process
TIME: CPU time is taken by the process
CMD: The command that started this process
There are other options which can be used along with ps command :
-a: Shows information about all users
-x: Shows information about processes without terminals
-u: Shows additional information like -f option
-e: Displays extended information
Stoppingaprocess:
When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For
processes running in background kill command can be used if it’s pid is known.
Networking Commands
One can use a variety of network tools to perform tasks such as obtaining information about
other systems on your network, accessing other systems, and communicating directly with other
users. Network information can be obtained using utilities such as ping, finger, traceroute, host,
dig, nslookup etc. These are useful for smaller networks and enables to access remote systems
directly to copy files or execute the command.
Network Information Tools are listed below:
1. ping: The ping command is used to check if a remote system is running or up. In short this
command is used to detect whether a system is connected to the network or
not. Syntax:
$ ping www.geeksforgeeks.com
Note: In place of using domain name you can use IP address also. A ping operation can fail if ping
access is denied by a network firewall.
2. host: This command is used to obtain network address information about a remote system
connected to your network. This information usually consists of system’s IP address, domain name
address and sometimes mail server also. Syntax:
$ host www.google.com
3. finger: One can obtain information about the user on its network and the who command to see
what users are currently online on your system. The who command list all users currently connected,
along with when, how long, and where they logged in. finger can operate on large networks, though
most systems block it for security reasons.
Syntax:
$ finger www.ABC.com
In place of ABC you can use any website domain or IP address.
4. traceroute: This command is use to track the sequence of computer networks. You can track to
21
OPERATING SYSTEMS NOTES II YEAR/I SEM
check the route through which you are connected to a host. mtr or xmtr tools can also be
used to perform both ping and traces. Options are available for specifying parameters like the
type of service (-t) or the source host (-s).
5. netstat: This command is used to check the status of ports whether they are open, closed, waiting
and masquerade connections. Network Statistic (netstat) command display connection information,
routing table information etc.
Syntax:
$ netstat
Note: To display routing table information use (netstat -r).
6.tracepath: tracepath performs a very similar function to that of traceroute command. The main
difference between these command is that tracepath doesn’t take complicated options. This command
doesn’t require root privileges.
Syntax:
$ tracepath www.google.com
7. dig: dig(Domain Information Groper) query DNS related information like a record, cname,
mxrecord etc. This command is used to solve DNS related queries. Syntax:
$ dig www.google.com
8. hostname: This command is used to see the hostname of your computer. You can change
hostname permanently in etc/sysconfig/network. After changing the hostname you need to reboot the
computer. Syntax:
$ hostname
9. route: The route command is used to display or modify the routing table. To add a gateway use (-
n). Syntax:
$ route -n
10. nslookup: You can use nslookup(name server lookup) command to find out DNS related query or
testing andtroubleshooting DNS server. Syntax:
$ nslookup google.com
Filters in Linux
Filters are programs that take plain text(either stored in a file or produced by another program) as
standard input, transforms it into a meaningful format, and then returns it as standard output. Linux
has a number of filters. Some of the most commonly used filters are explained below:
1. cat : Displays the text of the file line by line.
Syntax:
cat [path]
2. head : Displays the first n lines of the specified text files. If the number of lines is not specified
then by default prints first 10 lines.
Syntax:
head [-number_of_lines_to_print] [path]
3. tail : It works the same way as head, just in reverse order. The only difference in tail is, it returns
the lines from bottom to up.
Syntax:
tail [-number_of_lines_to_print] [path]
4. sort : Sorts the lines alphabetically by default but there are many options available to modify the
22
OPERATING SYSTEMS NOTES II YEAR/I SEM
sorting mechanism. Be sure to check out the main page to see everything it can do.
Syntax:
sort [-options] [path]
5. uniq : Removes duplicate lines. uniq has a limitation that it can only remove continuous duplicate
lines(although this can be fixed by the use of piping). Assuming we have the following data.
Syntax:
uniq [options] [path]
When applying uniq to sorted data, it removes the duplicate lines because, after sorting data,
duplicate lines come together.
6. wc : wc command gives the number of lines, words and characters in the data.
Syntax:
wc [-options] [path]
In above image the wc gives 4 outputs as:
number of lines
number of words
number of characters
path
7. grep : grep is used to search a particular information from a text file.
Syntax:
grep [options] pattern [path]
Below are the two ways in which we can implement grep.
8. tac : tac is just the reverse of cat and it works the same way, i.e., instead of printing from lines 1
through n, it prints lines n through 1. It is just reverse of cat command.
Syntax:
tac [path]
9. sed : sed stands for stream editor. It allows us to apply search and replace operation on our data
effectively. sed is quite an advanced filter and all its options can be seen on its man page.
Syntax:
sed [path]
10. nl : nl is used to number the lines of our text data.
Syntax:
nl [-options] [path]
23
OPERATING SYSTEMS NOTES II YEAR/I SEM
Process Program
Process is a dynamic object Program is a static object
Process States
When a process executed, it changes the state, generally the state of process is determined by the
current activity of the process. Each process may be in one of the following states:
1. New: The process is being created.
2. Running: The process is being executed.
3. Waiting: The process is waiting for some event to occur.
4. Ready : The process is waiting to be assigned to a processor.
5. Terminated : The Process has finished execution.
Only one process can be running in any processor at any time, But many process may be inready
and waiting states. The ready processes are loaded into a “ready queue”.
Diagram of process state
24
OPERATING SYSTEMS NOTES II YEAR/I SEM
a) New ->Ready: OS creates process and prepares the process to be executed, then OS moved the
process into ready queue.
b) Ready->Running: OS selects one of the Jobs from ready Queue and move themfrom ready to
Running.
e)Running -> Waiting: A process is put into the waiting state, if the process need anevent occur
(or) an I/O Device require.
f) Waiting->Ready: A process in the waiting state is moved to readystate when the event for
which it has been Completed.
Process Control Block:
Each process is represented in the operating System by a Process Control Block.
It is also called Task Control Block. It contains many pieces of information associated with a
specific Process.
Process State
Program Counter
CPU Registers
Memory – Management
Information
Accounting Information
25
CPU-Scheduling Info: includes a process pointer, pointers to scheduling Queues, other
scheduling parameters etc.
Memory management Info: includes page tables, segmentation tables, value ofbase and limit
registers.
Accounting Information: includes amount of CPU used, time limits, Jobs(or)Process numbers.
I/O Status Information: Includes the list of I/O Devices Allocated to the processes, list ofopen
files.
Threads:
A process is divide into number of light weight process, each light weight process is said to be a
Thread. The Thread has a program counter (Keeps track of which instruction to execute next),
registers (holds its current working variables), stack (execution History).
Thread States:
Process Thread
Process takes more time to create. Thread takes less time to create.
it takes more time to complete Less time to terminate.
execution & terminate.
Execution is very slow. Execution is very fast.
It takes more time to switch It takes less time to switch b/w two
b/w two threads.
processes.
Communication b/w two processes is Communication b/w two threads is
difficult . easy.
Process can’t share the same memory Threads can share same memory area.
area.
System calls are requested to System calls are not required.
communicate each other.
Process is loosely coupled. Threads are tightly coupled.
It requires more resources to execute. Requires few resources to execute.
26
Multithreading
A process is divided into number of smaller tasks each task is called a Thread. Number ofThreads
with in a Process execute at a time is called Multithreading.
If a program, is multithreaded, even when some portion of it is blocked, the whole program is not
blocked. The rest of the program continues working If multiple CPU’s are available.
Multithreading gives best performance. If we have only a single thread, number of CPU’s
available, No performance benefits achieved.
Process creation is heavy-weight while thread creation is light-weight Can simplify code,
increase efficiency
27