Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
179 views

OS Notes - Unit - I

Operating system notes For second year engineering Artificial intelligence and data science and engineering

Uploaded by

tejasrahane27
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
179 views

OS Notes - Unit - I

Operating system notes For second year engineering Artificial intelligence and data science and engineering

Uploaded by

tejasrahane27
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

OPERATING SYSTEM

Unit - I Notes

What is an Operating System?


 A program that acts as an intermediary between a user of a computer and the computer hardware.
 An operating System is a collection of system programs that together control the operations of a
computer system.
Some examples of operating systems are UNIX, Mach, MS-DOS, MS-Windows, Windows/NT,
Chicago, OS/2, MacOS, VMS, MVS, and VM.

Operating system goals:


 Execute user programs and make solving user problems easier.
 Make the computer system convenient to use.
 Use the computer hardware in an efficient manner.

Computer System Components


1. Hardware – provides basic computing resources (CPU, memory, I/O devices).
2. Operating system – controls and coordinates the use of the hardware among the various
application programs for the various users.
3. Applications programs – Define the ways in which the system resources are used to solve the
computing problems of the users (compilers, database systems, video games, business programs).
4. Users (people, machines, other computers).

Abstract View of System Components

Operating System Definitions-


Resource allocator – manages and allocates resources.
Control program – controls the execution of user programs and operations of I/O devices.
Kernel – The one program running at all times (all else being application programs).
Components of OS: OS has two parts. (1) Kernel. (2) Shell.

AI&DS, AVCOE Page 1


(1) Kernel is an active part of an OS i.e.; it is the part of OS running at all times. It is a program
which can interact with the hardware. Ex: Device driver, dll files, system files etc.
(2) Shell is called as the command interpreter. It is a set of programs used to interact with the
application programs. It is responsible for execution of instructions given to OS (called commands).
Operating systems can be explored from two viewpoints: the user and the system.
User View: From the user‟s point view, the OS is designed for one user to monopolize its resources, to
maximize the work that the user is performing and for ease of use.
System View: From the computer's point of view, an operating system is a control program that
manages the execution of user programs to prevent errors and improper use of the computer. It is
concerned with the operation and control of I/O devices.

Functions of Operating System:


Process Management
A process is a program in execution. A process needs certain resources, including CPU time,
memory, files, and I/O devices, to accomplish its task.
The operating system is responsible for the following activities in connection with process management.
✦ Process creation and deletion.
✦ process suspension and resumption.
✦ Provision of mechanisms for:
 process synchronization
 process communication

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.

I/O System Management


The I/O system consists of:
✦ A buffer-caching system
✦ A general device-driver interface
✦ Drivers for specific hardware devices

AI&DS, AVCOE Page 2


Secondary-Storage Management
Since main memory (primary storage) is volatile and too small to accommodate all data and
programs permanently, the computer system must provide secondary storage to back up main memory.
Most modern computer systems use disks as the principle on-line storage medium, for both programs and
data. The operating system is responsible for the following activities in connection with disk
management:
✦ Free space management
✦ Storage allocation
✦ Disk scheduling

Networking (Distributed Systems)


 A distributed system is a collection processor that do not share memory or a clock. Each
processor has its own local memory.
 The processors in the system are connected through a communication network.
 Communication takes place using a protocol.
 A distributed system provides user access to various system resources.
 Access to a shared resource allows:
 Increased data availability
✦ Enhanced reliability

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

AI&DS, AVCOE Page 3


Common System Components
 Process Management
 Main Memory Management
 File Management
 I/O System Management
 Secondary Management
 Networking
 Protection System
 Command-Interpreter System

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

2. Batch Processing Operating System:


 This type of OS accepts more than one jobs and these jobs are batched/ grouped together according
to their similar requirements. This is done by computer operator. Whenever the computer becomes
available, the batched jobs are sent for execution and gradually the output is sent back to the
user.
 It allowed only one program at a time.
 This OS is responsible for scheduling the jobs according to priority and the resource required.

3. Multiprogramming Operating System:


 This type of OS is used to execute more than one jobs simultaneously by a single processor. it
increases CPU utilization by organizing jobs so that the CPU always has one job to execute.
 The concept of multiprogramming is described as follows:
 All the jobs that enter the system are stored in the job pool( in disc). The operating system
