OS Unit1
OS Unit1
OPERATING SYSTEM
Definition
In the 1960’s one might have defined OS as “The software that controls
the hardware”.
Operating System performs all the basic tasks like managing files,
processes, and memory. Thus operating system acts as the manager of all
the resources, i.e. resource manager.
Operating system becomes an interface between the user and the machine.
It is one of the most required software that is present in the device.
Operating System is a type of software that works as an interface between
the system program and the hardware.
Concept of OS
The OS is a set of special programs that run on a computer system that
allow it to work properly.
It performs basic task as recognizing input from the keyboard, keeping
track of files and directories on the disk, sending output to the display
screen and controlling a peripheral device.
The OS must support the following tasks. They are,
Provides the facilities to create, modification of program and data file
using an editor.
Access to the compiler for translating the user program from high level
language to machine language.
Provide a loader program to move the compiled program code to the
computer memory for execution.
OS as a resource allocator
OS keeps track of the status of each resource and decides who gets a
resource, for how long and when.
OS makes sure that different programs and users running at the same time
do not interfere with each other.
It is also responsible for security, ensuring that unauthorized users do not
access the system.
The primary objective of OS is to increase productivity of a processing
resource such as computer hardware or user.
The OS is the first program run on a computer when the computer boots up.
Names of OS
DOS, windows 3,windows 95/98, windows NT/2000, Unix, Linux etc.
Classification of OS
OS classified into two types:
1. Character user interface (CUI) / Single user OS
The user can interact with computer through commands.
We cannot use mouse here,
It is not user friendly,
If user knows the command only the user can interact with computer.
For example: DOS, Unix, Linux.
GOALS OF OS
Simplify the execution of user programs and make solving user problems
easier.
Use computer hardware efficiently.
Make application software portable and versatile.
Provide isolation, security and protection among user programs.
Improve overall system reliability.
The salient points about the above figure displaying Computer System
Organisation is −
Computer consists of processor, memory, and I/O components, with one
or more modules of each type. These modules are connected through
interconnection network.
I/O devices and the CPU can execute concurrently.
Each device controller is in charge of a particular device type.
Each device controller has a local buffer.
CPU moves data from/to main memory to/from local buffers.
I/O is from the device to local buffer of controller.
Device controller informs CPU that it has finished its operation by
causing an interrupt.
Interrupt Handling
An interrupt is a necessary part of Computer System Organisation as it is
triggered by hardware and software parts when they need immediate attention.
An interrupt can be generated by a device or a program to inform the
operating system to halt its current activities and focus on something else.
Types of interrupts
Hardware and software interrupts
are two types of interrupts. Hardware
interrupts are triggered by hardware
peripherals while software interrupts are
triggered by software function calls.
Hardware interrupts are of further
two types. Maskable interrupts can be
ignored or disabled by the CPU while
this is not possible for non-maskable interrupts.
Disadvantages
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.
It is very difficult to guess or know the time required for any job to
complete.
Examples
Payroll Systems, Bank Statements, etc.
Preemptive Multi-Tasking
The operating system can initiate a context switching from the running
process to another process. In other words, the operating system allows stopping
the execution of the currently running process and allocating the CPU to some
other process.
Cooperative Multi-Tasking
The operating system never initiates context switching from the running
process to another process. A context switch occurs only when the processes
voluntarily yield control periodically or when idle or logically blocked to allow
multiple applications to execute simultaneously. Also, in this multitasking, all
the processes cooperate for the scheduling scheme to work.
Advantages
Multiple Programs can be executed simultaneously in Multi-Tasking
Operating System.
It comes with proper memory management.
Disadvantages of Multi-Tasking Operating System
The system gets heated in case of heavy programs multiple times.
6. Personal Computer
A personal computer (PC) is a microcomputer designed for use by one person
at a time.
Prior to the PC, computers were designed for -- and only affordable for --
companies that attached terminals for multiple users to a single
large mainframe computer whose resources were shared among all users. By the
Client/Server Systems
In client server systems, the client requests a resource and the server
provides that resource. A server may serve multiple clients at the same time while
a client is in contact with only one server. Both the client and server usually
communicate via a computer network and so they are a part of distributed
systems.
Peer to Peer Systems
The peer to peer systems contains nodes that are equal participants in data
sharing. All the tasks are equally divided between all the nodes. The nodes
interact with each other as required as share resources. This is done with the help
of a network.
Advantages
Failure of one will not affect the other network communication, as all
systems are independent of each other.
Electronic mail increases the data exchange speed.
Since resources are being shared, computation is highly fast and durable.
Load on host computer reduces.
These systems are easily scalable as many systems can be easily added to
the network.
Delay in data processing reduces.
Disadvantages
Failure of the main network will stop the entire communication.
To establish distributed systems the language is used not well-defined yet.
These types of systems are not readily available as they are very
expensive. Not only that the underlying software is highly complex and
not understood well yet.
Example: LOCUS
One more important aspect of Network Operating Systems is that all the
users are well aware of the underlying configuration, of all other users within the
network, their individual connections, etc. and that’s why these computers are
popularly known as tightly coupled systems.
Advantages
Highly stable centralized servers.
Security concerns are handled through servers.
New technologies and hardware up-gradation are easily integrated into the
system.
Server access is possible remotely from different locations and types of
systems.
Disadvantages
Servers are costly.
User has to depend on a central location for most operations.
Maintenance and updates are required regularly.
Examples
Microsoft Windows Server 2003, Microsoft Windows Server 2008,
UNIX, Linux, Mac OS X, Novell NetWare, BSD, etc.
Task Shifting: The time assigned for shifting tasks in these systems is
very less. For example, in older systems, it takes about 10 microseconds
in shifting from one task to another, and in the latest systems, it takes 3
microseconds.
Focus on Application: Focus on running applications and less importance
on applications that are in the queue.
Real-time operating system in the embedded system: Since the size of
programs is small, RTOS can also be used in embedded systems like in
transport and others.
Error Free: These types of systems are error-free.
Memory Allocation: Memory allocation is best managed in these types
of systems.
Disadvantages
Limited Tasks: Very few tasks run at the same time and their
concentration is very less on a few applications to avoid errors.
Use heavy system resources: Sometimes the system resources are not so
good and they are expensive as well.
Complex Algorithms: The algorithms are very complex and difficult for
the designer to write on.
Device driver and interrupt signals: It needs specific device drivers and
interrupts signal to respond earliest to interrupts.
Thread Priority: It is not good to set thread priority as these systems are
very less prone to switching tasks.
Examples
Scientific experiments, medical imaging systems, industrial control
systems, weapon systems, robots, air traffic control systems, etc.
Mainframe Systems
First commercial systems: Enormous, expensive and slow.
I/O: Punch cards and line printers.
Single operator/programmer/user runs and debugs interactively:
Standard library with no resource coordination
Monitor that is always resident
Inefficient use of hardware: poor throughput and poor utilization
They initially executed one program at a time and were known as batch
systems.
System Calls
A system call is a way for a user program to interface with the operating
system. The program requests several services, and the OS responds by
invoking a series of system calls to satisfy the request.
A system call can be written in assembly language or a high-level language
like C, C++ or Pascal.
System calls are predefined functions that the operating system may
directly invoke if a high-level language is used.
A system call is a method for a computer program to request a service from
the kernel of the operating system on which it is running.
A system call is a method of interacting with the operating system via
programs.
A system call is a request from computer software to an operating system's
kernel.
A simple system call may take few nanoseconds to provide the result, like
retrieving the system date and time. A more complicated system call, such
as connecting to a network device, may take a few seconds. Most operating
systems launch a distinct kernel thread for each system call to avoid
bottlenecks. Modern operating systems are multi-threaded, which means
they can handle various system calls at the same time.
The Application Program Interface (API) connects the operating
system's functions to user programs. It acts as a link between the operating
system and a process, allowing user-level programs to request operating
system services. The kernel system can only be accessed using system
calls. System calls are required for any programs that use resources.
C. Dinesh, AP/CSE-AIML, MRCE Page 16
UNIT – I CS403PC: OPERATING SYSTEMS
There are various situations where we must require system calls in the
operating system. Following of the situations are as follows:
1. It is must require when a file system wants to create or delete a file.
2. Network connections require the system calls to sending and receiving data
packets.
3. If you want to read or write a file, you need to system calls.
4. If you want to access hardware devices, including a printer, scanner, you
need a system call.
5. System calls are used to create and manage new processes.
open()
The open() system call allows you to access a file on a file system. It
allocates resources to the file and provides a handle that the process may refer to.
Many processes can open a file at once or by a single process only. It's all based
on the file system and structure.
read()
It is used to obtain data from a file on the file system. It accepts three
arguments in general:
A file descriptor.
A buffer to store read data.
The number of bytes to read from the file.
The file descriptor of the file to be read could be used to identify it and open it
using open() before reading.
C. Dinesh, AP/CSE-AIML, MRCE Page 19
UNIT – I CS403PC: OPERATING SYSTEMS
wait()
In some systems, a process may have to wait for another process to
complete its execution before proceeding. When a parent process makes a child
process, the parent process execution is suspended until the child process is
finished. The wait() system call is used to suspend the parent process. Once the
child process has completed its execution, control is returned to the parent process.
write()
It is used to write data from a user buffer to a device like a file. This system
call is one way for a program to generate data. It takes three arguments in general:
A file descriptor.
A pointer to the buffer in which data is saved.
The number of bytes to be written from the buffer.
fork()
Processes generate clones of themselves using the fork() system call. It is
one of the most common ways to create processes in operating systems. When a
parent process spawns a child process, execution of the parent process is
interrupted until the child process completes. Once the child process has
completed its execution, control is returned to the parent process.
close()
It is used to end file system access. When this system call is invoked, it
signifies that the program no longer requires the file, and the buffers are flushed,
the file information is altered, and the file resources are de-allocated as a result.
exec()
When an executable file replaces an earlier executable file in an already
executing process, this system function is invoked. As a new process is not built,
the old process identification stays, but the new process replaces data, stack, data,
head, etc.
exit()
The exit() is a system call that is used to end program execution. This call
indicates that the thread execution is complete, which is especially useful in multi-
threaded environments. The operating system reclaims resources spent by the
process following the use of the exit() system function.