OS Notes - Unit - I
OS Notes - Unit - I
Unit - I Notes
Main-Memory Management
Memory is a large array of words or bytes, each with its own address. It is a repository of
quickly accessible data shared by the CPU and I/O devices.
Main memory is a volatile storage device. It loses its contents in the case of system failure.
The operating system is responsible for the following activities in connections with memory
management:
Keep track of which parts of memory are currently being used and by whom.
Decide which processes to load when memory space becomes available.
Allocate and de-allocate memory space as needed.
File Management
A file is a collection of related information defined by its creator. Commonly, files represent
programs (both source and object forms) and data.
The operating system is responsible for the following activities in connections with file management:
✦ File creation and deletion.
✦ Directory creation and deletion.
✦ Support of primitives for manipulating files and directories.
✦ Mapping files onto secondary storage.
✦ File backup on stable (nonvolatile) storage media.
Protection System
Protection refers to a mechanism for controlling access by programs, processes, or users
to both system and user resources.
The protection mechanism must:
✦ distinguish between authorized and unauthorized usage.
✦ specify the controls to be imposed.
✦ provide a means of enforcement.
Command-Interpreter System
Many commands are given to the operating system by control statements which deal with:
✦ process creation and management
✦ I/O handling
✦ secondary-storage management
✦ main-memory management
✦ file-system access
✦ protection
✦ networking
The program that reads and interprets control statements is called variously:
✦ command-line interpreter
✦ shell (in UNIX)
Its function is to get and execute the next command statement.
Operating-System Structures
System Components
Operating System Services
System Calls
System Programs
System Structure
Virtual Machines
System Design and Implementation
System Generation
Evolution of OS:
1. Mainframe Systems
Reduce setup time by batching similar jobs Automatic job sequencing – automatically transfers control
from one job to another. First rudimentary
operating system. Resident monitor
initial control in monitor
control transfers to job
when job completes control transfers pack to monitor
The ability to continue providing service proportional to the level of surviving hardware is
called graceful degradation. Systems designed for graceful degradation are called fault tolerant.
The multiprocessor operating systems are classified into two categories:
1. Symmetric multiprocessing system
2. Asymmetric multiprocessing system
In symmetric multiprocessing system, each processor runs an identical copy of the operating
system, and these copies communicate with one another as needed.
In asymmetric multiprocessing system, a processor is called master processor that controls other
processors called slave processor. Thus, it establishes master-slave relationship. The master
processor schedules the jobs and manages the memory for entire system.
Let us understand the Different Types of Advanced Operating Systems to understand the
Major Design Issues better.
Transparency
Multiple Computers are used but the user gets a view of only single system being used. Makes the
network invisible to user/applications.
Various degrees of transparency are
• Access Transparency
• Location Transparency
• Name Transparency
• Data Transparency
• Execution Transparency
• Performance Transparency
Scalability
Scalability is a desirable property of a system, a network, or a process, which indicates its ability to either
handle growing amounts of work in a graceful manner, or to be readily enlarged. A system whose
performance improves after adding hardware, proportionally to the capacity added, is said to be a scalable
system.
Naming
The resources in a distributed system are spread across different computers and a naming scheme has to be
devised so that users can discover and refer to the resources that they need.
An example of such a naming scheme is the URL (Uniform Resource Locator) that is used to identify
WWW pages. If a meaningful and universally understood identification scheme is not used then many of
these resources will be inaccessible to system users.
Replication
Replication is one of the oldest and most important topics in the overall area of distributed systems. Whether
one replicates data or computation, the objective is to have some group of processes that handle incoming
events.
The user viewpoint focuses on how the user interacts with the operating system through the usage
of various application programs. In contrast, the system viewpoint focuses on how the hardware
interacts with the operating system to complete various tasks.
Most computer users use a monitor, keyboard, mouse, printer, and other accessories to operate
their computer system. In some cases, the system is designed to maximize the output of a single
user. As a result, more attention is laid on accessibility, and resource allocation is less important.
These systems are much more designed for a single user experience and meet the needs of a
single user, where the performance is not given focus as the multiple user systems.
Another example of user views in which the importance of user experience and performance is
given is when there is one mainframe computer and many users on their computers trying to
interact with their kernels over the mainframe to each other. In such circumstances, memory
allocation by the CPU must be done effectively to give a good user experience. The client-server
architecture is another good example where many clients may interact through a remote server,
and the same constraints of effective use of server resources may arise.
Moreover, the touchscreen era has given you the best handheld technology ever. Smartphones
interact via wireless devices to perform numerous operations, but they're not as efficient as a
computer interface, limiting their usefulness. However, their operating system is a great example
of creating a device focused on the user's point of view.
ADVERTISEMENT
Some systems, like embedded systems that lack a user point of view. The remote control used to
turn on or off the tv is all part of an embedded system in which the electronic device
communicates with another program where the user viewpoint is limited and allows the user to
engage with the application.
MultiProgramming
Time-Sharing OS
Advantages of Time-Sharing OS
Each task gets an equal opportunity.
Fewer chances of duplication of software.
CPU idle time can be reduced.
Resource Sharing: Time-sharing systems allow multiple users to share hardware resources such as the
CPU, memory, and peripherals, reducing the cost of hardware and increasing efficiency.
Improved Productivity: Time-sharing allows users to work concurrently, thereby reducing the waiting
time for their turn to use the computer. This increased productivity translates to more work getting
done in less time.
Disadvantages of Time-Sharing OS
Reliability problem.
One must have to take care of the security and integrity of user programs and data.
Data communication problem.
High Overhead: Time-sharing systems have a higher overhead than other operating systems due to the
need for scheduling, context switching, and other overheads that come with supporting multiple users.
Complexity: Time-sharing systems are complex and require advanced software to manage multiple
users simultaneously.
Distributed OS
Advantages of RTOS
Maximum Consumption: Maximum utilization of devices and systems, thus more output from all the
resources.
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 of RTOS
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.
Following are the five services provided by operating systems to the convenience of the users.
1. Program Execution
The purpose of computer systems is to allow the user to execute programs. So the operating
system provides an environment where the user can conveniently run programs. Running a
program involves the allocating and deallocating memory, CPU scheduling in case of
multiprocessing.
2. I/O Operations
Each program requires an input and produces output. This involves the use of I/O. So the
operating systems are providing I/O makes it convenient for the users to run programs.
3. File System Manipulation
The output of a program may need to be written into new files or input taken from some
files. The operating system provides this service.
4. Communications
The processes need to communicate with each other to exchange information during
execution. It may be between processes running on the same computer or running on the different
computers. Communications can be occur in two ways: (i) shared memory or (ii) message
passing
5. Error Detection
An error is one part of the system may cause malfunctioning of the complete system. To
avoid such a situation operating system constantly monitors the system for detecting the errors.
This relieves the user of the worry of errors propagating to various part of the system and causing
malfunctioning.
Following are the three services provided by operating systems for ensuring the efficient
operation of the system itself.
1. Resource allocation
When multiple users are logged on the system or multiple jobs are running at the same time,
resources must be allocated to each of them. Many different types of resources are managed by the
operating system.
2. Accounting
The operating systems keep track of which users use how many and which kinds of
computer resources. This record keeping may be used for accounting (so that users can be billed)
or simply for accumulating usage statistics.
3. Protection
When several disjointed processes execute concurrently, it should not be possible for one
process to interfere with the others, or with the operating system itself. Protection involves
System Call:
System calls provide an interface between the process and the operating system.
System calls allow user-level processes to request some services from the operating system
which process itself is not allowed to do.
For example, for I/O a process involves a system call telling the operating system to read or
write particular area and this request is satisfied by the operating system.
Process control
end, abort
load, execute
create process, terminate process
get process attributes, set process attributes
wait for time
wait event, signal event
allocate and free memory
File management
create file, delete file
open, close
read, write, reposition
get file attributes, set file attributes
Device management
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
Services provided by an OS are typically related to any kind of operation that a user program can perform
like creation, termination, forking, moving, communication, etc. Similar types of operations are grouped
into one single system call category. System calls are classified into the following categories:
2. Process Control
These types of system calls deal with process creation, process termination, process allocation,
deallocation etc. Basically manages all the process that are a part of OS.
fork(): Creates a new process (child) by duplicating the current process (parent). This call is made
when a process makes a copy of itself and the parent process is halted temporarily until the child
process finishes its execution.
exec(): Loads and runs a new program in the current process and replaces the current process with a
new process. All the data such as stack, register, heap memory everything is replaced by a new
process and this is known as overlay. For example, when you execute a java byte code using
command – java “filename”. Then in the background, exec() call will be made to execute the java file
and JVM will also be executed.
wait(): The primary purpose of this call is to ensure that the parent process doesn‟t proceed further
with its execution until all its child processes have finished their execution. This call is made when
one or more child processes are forked.
exit(): It simply terminates the current process.
kill(): This call sends a signal to a specific process and has various purpose including – requesting it
to quit voluntarily, or force quit, or reload configuration.
5. Device Management
The device management system calls are used to interact with various peripherial devices attached to the
PC or even the management of the current device.
SetConsoleMode(): This call is made to set the mode of console (input or output). It allows a process
to control various console modes. In windows, it is used to control the behaviour of command line.
WriteConsole(): It allows us to write data on console screen.
ReadConsole(): It allows us to read data from console screen (if any arguments are provided).
open(): This call is made whenever a device or a file is opened. A unique file descriptor is created to
maintain the control access to the opened file or device.
close(): This call is made when the system or the user closes the file or device.
Importance of System Calls
System Programming can be defined as the act of building Systems Software using System
Programming Languages. According to Computer Hierarchy, Hardware comes first then is Operating
System, System Programs, and finally Application Programs. Program Development and Execution can
be done conveniently in System Programs. Some of the System Programs are simply user interfaces,
others are complex. It traditionally sits between the user interface and system calls.
In the context of an operating system, system programs are nothing but a special software which give us
facility to manage and control the computer‟s hardware and resources. As we have mentioned earlier
these programs are more closely with the operating system so it executes the operation fast and helpful in
performing essential operation which can‟t be handled by application software .
2. Command Line Interface(CLI’s) : CLIs is the essential tool for user . It provide user facility to write
commands directly to the system for performing any operation . It is a text-based way to interact with
operating system. CLIs can perform many tasks like file manipulation, system configuration and etc.
3. Device drivers : Device drivers work as a simple translator for OS and devices . Basically it act as an
intermediatory between the OS and devices and provide facility to both OS and devices to understand
each other‟s language so that they can work together efficiently without interrupt.
4. Status Information : Information like date, time amount of available memory, or disk space is asked
by some users. Others providing detailed performance, logging, and debugging information which is
more complex. All this information is formatted and displayed on output devices or printed. Terminal
or other output devices or files or a window of GUI is used for showing the output of programs.
5. File Modification : This is used for modifying the content of files. Files stored on disks or other
storage devices, we use different types of editors. For searching contents of files or perform
transformations of files we use special commands.
7. Program Loading and Execution : When the program is ready after Assembling and compilation, it
must be loaded into memory for execution. A loader is part of an operating system that is responsible
for loading programs and libraries. It is one of the essential stages for starting a program. Loaders,
relocatable loaders, linkage editors, and Overlay loaders are provided by the system.
8. Communications : Connections among processes, users, and computer systems are provided by
programs. Users can send messages to another user on their screen, User can send e-mail, browsing on
web pages, remote login, the transformation of files from one user to another.
Shell Scripting
Usually, shells are interactive, which means they accept commands as input from users and execute them.
However, sometimes we want to execute a bunch of commands routinely, so we have to type in all
commands each time in the terminal.
As a shell can also take commands as input from file, we can write these commands in a file and can
execute them in shell to avoid this repetitive work. These files are called Shell Scripts or Shell
Programs. Shell scripts are similar to the batch file in MS-DOS. Each shell script is saved with `.sh` file
extension e.g., myscript.sh.
A shell script has syntax just like any other programming language. If you have any prior experience with
any programming language like Python, C/C++ etc. It would be very easy to get started with it.
A shell script comprises the following elements –
Shell Keywords – if, else, break etc.
Shell commands – cd, ls, echo, pwd, touch etc.
Functions
Control flow – if..then..else, case and shell loops etc.
A shell is a special user program that provides an interface to the user to use operating system services.
Shell accepts human-readable commands from the user and converts them into something which the
kernel can understand. It is a command language interpreter that executes commands read from input
devices such as keyboards or from files. The shell gets started when the user logs in or starts the terminal.
1). Displaying the file contents on the terminal:
cat: It is generally used to concatenate the files. It gives the output on the standard output.
more: It is a filter for paging through text one screenful at a time.
less: It is used to viewing the files instead of opening the file.Similar to more command but it
allows backward as well as forward movement.
head : Used to print the first N lines of a file. It accepts N as input and the default value of N is 10.
tail : Used to print the last N-1 lines of a file. It accepts N as input and the default value of N is 10.