loads a set of jobs from job pool into main memory and begins to execute.
 During execution, the job may have to wait for some task, such as an I/O operation, to
complete. In a multiprogramming system, the operating system simply switches to
another job and executes. When that job needs to wait, the CPU is switched to another
job, and so on.
 When the first job finishes waiting and it gets the CPU back.
 As long as at least one job needs to execute, the CPU is never idle.
Multiprogramming operating systems use the mechanism of job scheduling and CPU
scheduling.

4.Time-Sharing/multitasking Operating Systems


Time sharing (or multitasking) OS is a logical extension of multiprogramming. It provides extra
facilities such as:
 Faster switching between multiple jobs to make processing faster.

AI&DS, AVCOE Page 4


 Allows multiple users to share computer system simultaneously.
 The users can interact with each job while it is running.
These systems use a concept of virtual memory for effective utilization of memory space. Hence,
in this OS, no jobs are discarded. Each one is executed using virtual memory concept. It uses CPU
scheduling, memory management, disc management and security management. Examples: CTSS,
MULTICS, CAL, UNIX etc.

5.Multiprocessor Operating Systems


Multiprocessor operating systems are also known as parallel OS or tightly coupled OS. Such
operating systems have more than one processor in close communication that sharing the computer bus,
the clock and sometimes memory and peripheral devices. It executes multiple jobs at same time
and makes the processing faster.
Multiprocessor systems have three main advantages:
 Increased throughput: By increasing the number of processors, the system performs more work in
less time. The speed-up ratio with N processors is less than N.
 Economy of scale: Multiprocessor systems can save more money than multiple single-processor
systems, because they can share peripherals, mass storage, and power supplies.
 Increased reliability: If one processor fails to done its task, then each of the remaining
processors must pick up a share of the work of the failed processor. The failure of one
processor will not halt the system, only slow it down.

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.

6.Distributed Operating Systems


 In distributed system, the different machines are connected in a network and each machine
has its own processor and own local memory.
 In this system, the operating systems on all the machines work together to manage the
collective network resource.
 It can be classified into two categories:
1. Client-Server systems
2. Peer-to-Peer systems
Advantages of distributed systems.
 Resources Sharing
 Computation speed up – load sharing
 Reliability
 Communications
 Requires networking infrastructure.
 Local area networks (LAN) or Wide area networks (WAN)
.

AI&DS, AVCOE Page 5


7. Desktop Systems/Personal Computer Systems
a. The PC operating system is designed for maximizing user convenience and responsiveness. This
system is neither multi-user nor multitasking.
b. These systems include PCs running Microsoft Windows and the Apple Macintosh. The MS-
DOS operating system from Microsoft has been superseded by multiple flavors of Microsoft
Windows and IBM has upgraded MS-DOS to the OS/2 multitasking system.
c. The Apple Macintosh operating system has been ported to more advanced hardware, and now
includes new features such as virtual memory and multitasking.

8. Real-Time Operating Systems (RTOS)


a. A real-time operating system (RTOS) is a multitasking operating system intended for
applications with fixed deadlines (real-time computing). Such applications include some small
embedded systems, automobile engine controllers, industrial robots, spacecraft, industrial
control, and some large-scale computing systems.
b. The real time operating system can be classified into two categories:
i. hard real time system and 2. soft real time system.
c. A hard real-time system guarantees that critical tasks be completed on time. This goal
requires that all delays in the system be bounded, from the retrieval of stored data to the time
that it takes the operating system to finish any request made of it. Such time constraints dictate
the facilities that are available in hard real-time systems.
d. A soft real-time system is a less restrictive type of real-time system. Here, a critical real-time
task gets priority over other tasks and retains that priority until it completes. Soft real time system
can be mixed with other types of systems. Due to less restriction, they are risky to use for
industrial control and robotics.

Operating System Design Issues


There are various types of Advanced Operating Systems. Though all the Major Design Issues will
be applicable to most of the Operating Systems. The important issues related to Operating system
are transparency, flexibility, reliability, performance, scalability, naming, replication,
synchronization, security.

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

AI&DS, AVCOE Page 6


Flexibility
Flexible operating systems are taken to be those whose designs have been motivated to some degree by the
desire to allow the system to be tailored, either statically or dynamically, to the requirements of specific
applications or application domains.
Reliability
In general, reliability is the ability of a person or system to perform and maintain its functions in routine
circumstances, as well as hostile or unexpected circumstances.
Reliability is generally considered important by end users. Not all companies making operating systems
have a similar standard. Even among operating systems where reliability is a priority, there is a range of
quality.
Performance
The performance of computer hardware typically increases monotonically with time. Even if the same could
be said of software, the rate at which software performance improves is usually very slow compared to that
of hardware.
In fact, many might opine that there is plenty of software whose performance has deteriorated consistently
with time.

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.

AI&DS, AVCOE Page 7


User View of Operating System:
The user view depends on the system interface that is used by the users. Some systems are designed for a
single user to monopolize the resources to maximize the user's task. In these cases, the OS is designed
primarily for ease of use, with little emphasis on quality and none on resource utilization.

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.

1. Single User View Point

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.

2. Multiple User View Point

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.

3. Handled User View Point

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

4. Embedded System User View Point

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.

AI&DS, AVCOE Page 8


Types of Operating Systems
There are several types of Operating Systems which are mentioned below.

 Batch Operating System


 Multi-Programming System
 Multi-Processing System
 Multi-Tasking Operating System
 Time-Sharing Operating System
 Distributed Operating System
 Network Operating System
 Real-Time Operating System

1. Batch Operating System


This type of operating system does not interact with the computer directly. There is an operator which
takes similar jobs having the same requirements and groups them into batches. It is the responsibility of
the operator to sort jobs with similar needs. Batch Operating System is designed to manage and execute a
large number of jobs efficiently by processing them in groups.

Batch Operating System

Advantages of Batch Operating System


 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


AI&DS, AVCOE Page 9
 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 difficult to accurately predict the exact time required for a job to complete while it is in the queue.
Examples of Batch Operating Systems: Payroll Systems, Bank Statements, etc.

2. Multi-Programming Operating System


Multiprogramming Operating Systems can be simply illustrated as more than one program is present in
the main memory and any one of them can be kept in execution. This is basically used for better
utilization of resources.

MultiProgramming

Advantages of Multi-Programming Operating System


 Multi Programming increases the Throughput of the System.
 It helps in reducing the response time.

Disadvantages of Multi-Programming Operating System


 There is not any facility for user interaction of system resources with the system.

3. 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 the
CPU as they use a single system. These systems are also known as Multitasking Systems. The task can be

AI&DS, AVCOE Page 10


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.

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.

4. Distributed Operating System


These types of operating system are a recent advancement in the world of computer technology and are
being widely accepted all over the world and, that too, at a great pace. Various autonomous

AI&DS, AVCOE Page 11


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 systems‟ 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.

Distributed OS

Advantages of Distributed Operating System


 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.
 Delay in data processing reduces.

Disadvantages of Distributed Operating System


 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.
Examples of Distributed Operating Systems are LOCUS, etc.
Issues with Distributed Operating Systems

5. Network Operating System


These systems run on a server and provide the capability to manage data, users, groups, security,
applications, and other networking functions. These types of operating systems allow shared access to
files, printers, security, applications, and other networking functions over a small private network. 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.

AI&DS, AVCOE Page 12


Network Operating System

Advantages of Network Operating System


 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 of Network Operating System


 Servers are costly.
 User has to depend on a central location for most operations.
 Maintenance and updates are required regularly.
Examples of Network Operating Systems are Microsoft Windows Server 2003, Microsoft Windows
Server 2008, UNIX, Linux, Mac OS X, Novell NetWare, BSD, etc.

6. Real-Time Operating System


These types of OSs serve real-time systems. The time interval required to process and respond to inputs is
very small. This time interval is called response time. Real-time systems are used when there are time
requirements that are very strict like missile systems, air traffic control systems, robots, etc.

AI&DS, AVCOE Page 13


Types of Real-Time Operating Systems
 Hard Real-Time Systems: Hard Real-Time OSs are meant for applications where time constraints are
very strict and even the shortest possible delay is not acceptable. These systems are built for saving
life like automatic parachutes or airbags which are required to be readily available in case of an
accident. Virtual memory is rarely found in these systems.
 Soft Real-Time Systems: These OSs are for applications where time-constraint is less strict.
For more, refer to the Difference Between Hard Real-Time OS and Soft Real-Time OS.

Real-Time Operating System

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.

AI&DS, AVCOE Page 14


 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 of Real-Time Operating Systems are Scientific experiments, medical imaging systems,
industrial control systems, weapon systems, robots, air traffic control systems, etc

Operating System Services-

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

AI&DS, AVCOE Page 15


ensuring that all access to system resources is controlled. Security of the system from outsiders is also
important. Such security starts with each user having to authenticate him to the system, usually by
means of a password, to be allowed access to the resources.

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.

The following different types of system calls provided by an 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

AI&DS, AVCOE Page 16


Information maintenance
 get time or date, set time or date
 get system data, set system data
 get process, file, or device attributes
 set process, file, or device attributes

Communications
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices

Types of System Calls

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:

Types of System Calls

1. File System Operations


These system calls are made while working with files in OS, File manipulation operations such as
creation, deletion, termination etc.
 open(): Opens a file for reading or writing. A file could be of any type like text file, audio file etc.
 read(): Reads data from a file. Just after the file is opened through open() system call, then if some
process want to read the data from a file, then it will make a read() system call.

AI&DS, AVCOE Page 17


 write(): Writes data to a file. Wheneve the user makes any kind of modification in a file and saves it,
that‟s when this is called.
 close(): Closes a previously opened file.
 seek(): Moves the file pointer within a file. This call is typically made when we the user tries to read
the data from a specific position in a file. For example, read from line – 47. Than the file pointer will
move from line 1 or wherever it was previously to line-47.

Algorithm for Reading a File


algorithm read
input: user file descriptor, address of buffer in user process, number of bytes to read
output: count of bytes copied into user space
{
get file table entry from user file descriptor;
check file accessibility;
set parameters in u area for user address, byte count, I/O to user;
get inode from file table;
lock inode;
set byte offset in u area from file table offset;
while(count not satisfied)
{
convert file offset to disk block(algorithm bmap);
calculate offset into block, number of bytes to read;
if(number of bytes to read is 0)
break;
read block (algorithm breada if with read ahead, algorithm bread otherwise);
copy data from system buffer to user address;
update u area fields for file byte offset, read count, address to write into user space;
release buffer;
}
unlock inode;
update file table offset for next read;
return(total number of bytes read);
}

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.

AI&DS, AVCOE Page 18


3. Memory Management
These types of system calls deals with memory allocation, deallocation & dynamically changing the size
of a memory allocated to a process. In short, the overall management of memory is done by making these
system calls.
 brk(): Changes the data segment size for a process in HEAP Memory. It takes an address as argument
to define the end of the heap and explicitly sets the size of HEAP.
 sbrk(): This call is also for memory management in heap, it also takes an argument as an integer (+ve
or -ve) specifying whether to increase or decrease the size respectively.
 mmap(): Memory Map – It basically maps a file or device into main memory and further into a
process‟s address space for performing operations. And any changes made in the content of a file will
be reflected in the actual file.
 munmap(): Unmaps a memory-mapped file from a process‟s address space and out of main memory
 mlock() and unlock(): memory lock defines a mechanism through which certain pages stay in
memory and are not swapped out to the swap space in the disk. This could be done to avoid page
faults. Memory unlock is the opposite of lock, it releases the lock previously acquired on pages.

4. Interprocess Communication (IPC)


When two or more process are required to communicate, then various IPC mechanism are used by the OS
which involves making numerous system calls. Some of them are :
 pipe(): Creates a unidirectional communication channel between processes. For example, a parent
process may communicate to its child process through a pipe making a parent process as input source
of its child process.
 socket(): Creates a network socket for communication. Processes in same or other networks can
communicate through this socket, provided that they have necessary network permissions granted.
 shmget(): It is short for – „shared-memory-get‟. It allows one or more processes to share a portion of
memory and achieve interprocess communication.
 semget(): It is short for – „semaphore-get‟. This call typically manages the coordination of multiple
processes while accessing a shared resource that is, the critical section.
 msgget(): It is short for – „message-get‟. IPC mechanism has one of the fundamental concept called –
„message queue‟ which is a queue data structure inside memory through which various processes
communicate with each other. This message queue is allocated through this call allowing other
processes a structured way of communication for data exchange purpose.

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

AI&DS, AVCOE Page 19


 Efficient Resource Management: System Calls help your computer manage its resources efficiently.
They allocate and manage memory so programs run smoothly without using up too many resources.
This is important for multitasking and overall performance.
 Security and Isolation: System Calls ensure that one program cannot interfere with or access the
memory of another program. This enhances the security and stability of your device.
 Multitasking Capabilities: System Calls support multitasking, allowing multiple programs to run
simultaneously. This improves productivity and makes it easy to switch between applications.
 Enhanced Control: System Calls provide a high level of control over your device‟s operations. They
allow you to start and stop processes, manage files, and perform various system-related tasks.
 Input/Output (I/O) Operations: System Calls enable communication with input and output devices,
such as your keyboard, mouse, and screen. They ensure that these devices work effectively.
 Networking and Communication: System Calls facilitate networking and communication between
different applications. They make it easy to transfer data over networks, browse the web, send emails,
and connect online.

System Programs in Operating System

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 .

Here are the examples of System Programs :


1. File Management : A file is a collection of specific information stored in the memory of a computer
system. File management is defined as the process of manipulating files in the computer system, its
management includes the process of creating, modifying and deleting files.

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.

AI&DS, AVCOE Page 20


6. Programming-Language support : For common programming languages, we use Compilers,
Assemblers, Debuggers, and interpreters which are already provided to users. It provides all support to
users. We can run any programming language. All important languages are provided.

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.

Why do we need shell scripts?


There are many reasons to write shell scripts:
 To avoid repetitive work and automation
 System admins use shell scripting for routine backups.
 System monitoring
 Adding new functionality to the shell etc.

Advantages of shell scripts


 The command and syntax are exactly the same as those directly entered in the command line, so
programmers do not need to switch to entirely different syntax
 Writing shell scripts are much quicker
 Quick start
 Interactive debugging etc.
Disadvantages of shell scripts
 Prone to costly errors, a single mistake can change the command which might be harmful.
 Slow execution speed
 Design flaws within the language syntax or implementation
 Not well suited for large and complex task
 Provide minimal data structure unlike other scripting languages. etc

AI&DS, AVCOE Page 21


Basic Shell Commands in Linux

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.

2) File and Directory Manipulation Commands:


 mkdir : Used to create a directory if not already exist. It accepts the directory name as an input
parameter.
 cp : This command will copy the files and directories from the source path to the destination path.
It can copy a file/directory with the new name to the destination path. It accepts the source
file/directory and destination file/directory.
 mv : Used to move the files or directories. This command‟s working is almost similar
to cp command but it deletes a copy of the file or directory from the source path.
 rm : Used to remove files or directories.
 touch : Used to create or update a file.

3). Extract, sort, and filter data Commands:


 grep : This command is used to search for the specified text in a file.
 grep with Regular Expressions: Used to search for text using specific regular expressions in file.
 sort : This command is used to sort the contents of files.
 wc : Used to count the number of characters, words in a file.
 cut : Used to cut a specified part of a file.

4). Basic Terminal Navigation Commands:


 ls : To get the list of all the files or folders.
 ls -l: Optional flags are added to ls to modify default behavior, listing contents in extended form -l is
used for “long” output
 ls -a: Lists of all files including the hidden files, add -a flag
 cd: Used to change the directory.
 du: Show disk usage.
 pwd: Show the present working directory.
 man: Used to show the manual of any command present in Linux.
 rmdir: It is used to delete a directory if it is empty.
 ln file1 file2: Creates a physical link.
 ln -s file1 file2: Creates a symbolic link.
 locate: It is used to locate a file in Linux System
 echo: This command helps us move some data, usually text into a file.
 df: It is used to see the available disk space in each of the partitions in your system.
 tar: Used to work with tarballs (or files compressed in a tarball archive)

AI&DS, AVCOE Page 22


5). File Permissions Commands: The chmod and chown commands are used to control access to files in
UNIX and Linux systems.
 chown : Used to change the owner of the file.
 chgrp : Used to change the group owner of the file.
 chmod : Used to modify the access/permission of a user.

AI&DS, AVCOE Page 23

You might also like