Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Operating System Operating System

OPERATING SYSTEMS BCA – SEM 3 – OPERATING SYSTEM - Syllabus Unit I


Introduction: What Operating Systems do, Computer system organization, Computer system
architecture, Operating system structure.

System Structure: Operating system services, User operating system interface, System Calls,
Types of System Calls, Overview of UNIX Operating System, Basic features of Unix operating
System.

Unit II
Process Concept: Process Concept, Process Scheduling, Operation on Process.

Process Scheduling: Basic Concepts, Scheduling Criteria, Scheduling Algorithms, CPU


Scheduling in UNIX.

Unit III
Synchronization: Background, The critical section problem.

Semaphores: Usage, Implementation, Deadlocks and Starvation, Classic problems of


synchronization.

Deadlocks: System Model, Deadlock Characterization, Deadlock Prevention.

Unit IV
Memory Management: Background, Basic hardware, Address Binding, Swapping,
Contiguous memory allocation,

Paging: Basic Method, Hardware Support, Protection, Memory Management in UNIX.

Unit V

Files and Directories: Files and Directories in UNIX, File Structure, File System
Implementation of Operating System Functions, File permission, Basic Operation on Files,
Changing Permission Modes, Standard files, Processes Inspecting Files, Operating On Files

TEXT BOOKS
1. Operating system Concepts: Abraham Silberschatz, Peter B. Galvin, Greg Gagne, 8th
Edition, Wiley.

2. Unix and shell Programming by B.M Harwani, OXFORD University Press.

1 2
Operating System Operating System
Unit I Ios 15.44
Introduction: What Operating Systems do, Computer system organization, Computer system
Mac OS 4.34
architecture, Operating System Structure.
Linux 0.95
System Structure: Operating system services, User operating system interface, System Calls,
Types of System Calls, Overview of UNIX Operating System, Basic features of UNIX Chrome OS 0.14
operating System. Windows Phone OS 0.06

1. What is an Operating System? 2) Explain about various Types of Operating Systems?


A) Operating System: An Operating System (OS) is software that acts as an interface A) Types of Operating System (OS): Following are the popular types of OS (Operating
between computer hardware components and the user. Every computer system must have at System):
least one operating system to run other programs. Applications like Browsers, MS Office,
Notepad Games, etc., need some environment to run and perform its tasks. • Batch Operating System
The OS helps you to communicate with the computer without knowing how to speak • Multitasking/Time Sharing OS
the computer‘s language. It is not possible for the user to use any computer or mobile device • Multiprocessing OS
without having an operating system. • Real Time OS
• Distributed OS
• Network OS Mobile OS

Batch Operating System: Some computer processes are very lengthy and time-consuming.
To speed the same process, a job with a similar type of needs are batched together and run as
a group. The user of a batch operating system never directly interacts with the computer. In
this type of OS, every user prepares his or her job on an offline device like a punch card and
submits it to the computer operator.
History Of an OS
• Operating systems were first developed in the late 1950s to manage tape storage Multi-Tasking/Time-sharing Operating systems: Time-sharing operating system enables
• The General Motors Research Lab implemented the first OS in the early 1950s for their people located at a different terminal (shell) to use a single computer system at the same time.
IBM 701 The processor time (CPU) which is shared among multiple users is termed as time sharing.
• In the mid-1960s, operating systems started to use disks
• In the late 1960s, the first version of the Unix OS was developed Real time OS: A real time operating system time interval to process and respond to inputs is
• The first OS built by Microsoft was DOS. It was built in 1981 by purchasing the 86DOS very small. Examples: Military Software Systems, Space Software Systems are the Real time
software from a Seattle company OS example.
• The present-day popular OS Windows first came to existence in 1985 when a GUI was
Distributed Operating System: Distributed systems use many processors located in different
created and paired with MS-DOS.
machines to provide very fast computation to its users.
Examples of Operating System with Market Share
Network Operating System: Network Operating System runs on a server. It provides the
OS Name Share capability to serve to manage data, user, groups, security, application, and other networking
Windows 40.34 functions.
Android 37.95

3 4
Operating System Operating System
Mobile OS: Mobile operating systems are those OS which is especially that are designed to 6. Secondary-Storage Management: Systems have several levels of storage which includes
power smart phones, tablets, and wearable devices. Some most famous mobile operating primary storage, secondary storage, and cache storage. Instructions and data must be stored
systems are Android and iOS, but others include BlackBerry, Web, and watchOS. in primary storage or cache so that a running program can reference it.
7. Security: Security module protects the data and information of a computer system against
3) What are the Functions of Operating System? malware threat and authorized access.
A) Functions of Operating System: Some typical operating system functions may include
managing memory, files, processes, I/O system & devices, security, etc. Below are the main 8. Command interpretation: This module is interpreting commands given by the and acting
functions of Operating System: system resources to process that commands.

9. Networking: A distributed system is a group of processors which do not share memory,


hardware devices, or a clock. The processors communicate with one another through the
network.

10. Job accounting: Keeping track of time & resource used by various job and users.

11. Communication management: Coordination and assignment of compilers, interpreters,


and another software resource of the various users of the computer systems.

4) What are the Features, Advantages and Disadvantages of Operating System?


A) Features of Operating System (OS): The Following are the important features of OS

Functions of Operating System • Protected and supervisor mode


• Allows disk access and file systems Device drivers Networking Security
1. Process management: Process management helps OS to create and delete processes. It • Program Execution
also provides mechanisms for synchronization and communication among processes. • Memory management Virtual Memory Multitasking
• Handling I/O operations
2. Memory management: Memory management module performs the task of allocation and • Manipulation of the file system
de-allocation of memory space to programs in need of these resources. • Error Detection and handling
• Resource allocation
3. File management: It manages all the file-related activities such as organization storage,
• Information and Resource Protection
retrieval, naming, sharing, and protection of files.

4. Device Management: Device management keeps tracks of all devices. This module also
responsible for this task is known as the I/O controller. It also performs the task of
allocation and de-allocation of the devices.

5. I/O System Management: One of the main objects of any OS is to hide the peculiarities
of those hardware devices from the user.

5 6
Operating System Operating System
Advantage of Operating System: • a data bus is used to transfer the contents to/from that location
• Allows you to hide details of hardware by creating an abstraction Easy to use
with a GUI This means that the same address and data buses are used in the process of transferring
• Offers an environment in which a user may execute programs/applications instructions and data between main memory and the processor. A third bus, the control bus,
• The operating system must make sure that the computer system convenient to use is used to synchronize and control operations.
• Operating System acts as an intermediary among applications and the hardware
components Harvard architecture: On the other hand, Harvard architecture keeps instructions and data
• It provides the computer system resources with easy to use format in separate memories. The processor accesses these memories using separate data and
• Acts as an intermediator between all hardware‘s and software‘s of the system address buses; the processor is connected to the ‗instructions memory‘ using a dedicated set
Disadvantages of Operating System of address and data buses, and is connected to the ‗data memory‘ using a different set of
address and data buses.
• If any issue occurs in OS, you may lose all the contents which have been stored in your
system The Harvard architecture is used extensively in embedded systems, for example in digital
• Operating system‘s software is quite expensive for small size organization which adds signal processing (DSP) systems. Many microcontroller devices use a Harvard-like
burden on them. Example Windows architecture. Some types of smart phones use a modified Harvard architecture — although
• It is never entirely secure as a threat can occur at any time distinctions between modern processors are difficult to categories in relation to such 'pure'
theoretical models.
4) Explain about Computer Architecture?
A) Computer architecture: It refers to the structure and organization of a computer system. Comparison between von Neumann and Harvard architecture
It specifies the components that make up a computer system and describes how these are
interconnected, how they interact with each other, and how they are managed. Harvard architecture is characterized by the use of separate memory units and buses for
There are 2 architectures, namely instructions and data, which means that both memories can be accessed simultaneously. This
• Von Neumann architecture minimizes the issue of keeping the processor waiting while loading or saving data into
• Harvard architecture memory, which in turn increases the processor performance.

Von Neumann architecture: In the 1940s, John von Neumann and his team developed the Von Neumann architecture uses the same address and data buses for both instructions and
concept of the stored program computer. The Von Neumann architecture used the idea of data, which means that both instructions and data share the same pathways.
storing program instructions and data in main memory and moving them between memory
and the processor. Von Neumann architecture is used in many modern-day computer Moreover, with Harvard architecture, each memory can be adapted to meet the needs of a
systems. The von Neumann architecture consists of particular system: the instruction and data memories can be different sizes, different word
lengths, or implemented using a different type of technology. For example, for systems with a
• a Processor
predetermined use (such as embedded systems), the instruction memory can be implemented
• a Memory unit that can communicate directly with the processor
as a read-only memory (ROM), which protects the programs from accidental or deliberate
• connections for input and output devices
changes by hacking. On the other hand, von Neumann architecture allows for the instructions
• Secondary storage for saving/backing up data
and data to be saved in the same memory, which can be exploited by hackers who could
disguise instructions (malware) as data that the processor may execute unknowingly when
The processor can access the instructions and data in the main memory as required executing attempting to read the data.
the program. It does this by using dedicated connections called buses:

• an address bus is used to identify the addressed location


7 8
Operating System Operating System
Therefore, Harvard architecture is commonly used in embedded systems, i.e. computer ALU (Arithmetic Logic Unit): All arithmetic calculations and logical operation are
systems that are designed purposefully to perform a specific set of operations and are often performed using the Arithmetic/Logical Unit or ALU.
used in situations where the speed of operation is very important. For example, embedded Memory Unit: A memory is just like a human brain. It is used to store data and instruction.
systems such as traffic-control cameras are required to process large amounts of data in real Computer memory is use to Stores information being processed by the CPU
time. Nonetheless, von Neumann architecture enables a more flexible use of the main
memory, which allows the processor to run a variety of programs that are not known in Control Unit: Control unit help to perform operations of input unit, output unit, Memory unit
advance. and ALU in a sequence.
Therefore, von Neumann architecture is commonly used in general-purpose computers that
are expected to accommodate the varying needs of the end users, for example, run numerous Memory: Computer memory is any physical device capable of storing information
applications and switch between different tasks. temporarily or permanently. For example, Random Access Memory RAM is a type of volatile
memory that is stores information on an integrated circuit, and that is used by the operating
5) Explain about Computer Organization? system, software, hardware, or the user. Computer memory divide into two parts namely
A) Computer Organization refers to the level of abstraction above the digital logic level, but 1.Volatile memory and 2. Non-volatile memory
below the operating system level. Computer organization consist of following parts
• CPU – central processing unit Volatile memory is a temporary memory that loses its contents when the computer or
• Memory hardware device loses power, ex: RAM. Non-volatile memory keeps its contents even if the
• Input devices power is lost. Example: ROM or EPROM is a good example of a non-volatile memory
• Output devices
CPU – central processing unit: It is alternatively referred to as the brain of the computer, Input Devices: A device that can be used to insert data into a computer system is called as
processor, central processor, or microprocessor, the CPU (pronounced as C-P- input device. It allows people to supply information to computers. An input device is any
U) was first developed at Intel with the help of Ted Hoff in the early 1970‘s and is short for hardware device that sends data to the computer, without any input devices, a computer would
Central Processing Unit. The computer CPU is responsible for handling all instructions it only be a display device and not allow users to interact with it, much like a TV. Examples of
receives from hardware and software running on the computer. CPU is considered as the brain input devices include keyboards, mouse, scanners, digital cameras and joysticks.
of the computer. CPU performs all types of data processing operations. It stores data,
intermediate results and instructions (program). It controls the operation of all parts of Output Devices: A device which is used to display result from a computer is called as output
computer. device. It Allows people to receive information from computers. An output device is any
peripheral that receives or displays output from a computer. Examples of output devices
include Printer, Scanner, Monitor, etc.

6) What are the Differences between Computer Architecture and Computer


Organization?
A) Computer Architecture: Computer Architecture is a functional description of
requirements and design implementation for the various parts of computer. It deals with
functional behavior of computer system. It comes before the computer organization while
designing a computer. Architecture describes what the computer does.

Computer Organization: Computer Organization comes after the decide of Computer


Architecture first. Computer Organization is how operational attribute are linked together and
CPU itself has following three components
9 10
Operating System Operating System
contribute to realize the architectural specification. Computer Organization deals with 8. Architecture coordinates between Computer Organization handles the
structural relationship. Organization describes how it does it. the hardware and software of the segments of the network in a system.
system.
7) Explain about Structure of Operating System?
A) Operating System Structure: 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
• Layered Structure
• Micro Kernel
• Modular Structure

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.

S.NO Computer Architecture Computer Organization


1. Architecture describes what the Organization describes how it does it.
computer does.
2. Computer Architecture deals with Computer Organization deals with
functional behavior of computer structural relationship.
system.
3. In above figure, its clear that it deals
In above figure, its also clear that it deals
with high-level design issue. with low-level design issue.
4. Architecture indicates its hardware. Where, Organization indicates its
performance. Advantages of Simple structure:
5. For designing a computer, its For designing a computer, organization is • It delivers better application performance because of the few interfaces between the
architecture is fixed first. decided after its architecture. application program and the hardware.
• Easy for kernel developers to develop such an operating system.
6. Computer Architecture is also called Computer Organization is frequently
as instruction set architecture. called as micro architecture. Disadvantages of Simple structure:
• The structure is very complicated as no clear boundaries exist between modules.
7. Computer Architecture comprises Computer Organization consists of
• It does not enforce data hiding in the operating system.
logical functions such as instruction physical units like circuit designs,
sets, registers, data types and peripherals and adders.
addressing modes. 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
11 12
Operating System Operating System
the hardware and the topmost layer (layer N) is the user interface. These layers are so designed • As micro kernels are small so these can be tested effectively.
that each layer uses the functions of the lower level layers only. This simplifies the debugging Disadvantages of Micro-kernel structure:
process as if lower level layers are debugged and an error occurs during debugging then the • Increased level of inter module communication degrades system performance.
error must be on that layer only as the lower level layers have already been debugged.
Modular structure or approach: It is considered as the best approach for an OS. It involves
The main disadvantage of this structure is that at each layer, the data needs to be designing of a modular kernel. The kernel has only set of core components and other services
modified and passed on which adds overhead to the system. Moreover careful planning of the are added as dynamically loadable modules to the kernel either during run time or boot time.
layers is necessary as a layer can use only lower level layers. UNIX is an example of this It resembles layered structure due to the fact that each kernel has defined and protected
structure. interfaces but it is more flexible than the layered structure as a module can call any other
module. For example Solaris OS is organized as shown in the figure.

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. 9) What are the services provided by Operating System?
A) Operating system services: The operating system provides the programming environment
Disadvantages of Layered structure: in which a programmer works on a computer system. The user program requests various
• In this structure the application performance is degraded as compared to simple structure. resources through the operating system. The operating system gives several services to utility
• It requires careful planning for designing the layers as higher layers use the functionalities programmers and users. Applications access these services through application programming
of only the lower layers. interfaces or system calls. By invoking those interfaces, the application can request a service
from the operating system, pass parameters, and acquire the operation outcomes.
Micro-kernel: This structure designs the operating system by removing all non-essential
components from the kernel and implementing them as system and user programs. This result Following are the services provided by an operating system -
in a smaller kernel called the micro-kernel. Advantages of this structure are that all new o Program execution o Control Input/output devices o Program
services need to be added to user space and does not require the kernel to be modified. Thus it creation o Error Detection and Response
is more secure and reliable as if a service fails then rest of the operating system remains o Accounting o Security and Protection o File
untouched. Mac OS is an example of this type of OS. Management
o Communication
Advantages of Micro-kernel structure:
• It makes the operating system portable to various platforms.
13 14
Operating System Operating System
Program execution: To execute a program, several tasks need to be performed. Both the For Example: When a user downloads something from the internet, that program may contain
instructions and data must be loaded into the main memory. In addition, input-output devices malicious code that may harm the already existing programs. The operating system ensures
and files should be initialized, and other resources must be prepared. The Operating structures that proper checks are applied while downloading such programs.
handle these kinds of tasks. The user now no longer should fear the reminiscence allocation or
multitasking or anything. If one computer system is shared amongst a couple of users, then the various processes must
be protected from another intrusion. For this, the operating system provides various
Control Input/output devices: As there are numerous types of I/O devices within the mechanisms that allow only those processes to use resources that have gained proper
computer system, and each I/O device calls for its own precise set of instructions for the authorization from the operating system. The mechanism may include providing unique users
operation. The Operating System hides that info with the aid of presenting a uniform interface. ids and passwords to each user.
Thus, it is convenient for programmers to access such devices easily.
File management: Computers keep data and information on secondary storage devices like
Program Creation: The Operating system offers the structures and tools, including editors magnetic tape, magnetic disk, optical disk, etc. Each storage media has its capabilities like
and debuggers, to help the programmer create, modify, and debugging programs. speed, capacity, data transfer rate, and data access methods.

Error Detection and Response: An Error in a device may also cause malfunctioning of the For file management, the operating system must know the types of different files and
entire device. These include hardware and software errors such as device failure, memory the characteristics of different storage devices. It has to offer the proportion and safety
error, division by zero, attempts to access forbidden memory locations, etc. To avoid error, the mechanism of documents additionally.
operating system monitors the system for detecting errors and takes suitable action with at
least impact on running applications. While working with computers, errors may occur quite Communication: The operating system manages the exchange of data and programs among
often. Errors may occur in the: different computers connected over a network. This communication is accomplished using
message passing and shared memory.
o Input/ Output devices: For example, connection failure in the network, lack of paper
10) Explain about User Interface of Operating System?
in the printer, etc.
A) User Interface: A User interface (UI) facilitates communication between an application
o User program: For example: attempt to access illegal memory locations, divide by
and its user by acting as an intermediary between them. Each application including the
zero, use too much CPU time, etc. o Memory hardware: For example, Memory error,
operating system is provided with a specific UI for effective communication. The two basic
the memory becomes full, etc.
function of a user interface of an application is to take the inputs from the user and to provide
To handle these errors and other types of possible errors, the operating system takes appropriate the output to the users. However, the types of inputs taken by the UI and the types of output
action and generates messages to ensure correct and consistent computing. provided by the UI may vary from one application to another. A user interface of any operating
system can be classified into one of the following types:
Accounting: An Operating device collects utilization records for numerous assets and tracks
the overall performance parameters and responsive time to enhance overall performance. 1. Graphical user interface (GUI)
These personal records are beneficial for additional upgrades and tuning the device to enhance 2. Command line user interface (CLI)
overall performance.
Graphical user interface (GUI): The graphical user interface is a type of GUI that enables
Security and Protection: Operating device affords safety to the statistics and packages of a the users to interact with the operating system by means of point-and-click operations. GUI
person and protects any interference from unauthorized users. The safety feature counters contains several icons representing pictorial representation of the variables such as a file,
threats, which are published via way of individuals out of doors the manager of the running directory, and device. The graphical icon provided in the UI can be manipulated by the users
device. using a suitable pointing device such as a mouse, trackball, touch screen and light pen. The
other input devices like keyboard can also be used to manipulate these graphical icons. GUIs
are considered to be very user- friendly interface because each object is represented with a

15 16
Operating System Operating System
corresponding icon. Unlike the other UIs the users need not provide text command for When computer software needs to access the operating system's kernel, it makes a system call.
executing tasks. The system call uses an API to expose the operating system's services to user programs. It is
the only method to access the kernel system. All programs or processes that require resources
Advantages of GUI based operating system for execution must use system calls, as they serve as an interface between the operating system
and user programs. Below are some examples of how a system call varies from a user function.
• The GUI interface is easy to understand and even the new users can operate on them on
their own.
1. A system call function may create and use kernel processes to execute the asynchronous
• The GUI interface visually acknowledges and confirms each type of activities
processing.
performed by the users. For example when the user deletes a file in the Windows
operating system, then the operating system asks for the confirmation before deleting 2. A system call has greater authority than a standard subroutine. A system call with kernel-
it. mode privilege executes in the kernel protection domain.
• The GUI interface enables the users to perform a number of tasks at the same time. This 3. System calls are not permitted to use shared libraries or any symbols that are not present
feature of the operating system is also known as multitasking. in the kernel protection domain.
4. The code and data for system calls are stored in global kernel memory.
Command line Interface (CLI): Command line interface is a type of UI that enables the users
to interact with the operating system by issuing some specific commands. In order to perform Need of system calls:
a task in this interface, the user needs to type a command at the command line.
When the user enters the key, the command line interpreter received a command. The There are various situations where you must require system calls in the operating system.
software program that is responsible for receiving and processing the commands issued by the Following of the situations are as follows:
user. After processing the command are called command line interpreter, the command line
1. It is must require when a file system wants to create or delete a file.
interpreter displays the command prompt again along with the output of the previous command
issued by the user. 2. Network connections require the system calls to sending and receiving data packets.
The disadvantages of the CLI are that the user needs to remember a lot to interact with 3. If you want to read or write a file, you need to system calls.
the operating system. Therefore these types of interface are not considered very friendly from 4. If you want to access hardware devices, including a printer, scanner, you need a system
the user‘s perspective. call.
Example: In order to perform a task, we need to type a command at the command prompt 5. System calls are used to create and manage new processes.
denoted by C:\> to copy a text file, say al.text, from the C drive of our computer system. To Types of System Calls: There are commonly five types of system calls. These are as follows:
the D drive, we need to type the copy command at the command prompt.
1. Process Control
11) What is a System Call? What are the various types of System calls? 2. File Management
A) System Call: A system call is a method for a computer program to request a service from
3. Device Management
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 4. Information Maintenance
software to an operating system's kernel. 5. Communication

The Application Program Interface (API) connects the operating system's functions Process Control: Process control is the system call that is used to direct the processes. Some
to user programs. It acts as a link between the operating system and a process, allowing process control examples include creating, load, abort, end, execute, process, terminate the
userlevel programs to request operating system services. The kernel system can only be process, etc.
accessed using system calls. System calls are required for any programs that use resources.

How is system calls made?


17 18
Operating System Operating System
File Management: File management is a system call that is used to handle the files. Some file Portability: This feature makes the UNIX work on different machines and platforms with
management examples include creating files, delete files, open, close, read, write, etc. the easy transfer of code to any computer system. Since a significant portion of UNIX is
written in C language, and only a tiny portion is coded in assembly language for specific
Device Management: Device management is a system call that is used to deal with devices. hardware.
Some examples of device management include read, device, write, get device attributes,
release device, etc. File Security and Protection: Being a multi-user system, UNIX makes special consideration
for file and system security. UNIX has different levels of security using assigning username
Information Maintenance: Information maintenance is a system call that is used to maintain and password to individual users ensuring the authentication, at the level providing file access
information. There are some examples of information maintenance, including getting system permission viz. read, write and execute and lastly file encryption to change the file into an
data, set time or date, get time or date, set system data, etc. unreadable format.
Communication: Communication is a system call that is used for communication. There are
some examples of communication, including create, delete communication connections, send, Command Structure: UNIX commands are easy to understand and simple to use. Example:
receive messages, etc. "cp", mv etc. While working in the UNIX environment, the UNIX commands are casesensitive
and are entered in lower case.
12) What is UNIX? What are its features?
Communication: In UNIX, communication is an excellent feature that enables the user to
A) UNIX operating system: UNIX is a powerful Operating System initially developed by
communicate worldwide. It supports various communication facilities provided using the write
Ken Thompson, Dennis Ritchie at AT&T Bell laboratories in 1970. It is prevalent among
command, mail command, talk command, etc.
scientific, engineering, and academic institutions due to its most appreciative features like
multitasking, flexibility, and many more. In UNIX, the file system is a hierarchical structure Accounting: UNIX keeps an account of jobs created by the user. This feature enhances the
of files and directories where users can store and retrieve information using the files. system performance in terms of CPU monitoring and disk space checking. It allows you to
keep an account of disk space used by each user, and the disk space can be limited by each
Features of UNIX Operating System: The features of Unix Operating System are other. You can assign every user a different disk quota. The root user can perform these
• Multitasking accounting tasks using various commands such as quota, df, du, etc.
• Multiuser
• Portability UNIX Tools and Utilities: UNIX system provides various types of tools and utilities facilities
• File Security and Protection such as UNIX grep, sed and awk, etc. Some of the general-purpose tools are compilers,
• Command Structure interpreters, network applications, etc. It also includes various server programs which provide
• Communication remote and administration services.
• Accounting
13) What are the advantages and disadvantages of Unix Operating System?
• Unix Tools and Utilities
A) Advantages of UNIX operating system
Ecommerce: Many big online stores use UNIX or Linux servers to host their websites. UNIX
Multitasking: A UNIX operating system is a multitasking operating system that allows you to
has also used to manage mobiles and electronic machines.
initiate more than one task from the same terminal so that one task is performed as a foreground
and the other task as a background process. Portable: As UNIX is made from using C language so it is a highly portable OS. You can use
this OS on any PC or MAC computers. C is a very popular language and most programmers
Multi-user: UNIX operating system supports more than one user to access computer resources
can work easily in this language. You can communicate with hardware by using the C
like main memory, hard disk, tape drives, etc. Multiple users can log on to the system from
language.
different terminals and run different jobs that share the resources of a command terminal. It
deals with the principle of time-sharing.
19 20
Operating System Operating System
Memory usage: UNIX use less memory while running sophisticated programs. UNIX OS Multitasking: You can open many programs in the UNIX OS and all the programs work in
can handle virtual memory nicely. The virtual memory expands as more programs come into parallel using multiprocessor technology.
the main memory. Most of the tasks in UNIX is done by using fewer resources.
Modular: The utilities for UNIX are made in modular form. If you are a programmer then
Less code to execute: In GUI (graphical user interface), we sometimes need many mouse you can make small programs in modular form and then unite the modules and all the modules
clicks to perform some specific task but in the case of UNIX we can simply write one command will work consistently throughout the system.
in CLI (command line interface) and that task is done.
Human readable source code: As most of the code is written in C language and is available
Files used everywhere: All type of data is stored in files i.e. all devices and terminal are as open-source so any user can see and understands the code. The source code is written in the
stored in files. Working with files in OS becomes fast and can be easily managed by UNIX. English language. I know English words are different from source code but if you understand
the basics of programming and also understand English then you can easily follow through
Ideal for web hosting: As UNIX OS is free and secure so it is widely used by web hosting with the code and change it.
companies. Many web hosting servers use utilities like DNS (Domain Name Server), DHCP
(Dynamic Host Configuration Protocol) and the web server. Many vendors: UNIX has many popular vendors and standards including POSIX, AIX, and
HP-UX.
Safe and secure: UNIX provides a safe and secure platform in which multiple users can
interact with the servers online without any security issues. The interaction with the UNIX Hiring experts: As UNIX is more than 50 years old so there are many expert developers
servers is fast and without any bugs. UNIX uses UID and GID for controlling permissions for available that can help you to sort out your problem in the OS. The demand for UNIX
users and files are accessed by users through these permissions developers is also high because most cloud-based applications run on UNIX. Online servers
and mobile OS like Android is also developed in UNIX.
No anti-virus needed: As you know that Chrome OS, macOS, Linux, Ubuntu and android
are developed by using UNIX OS. These OS are considered safe from any virus. You don‘t Many variants available: There are many types of UNIX variants are available for UNIX
need to install any anti-virus in newly build Chrome OS. OS. If you are not comfortable using Linux then you can use Ubuntu, Redhat or macOS. Every
UNIX OS has some type of different UI. You are free to use any type of UNIX OS.
User interactions: There are many online servers, electric machines where user interaction is
not involved. UNIX is an ideal choice for machines and devices where no or fewer user Used in a large organization: UNIX is used in universities, research laboratories, colleges
interactions are involved. UNIX can manage the automatic working of systems very well. and large government organizations. Many students and researchers use UNIX for code
learning and get expertise in using operating systems. UNIX is considered as the first OS to
Supports multiple users: In UNIX every user needs a username password to use the OS. use a full-screen editor and editing code online by various people becomes easy in UNIX.
Every file is protected from unauthorized use. Multiple users can log in to the system and use Other features: Some other features of UNIX include:-
the OS as they need. You can take the example of RDP (Remote Desktop Protocol) server and
VPS (Virtual Private Server). • UNIX is free
• The file system is hierarchical by which accessing and retrieving files become easy
String commands and utilities: If you want to put text inside binary data and tries to fetch • The performance of UNIX is better than Windows NT
the text then it is done by using string commands and utilities. You can combine small • Stable database access
commands into complex commands by using string commands. There are more than 400 • Better handling of internet and intranet in servers
command and utilities in UNIX by which you can do all type of tasks. • Internet-client and file server are better managed using Java in UNIX

Looks the same as MS-DOS: If you have experience in using MS-DOS in windows then it Disadvantages of UNIX operating system
becomes easy for you to use UNIX. The usage of commands and user interface is quite similar Not user friendly: Novice user has difficulty in using UNIX. Most of the work in UNIX is
to MS-DOS. done by using commands in CLI so beginner has to remember a different type of commands.

21 22
Operating System Operating System
UNIX is solely made for programmers and not for beginner users. Some experience people
also feel difficulty in using commands because some commands are very different from their
name.

Poor documentation: There is not any proper documentation available for UNIX. If the user
gets any problem then he has to consult some expert and getting online help from the
documentation is very difficult. If you compare this with Windows and macOS then you will
get proper and easy to follow the documentation that is available online.

Cryptic commands: Most of the commands in UNIX use cryptic words. It is difficult for the
casual user to get the idea of working of command. Some commands use special characters While working with UNIX OS, several layers of this system provide interaction between the
and understanding commands for newbie programmers become difficult. If you use any wrong pc hardware and the user. Following is the description of each and every layer structure in
character in the command then your system will start doing unknown works that may also UNIX system:
delete or change some data from your computer. Some commands in UNIX work in a
Layer-1: Hardware - This layer of UNIX consists of all hardware-related information in the
combination of other commands so if you forget any command then your work cannot be
UNIX environment.
completed.

High learning curve: The commands in UNIX is much more difficult than commands in
Layer-2: Kernel - The core of the operating system that's liable for maintaining the full
Windows MS-DOS and macOS. It also becomes difficult to remember the commands. You
functionality is named the kernel. The kernel of UNIX runs on the particular machine hardware
have to go through the documentation every time you have to use any complex command. The
and interacts with the hardware effectively.
new UNIX OS comes with GUI but still, most of the work is done using CLI. The apps and
software in UNIX are also not very popular and you have to learn them before using this
software.

Other drawbacks: Some other drawbacks of UNIX include:-


Some drivers are not available for the software

• The UI of UNIX is not so much attractive


• Some variants of UNIX requires most memory usage
• As UNIX has fewer users so most game companies not make games for UNIX. UNIX
has very fewer games available than Windows and macOS

14) Explain about structure of UNIX OS layers? A)


The structure of Unix OS Layers are as follows:

It also works as a device manager and performs valuable functions for the processes
which require access to the peripheral devices connected to the computer. The kernel controls
these devices through device drivers.

The kernel also manages the memory. Processes are executed programs that have
owner's humans or systems who initiate their execution.

23 24
Operating System Operating System
The system must provide all processes with access to an adequate amount of memory,
and a few processes require a lot of it. To make effective use of main memory and to allocate
a sufficient amount of memory to every process. It uses essential techniques like paging,
swapping, and virtual storage.
Unit IV
Layer-3: The Shell - The Shell is an interpreter that interprets the command submitted by the Memory Management: Background, Basic hardware, Address Binding, Swapping,
user at the terminal, and calls the program you simply want. It also keeps a history of the list Contiguous memory allocation,
of the commands you have typed in. If you need to repeat a command you typed it, use the
cursor keys to scroll up and down the list or type history for a list of previous commands. Paging: Basic Method, Hardware Support, Protection, Memory Management in UNIX.
There are various commands like cat, mv, cat, grep, id, wc, and many more.
1) Write short notes on Memory Management Background?
Types of Shell in UNIX System: A) Memory Management Background: Memory consists of a large array of words or bytes,
each with its own address. The CPU fetches instructions from memory according to the value
o Bourne Shell: This Shell is simply called the Shell. It was the first Shell for UNIX OS.
of the program counter. These instructions may cause additional loading from and storing to
It is still the most widely available Shell on a UNIX system.
specific memory addresses.
o C Shell: The C shell is another popular shell commonly available on a UNIX system.
The C shell was developed by the University of California at Berkeley and removed Usually, a program resides on a disk as a binary executable file. The program must be brought
some of the shortcomings of the Bourne shell. into memory and placed within a process for it to be executed. Depending on the memory
o Korn Shell: This Shell was created by David Korn to address the Bourne Shell's management in use, the process may be moved between disk and memory during its execution.
userinteraction issues and to deal with the shortcomings of the C shell's scripting quirks. The collection of processes on the disk that is waiting to be brought into memory for execution
forms the input queue
Layer-4: Application Programs Layer - It is the outermost layer that executes the given
external applications. UNIX distributions typically come with several useful applications
2) What do you mean by memory management in OS or Explain basic hardware in
programs as standard. For Example: emacs editor, StarOffice, xv image viewer, g++ compiler
memory management?
etc.
A) Memory Management in OS: The term Memory can be defined as a collection of data in
a specific format. It is used to store instructions and processed data. The memory comprises a
large array or group of words or bytes, each with its own location. The primary motive of a
computer system is to execute programs. These programs, along with the information they
access, should be in the main memory during execution. The CPU fetches instructions from
memory according to the value of the program counter.

Memory is the important part of the computer that is used to store the data. Its management
is critical to the computer system because the amount of main memory available in a computer
system is very limited. At any time, many processes are competing for it. Moreover, to increase
performance, several processes are executed simultaneously. For this, we must keep several
processes in the main memory, so it is even more important to manage them effectively.

In a multiprogramming computer, the operating system resides in a part of memory and the
rest is used by multiple processes. The task of subdividing the memory among different
processes is called memory management. Memory management is a method in the operating
25 26
Operating System Operating System
system to manage operations between main memory and disk during process execution. The • Memory managers should enable sharing of memory space between processes. Thus,
main aim of memory management is to achieve efficient utilization of memory. two programs can reside at the same memory location although at different times.
To achieve a degree of multiprogramming and proper utilization of memory, memory 3) Explain about Memory management Techniques?
management is important. Many memory management methods exist, reflecting various A) Memory Management Techniques: The Memory management Techniques can be
approaches, and the effectiveness of each algorithm depends on the situation. classified into following main categories:
• Contiguous memory management schemes
• Non-Contiguous memory management schemes

Need of Memory Management:


• Allocate and de-allocate memory before and after process execution. Contiguous memory management schemes: In a Contiguous memory management scheme,
• To keep track of used memory space by processes. each program occupies a single contiguous block of storage locations, i.e., a set of memory
• To minimize fragmentation issues. locations with consecutive addresses. The Contiguous memory management scheme is further
• To proper utilization of main memory. divided into two types namely
• To maintain data integrity while executing of process. • Single contiguous memory management schemes
• Multiple Partitioning

Non-Contiguous memory management schemes: In a Non-Contiguous memory


Roles of Memory management: Memory management plays several roles in a computer
management scheme, the program is divided into different blocks and loaded at different
system. Following are the important roles in a computer system:
portions of the memory that need not necessarily be adjacent to one another. This scheme can
• Memory manager is used to keep track of the status of memory locations, whether it is
be classified depending upon the size of blocks and whether the blocks reside in the main
free or allocated. It addresses primary memory by providing abstractions so that
memory or not. It is further subdivided into two types namely
software perceives a large memory is allocated to it.
• Paging
• Memory manager permits computers with a small amount of main memory to execute
• Segmentation
programs larger than the size or amount of available memory. It does this by moving
information back and forth between primary memory and secondary memory by using
the concept of swapping.
• The memory manager is responsible for protecting the memory allocated to each
process from being corrupted by another process. If this is not ensured, then the system
may exhibit unpredictable behavior.
27 28
Operating System Operating System
5. This technique can be easily applied to priority-based scheduling in order to improve its
performance.
4.Explain Swapping?
Swapping A process can be swapped temporarily out of memory to a backing store, and then Disadvantages of Swapping: The drawbacks of the swapping technique are as follows:
brought back into memory for continued execution Backing store – fast disk large enough to 1. There may occur inefficiency in the case if a resource or a variable is commonly used
accommodate copies of all memory images for all users; must provide direct access to these by those processes that are participating in the swapping process.
memory images Roll out, roll in – swapping variant used for priority-based scheduling
2. If the algorithm used for swapping is not good then the overall method can increase the
algorithms; lower-priority process is swapped out so higher-priority process can be loaded and number of page faults and thus decline the overall performance of processing.
executed Major part of swap time is transfer time; total transfer time is directly proportional 3. If the computer system loses power at the time of high swapping activity then the user
to the amount of memory swapped and Modified versions of swapping are found on many might lose all the information related to the program.
systems (i.e., UNIX, Linux, and Windows) System maintains a ready queue of ready-to-run
processes which have memory images on disk
5.Explain Address Binding?

A) Binding process:

The distinction between logical memory addresses and physical memory addresses enables
address virtualization. However, it is to be discretely noted that the actual required instructions
or values are stored in physical memory only and each virtual address is decoded back into the
physical memory address.

Address binding refers to the translation of provided virtual address spaces to actual physical
memory address spaces to execute the program. There are different modes and sequences in
which addresses are bound to their true value.

Types of Swapping Techniques: There are two more concepts that come in the swapping Program to a process
technique and these are: swap in and swap out.
While a program refers to a file that consists of a set of executable instructions, a process is
Swap In and Swap Out in OS: The procedure by which any process gets removed from the the precise execution of those instructions.
hard disk and placed in the main memory or RAM commonly known as Swap In. On the other
Note: Address binding forms an essential phase of converting a program to a process instance.
hand, Swap Out is the method of removing a process from the main memory or RAM and then
adding it to the Hard Disk.

Advantages of Swapping: The advantages/benefits of the Swapping technique are as follows: Different types of an address binding

1. The swapping technique mainly helps the CPU to manage multiple processes within a There are precisely three distinct mechanisms for binding addresses based on the differences
in the virtual address in question.
single main memory.
2. This technique helps to create and use virtual memory. • Compile time binding: Symbolic variables in processes that have their memory location
3. With the help of this technique, the CPU can perform several tasks simultaneously. specified before execution and are translated into absolute addresses at the time of
Thus, processes need not wait too long before their execution. compilation.
4. This technique is economical.

29 30
Operating System Operating System
• Load time binding: Symbolic variables in processes that do not have their memory Base register contains value of smallest physical address.
location specified before execution and are translated into relocatable addresses at the
time of loading. Limit register contains range of logical addresses.
• Runtime or execution binding: Binding is uncertain due to the likelihood that the
process might be changed from one memory slot to another during execution. Hence, Each logical address must be less than the limit register .
address binding is done at the execution time of the process.

Address binding allows the appropriate mapping of virtual memory addresses to physical MMU maps logical address dynamically.
memory references. This allows for performing the correct process executions .

Memory allocation
There are two methods namely,
1.Fixed partition or static partition
2.Dynamic or variable partition

1.Fixed partition or static partition:


In this contiguous memory allocationeach process in a single contiguous section of memory

P1 P2 P3 P4 P5 P6 P7 P8 P9

1.The partitions cannot overlap


2.A process must be contiguously present in a partition for the execution.

Internal fragmentation:
The partition will be wasted and remain unused if the process size
6.Explain contiguous memory management scheme?
Is lesser than the total size of the partition.
Contiguous memory:
P1 P2 P3
Main memory usually into two partitions:
3MB 3MB 3MB
Resident operating system, usually held in low memory with interrupt vector.

User processes then held in high memorynRelocation registers used to protect user processes 4MB 4MB 4MB
from each other, and from changing operating-system code and data.
31 32
Operating System Operating System
table holds the base address of each page in physical memory. This base address is combined
External fragmentation: along with the page offset to define the physical memory address that is sent to the memory
We cannot used the total unused memory actually we have some free space unit.
available but not in contiguous form

Advantages of Fixed Partition:


• Simple to implement.
• Easy to manage and design.
Disadvantages of fixed partition:
Limitation on the size of the process
Degree of multiprogramming is less

2.Dynamic or variable partition:


The dynamic partitioning was designed to overcome the problems of a fixed
partitioning scheme. In a dynamic partitioning scheme, each process occupies only as much
memory as they require when loaded for processing. Requested processes are allocated
memory until the entire physical memory is exhausted or the remaining space is insufficient
to hold the requesting process. In this scheme the partitions used are of variable size, and the
number of partitions is not defined at the system generation time. This is a logical concept that ensures faster data access. Some terms involved in
paging are:
Advantages of Dynamic Partition: • Logical Address (Virtual Address): It is represented in bits and is the address
• Simple to implement. generated by the CPU
• Easy to manage and design. • Logical Address Space (Virtual Address Space): It is represented in words/bytes
and is the set of all the logical addresses that a program generates.
Disadvantages of Dynamic Partition: • Physical Address: It is represented in bits and is an address that is actually
present on the memory unit.
• This scheme also suffers from External fragmentation.
• Physical Address Space: It is represented in words/bytes and is a set of physical
• The number of partitions is specified at the time of system addresses that correspond to logical addresses.

7.What is paging?Explain basic method of paging?


A) Paging: Paging is a function of memory management where a computer will store and Paging technique is the mapping done from virtual address to physical address by the
MMU (a hardware device). The Physical Address Space is divided into multiple fixed-
retrieve data from a device's secondary storage to the primary storage. Memory management
size blocks. These blocks are called frames. Whereas, Logical address Space is divided
is a crucial aspect of any computing device, and paging specifically is important to the into fixed-size pages. Here the size of a page is equal to the size of a frame which
implementation of virtual memory. allows maximum utilization of the main memory and avoids external fragmentation.

The address generated by a CPU is divided into:


Basic method of paging: Physical memory is divided into the fixed-sized blocks called
frames. Logical memory is as well divided into blocks of the same size called pages. When a 1. Page number(p): This is the number of bits that represent the pages in Logical
process is to be implemented, its pages are loaded in to any available memory frames from the Address Space or Page number.
backing store. Each address produced by the CPU is divided into two parts: a page offset (d) 2. Page offset(d): This is the number of bits that represent a particular word in a page
and a page number (p). The page number is used like the index into a page table. The page or the page size of Logical Address Space or page offset.
33 34
Operating System Operating System
We can divide Physical Address into:

1. Frame number(f): This is the number of bits that represent the frame of Physical
Address Space or Frame number.
2. Frame offset(d): This is the number of bits that represent a particular word in a
frame or frame size of Physical Address Space or frame offset.
Advantages of Paging
Following are the advantages of Paging in OS:
• The memory management algorithm is easy to use.
• External Fragmentation is not required.
• Swapping between equal-sized pages and page frames becomes easier.
Disadvantages of Paging
Following are the disadvantages of paging in Operating System:

• Internal fragmentation. Example


• Additional memory consumption by Page tables.
• Memory reference overhead due to multi-level paging. Assuming that the main memory is 16 KB and the frame size is 1 KB, the main memory
will be partitioned into a collection of 16 1 KB frames. P1, P2, P3, and P4 are the four
processes in the system, each of which is 4 KB in size. Each process is separated into 1
8 What is Paging in the OS? KB pages, allowing one page to be saved in a single frame.

Paging is a storage mechanism used in OS to retrieve processes from secondary storage to Because all of the frames are initially empty, the pages of the processes will be stored in a
the main memory as pages. The primary concept behind paging is to break each process continuous manner. The graphic below depicts frames, pages, and the mapping between
into individual pages. Thus the primary memory would also be separated into frames. them.

One page of the process must be saved in one of the given memory frames. These pages Consider the case when P2 and P4 are shifted to the waiting state after a period of time.
can be stored in various memory locations, but finding contiguous frames/holes is always Eight frames are now empty, allowing other pages to be loaded in their stead. Inside the
the main goal. Process pages are usually only brought into the main memory when they ready queue is the process P5, which is 8 KB (8 pages) in size.
are needed; else, they are stored in the secondary storage. Given that we have 8 noncontiguous frames accessible in memory, paging allows us to
store the process in many locations. As a result, we can load the process P5 page instead
The frame sizes may vary depending on the OS. Each frame must be of the same size. of P2 and P4.
Since the pages present in paging are mapped on to the frames, the page size should be
similar to the frame size.

35 36
Operating System Operating System
• If the physical address is 12 bits, then the physical address space would be 4 K words
• If the logical address is 13 bits, then the logical address space would be 8 K words
• If the page size is equal to the frame size, which is equal to 1 K words (assumption),
Then:

Memory Management Unit The address generated by the CPU is divided into the following:
The Memory Management Unit (MMU) is responsible for converting logical addresses to
• Page offset(d): It refers to the number of bits necessary to represent a certain word on a
physical addresses. The physical address refers to the actual address of a frame in which each page, page size in Logical Address Space, or page word number or page offset.
page will be stored, whereas the logical address refers to the address that is generated by the
• Page number(p): It is the number of bits needed to represent the pages in the Logical
CPU for each page. Address Space or the page number.
When the CPU accesses a page using its logical address, the OS must first collect the The Physical Address is divided into the following:
physical address in order to access that page physically. There are two elements to the
• Frame offset(d): It refers to the number of bits necessary to represent a certain word in a
logical address:
frame, or the Physical Address Space frame size, the word number of a frame, or the
• Page number frame offset.
• Offset • Frame number(f): It’s the number of bits needed to indicate a frame of the Physical
Address Space or a frame number.
The OS’s memory management unit must convert the page numbers to the frame numbers.
Dedicated registers can be used to implement the page table in hardware. However, using a
register for the page table is only useful if the page table is tiny. We can employ TLB
Examples
(translation look-aside buffer), a particular, tiny, fast look-up hardware cache if the page
Let’s say the CPU requests the 10th word of the 4th page of process P3 in the image above. table has a significant number of entries.
Because page number 4 of process P1 is stored at frame number 9, the physical address will
be returned as the 10th word of the 9th frame. • The TLB is a high-speed, associative memory.
• LB entries are made up of two parts: a value and a tag.
Let’s consider another example: • When this memory is accessed, an item is compared to all tags at the same time.
• If the object is located, the value associated with it is returned.
37 38
Operating System Operating System
where pi is an index into the outer page table, and p2 is the displacement within the page
of the outer page table

m = main memory access time

In case the page table is kept in the main memory,

then the effective access time would be = m(page table) + m(page in page table)

9 Explain structure of page table or types of page table?


Structure of the Page Table
Hierarchical Paging
Hashed Page Tables Three level paging:

Inverted Page Tables 64 bit logical address space and page size of 1 KB and it is further divided data into

Hierarchical Page Tables: Break up the logical address space into multiple page tables A Page number consists:52
simple technique is a two-level page table Page off set:12
Two-Level Page-Table Schema:
A logical address (on 32-bit machine with 1K page size) is divided into a page number
consisting of 22 bits
Hashed Page Tables:
a page offset consisting of 10 bits
Common in address spaces > 32 bits
Since the page table is paged, the page number is further divided into:
The virtual page number is hashed into a page table
a 12-bit page number a 10-bit page offset
This page table contains a chain of elements hashing to the same
Thus, a logical address is as follows:
location Virtual page numbers are compared in this chain searching for a match
If a match is found, the corresponding physical frame is extracted
39 40
Operating System Operating System

Frame no Page no Process id

F0 P2 P1

F1 P0 P1

Inverted Page Table:


F2 P1 P3
Each process having individual page table.
In multiprocessing ‘n’ no. of processes creates a no. of page tables want to share in the
Memory. F3 P1 P2

By using this the no. of entries is equal to the no. of frames.


By using inverted page table we overcome the drawbacks of page table. F4 P3 P2
We store a fixed portion of memory is required to paging into for all the processes
Page table for process p1 page table for process p2 page table for process p3 F5 P2 P3

F1
0
F3 F2
1
2 F0 F5

F4
3

Advantages and Disadvantages of Paging


Here is a list of advantages and disadvantages of paging
• Paging reduces external fragmentation, but still suffers from internal fragmentation.
• Paging is simple to implement and assumed as an efficient memory management
technique.
41 42
Operating System Operating System
• Due to equal size of the pages and frames, swapping becomes very easy. • Partition size mainly depends upon the length of modules.
Thus with the help of this technique, secondary memory and main memory are divided
• Page table requires extra memory space, so may not be good for a system having small
into unequal-sized partitions
RAM.
10 Explain about segmentation in os?what is its basic method,its architecture,its
hardware,its advantages and disadvantages?
Segmentation:
Memory-management scheme that supports user view of memory A program is a
collection of segments
 A segment is a logical unit such as:
 main program
 Procedure
User’s View of a Program
 function
Basic Method of Segmentation: A computer system that is using segmentation has a
Method logical address space that can be viewed as multiple segments. And the size of the segment is
 object of the variable that is it may grow or shrink. During the execution each segment has a name
and length and the address mainly specifies both thing name of the segment and the
 local variables, global variables
displacement within the segment. Therefore the user specifies each address with the help of
 common block two quantities: segment name and offset.
 stack For simplified Implementation segments are numbered; thus referred to as segment
 symbol table number rather than segment name. Thus the logical address consists of two tuples:
<segment-number, offset> where, Segment Number(s) is used to represent the number of
 arrays bits that are required to represent the segment. Offset(d) Segment offset is used to represent
Types of Segmentation: There are the 2 types of Segmentation, namely the number of bits that are required to represent the size of the segment.

• Virtual Memory Segmentation With this type of segmentation, each process is Segmentation Architecture :
segmented into n divisions and the most important thing is they are not segmented all
Logical address consists of a two tuple: o < segment number,offset >
at once.
• Simple Segmentation With the help of this type, each process is segmented into n Segment table:maps two-dimensional physical address space
divisions and they are all together segmented at once exactly but at the runtime and can Base: contains the starting physical address where the segments reside in memory
be non-contiguous (that is they may be scattered in the memory).
Limit:specifies the length of the segment
Characteristics of Segmentation: Some characteristics of the segmentation technique are Segment-table base register (STBR) :points to the segment table’s location in memory
as follows:
Segment-table length register (STLR): indicates number of segments used by a program;
• The Segmentation partitioning scheme is variable-size. segment number s is legal if s < STLR
• Partitions of the secondary memory are commonly known as segments. Protection
43 44
Operating System Operating System
• This technique leads to external fragmentation as the free space gets broken down into
smaller pieces along with the processes being loaded and removed from the main
memory then this will result in a lot of memory waste.

11 Explain hardware support in paging?

Paging is a storage mechanism that allows OS to retrieve processes from the secondary
storage to the main memory in the form of pages. Every memory access while paging
requires reading the page table. ( Page table is a data structure used by the virtual
memory system to store the mapping between logical addresses and physical addresses. )
Logical addresses are generated by the CPU for the pages of the processes therefore they
are generally used by the processes. Physical addresses are the actual frame address of
the memory. They are generally used by the hardware or more specifically by RAM
subsystems.
Let's say arithmetic operations have to be performed upon every memory access in the
software. This results in the system getting slow because of low effective access time.
The logical address generated by CPU consists of two parts: Segment Number(s), It is used Page size (like the frame size) is typically defined by hardware.
as an index into the segment table. Offset(d), It must lie in between '0' and 'segment limit'. In For hardware support to be effective, the required page size to be the power of two,
this case, if the Offset exceeds the segment limit then the trap is generated. Thus; correct varying between 512 bytes and 1GB per page depending on the computer architecture.
offset+segment base= address in Physical memory and segment table is basically an array This can perform fast logical shifting to get page number and the page offset, no need to
of base-limit register pair. perform expensive arithmetic operations. The selection of a power of 2 as a page offset is
particularly easy. If the size of the logical address space is 2^m, and page size is 2^n
Advantages of Segmentation: The Advantages of the Segmentation technique are as bytes, give 2^(m-n) pages so require (m-n) bits to specify page number and offset of n
follows: bits to specify offset within the page. Thus, the logical address is as follows

• In the Segmentation technique, the segment table is mainly used to keep the record of
segments. Also, the segment table occupies less space as compared to the paging table.
There is no Internal Fragmentation.
• Segmentation generally allows us to divide the program into modules that provide better where p is an index into the page table and d is the displacement within the page.
visualization.
12 Explain protection in paging?
• Segments are of variable size.
The paging process should be protected by using the concept of insertion of an
Disadvantages of Segmentation: Some disadvantages of this technique are as follows: additional bit called Valid/Invalid bit. Paging Memory protection in paging is achieved by
associating protection bits with each page.
• Maintaining a segment table for each process leads to overhead This technique is
In order to indicate whether the page read only or read-write, we can use a bit in page
expensive.
table to specify it. Whenever page table accessed to find a frame (during computation
• The time is taken in order to fetch the instruction increases since now two memory
of physical address). This protection bit checked to ensure that no writes made to read
accesses are required.
only page. If an attempt made to write to a read-only page, hardware trap sent to the
• Segments are of unequal size in segmentation and thus are not suitable for swapping.
operating system.

45 46
Operating System Operating System

13 Explain about Memory management in UNIX?


Memory is an important resource in computer. Memory management is the process of
managing the computer memory which consists of primary memory and secondary memory.
The goal for memory management is to keep track of which parts of memory are in use and
which parts are not in use, to allocate memory to processes when they need it and deallocate
it when they are done. UNIX memory management scheme includes swapping and demand
paging.
Swapping:
The process of moving some pages out of main memory and moving others in, is called
swapping. A page fault occurs when the CPU tries to access a page that is not in main memory,
thus forcing the CPU to wait for the page to be swapped in. Since moving data to and from
disks takes a significant amount of time, the goal of the memory manager is to minimize the
number of page faults.

Demand Paging:
Paging is a memory allocation strategy by transferring a fixedsized unit of the virtual address
space called virtual page whenever the page is needed to execute a program. As the size of
frames and pages are the same, any logical page can be placed in any physical frame of
memory. Every processes will be logical divided and allocate in the virtual address space.
There is a page table in the virtual memory to allocate and keep tracking of the pages to map
into the frames.

14) What are the Differences between Paging and Segmentation?


A) Differences between Paging and Segmentation:

Paging Segmentation

47 48
Operating System Operating System
15) What are the differences between Contiguous and Non-Contiguous Memory
Paging is a memory management Segmentation is also a memory management Allocation?
technique where memory is partitioned technique where memory is partitioned into A) The differences between Contiguous and Non-Contiguous Memory Allocation:
into fixed-sized blocks that are variable-sized blocks that are commonly
commonly known as pages. known as segments.
Contiguous Memory Allocation Non-Contiguous Memory Allocation

With the help of Paging, the logical With the help of Segmentation, the logical The contiguous Memory Allocation The non-Contiguous Memory allocation
address is divided into a page number address is divided into section technique allocates one single technique divides the process into several
and page offset. number and section offset. contiguous block of memory to the blocks and then places them in the different
process and memory is allocated to the address space of the memory that is
process in a continuous fashion. memory is allocated to the process in a non-
This technique may lead to Internal Segmentation may lead to External contiguous fashion.
Fragmentation. Fragmentation.

In this Allocation scheme, there is no While in this scheme, there is overhead in


In Paging, the page size is decided by the While in Segmentation, the size of the segment
overhead in the address translation the address translation while the execution
hardware. is decided by the user.
while the execution of the process. of the process.

In order to maintain the page data, the In order to maintain the segment data, the In Contiguous Memory Allocation, the In Non-contiguous Memory allocation
page table is created in the Paging segment table is created in the Paging process executes faster because the execution of the process is slow as the
whole process is in a sequential block. process is in different locations of the
memory.
The page table mainly contains the base The segment table mainly contains the segment
address of each page. number and the offset.
Contiguous Memory Allocation is easier The non-Contiguous Memory Allocation
for the Operating System to control. scheme is difficult for the Operating
This technique is faster than On the other hand, segmentation is slower than
System to control.
segmentation. paging.

In Paging, a list of free frames is In Segmentation, a list of holes is maintained In this, the memory space is divided into In this scheme, the process is divided into
maintained by the Operating system. by the Operating system. fixed-sized partitions and each partition several blocks and then these blocks are
is allocated only to a single process. placed in different parts of the memory
according to the availability of memory
In this technique, in order to calculate the In this technique, in order to calculate the space.
absolute address page number and the absolute address segment number and the
offset both are required. offset both are required.

49 50
Operating System Operating System

Contiguous memory allocation includes Non-Contiguous memory allocation includes


Paging follows non-contiguous memory Swapping can be done without any
single partition Paging and Segmentation. management. memory management technique.
allocation and multi-partition
allocation.
Paging is more flexible because in this Swapping is less flexible as the entire
there is the movement of pages of a process moves back and forth in the
In this type of memory allocation, In this type of memory allocation generally, process. main memory and back store.
generally, a table is maintained by the a table has to be maintained for each
operating system that maintains the list process that mainly carries the base
of all available and occupied partitions addresses of each block that has been Paging occurs when some part of the While Swapping occurs when the
in the memory space. acquired by a process in the memory. process is transferred to the disk. whole process is transferred to the
disk.

Contiguous Memory Allocation Non-Contiguous Memory Allocation


For medium workloads paging technique is For heavy workloads swapping
suitable. technique is suitable.
There is wastage of memory in There is no wastage of memory in
Contiguous Memory allocation. NonContiguous Memory allocation.

In this type of allocation, swapped-in In this type of allocation, swapped-in This technique allows the memory address With the help of Swapping multiple
processes are arranged in the originally processes can be arranged in any place in the space of a process to be noncontiguous. processes can run in parallel in the
allocated space. memory. Operating System

16) What are the differences between Paging and Swapping? This technique helps to implement virtual Swapping helps the CPU to access
memory. processes faster.
A) Difference Between Paging and Swapping
Paging Swapping

Paging is a memory management Swapping is a technique that is used


technique in which computer stores and to temporarily remove the inactive
retrieves data from the secondary storage programs from the main memory of
for use in the main memory. the computer system

This technique allows more processes to Swapping allows fewer processes to


reside in the main memory reside in the main memory.

51 52
Operating System Operating System
Unit V 2. Identifier : This unique tag, usually a number ,identifies the file within the file
system.
Files and Directories: Files and Directories in UNIX, File Structure, File System
Implementation of Operating System Functions, File permission, Basic Operation on Files, 3. Type : Files are of so many types. The type depends on the extension of the file.
Changing Permission Modes, Standard files, Processes Inspecting Files, Operating On Files Example: .exe Executable file .obj Object file .src Source file

4. Location : This information is a pointer to a device and to the location of the file on
that device
File System
5. Size : The current size of the file (in bytes, words,blocks).
File Concept: Computers can store information on various storage media such as, magnetic
disks, magnetic tapes, optical disks. The physical storage is converted into a logical storage 6. Protection : Access control information determines who can do reading, writing,
unit by operating system. The logical storage unit is called FILE. A file is a collection of similar executing and so on.
records. A record is a collection of related fields that can be treated as a unit by some
7. Time, Date, User identification : This information may be kept for creation, last
application program. A field is some basic element of data. Any individual field contains a
modification,last use.
single value. A data base is collection of related data.
FILE OPERATIONS:

1. Creating a file : Two steps are needed to create a file.

Structure of file:
They are:
The structure of file is as follows
• Check whether the space is available ornot
Text: Text consists of sequence of characters.
• If the space is available then made an entry for the new file in the directory. The entry
Source: Source consist of collecting of sub routines and functions.
includes name of the file, path of the file,etc…
Object: Object consist of sequence of bytes.
2. Writing a file : To write a file, we have to know 2 things. One is name of the file and second
Concepts of files: is the information or data to be written on the file, the system searches the entired given
location for the file. If the file is found, the system must keep a write pointer to the location
The concept of files mainly follows in the file where the next write is to take place.
File attributes 3. Reading a file : To read a file, first of all we search the directories for the file, if the file is
File operations found, the system needs to keep a read pointer to the location in the file where the next read
is to take place. Once the read has taken place, the read pointer is updated.
File types
4. Repositioning within a file : The directory is searched for the appropriate entry and the
FILE ATTRIBUTES : current file position pointer is repositioned to a given value. This operation is also called file
seek.
1. Name : A file is named for the convenience of the user and is referred by its name. A
name is usually a string of characters 5. Deleting a file : To delete a file, first of all search the directory for named file, then released
the file space and erase the directoryentry.

53 54
Operating System Operating System
6. Truncating a file : To truncate a file, remove the file contents only but, the attributes are as file structures, the resulting size of OS is large. If the OS defines 5 different file structures, it
itis. needs to contain the code to support these file structures. All OS must support at least one
structure that of an executable file so that the system is able to load and run programs.
FILE TYPES:The name of the file split into 2 parts. One is name and second is Extension.
The file type is depending on extension of the file.
INTERNAL FILE STRUCTURE:
In UNIX OS, defines all files to be simply stream of bytes. Each byte is individually
addressable by its offset from the beginning or end of the file. In this case, the logical record
size is 1 byte. The file system automatically packs and unpacks bytes into physical disk blocks,
say 512 bytes per block.
The logical record size, physical block size, packing determines how many logical records are
in each physical block. The packing can be done by the user’s application program or OS. A
file may be considered a sequence of blocks. If each block were 512 bytes, a file of 1949 bytes
would be allocated 4 blocks (2048 bytes). The last 99 bytes would be wasted. It is called
internal fragmentation all file systems suffer from internal fragmentation, the larger the block
size, the greater the internal fragmentation.

FILE ACCESS METHODS:


Files stores information, this information must be accessed and read into computer memory.
There are so many ways that the information in the file can be accessed.
1. Sequential file access: Information in the file is processed in order i.e. one record after the
other. Magnetic tapes are supporting this type of file accessing.
Eg : A file consisting of 100 records, the current position of read/write head is 45th record,
suppose we want to read the 75th record then, it access sequentially from 45, 46, 47 ……..
74, 75. So the read/write head traverse all the records between 45 to 75.

2. Direct access:
Direct access is also called relative access. Here records can read/write randomly without
any order. The direct access method is based on a disk model of a file, because disks allow
random access to any file block. Eg : A disk containing of 256 blocks, the position of
read/write head is at 95th block. The block is to be read or write is 250th block. Then we
can access the 250th block directly without any restrictions. Eg : CD consists of 10 songs,
at present we are listening song 3, If we want to listen song 10, we can shift to 10.
FILE STRUCTURE:
3. Indexed Sequential File access :
File types also can be used to indicate the internal structure of the file. The operating system
The main disadvantage in the sequential file is, it takes more time to access a Record
requires that an executable file have a specific structure so that it can determine where in
Records are organized in sequence based on a key field. Eg : A file consisting of 60000
memory to load the file and what the location of the first instruction is. If OS supports multiple
records,the master index divide the total records into 6 blocks, each block consisiting of a
55 56
Operating System Operating System
pointer to secondary index.The secondary index divide the 10,000 records into 10 system and the intended use cases. Some common file systems used in operating
indexes.Each index consisting of a pointer to its orginal location.Each record in the index systems include NTFS and FAT in Windows, and ext4 and XFS in Linux.
file consisting of 2 field, A key field and a pointer field.

FILE SYSTEM IMPLEMENTATION OF OPERATING SYSTEM FUNCTIONS:


A file is a collection of related information. The file system resides on secondary
storage and provides efficient and convenient access to the disk by allowing data to be
stored, located, and retrieved.
File system implementation in an operating system refers to how the file system manages
the storage and retrieval of data on a physical storage device such as a hard drive, solid-
state drive, or flash drive. The file system implementation includes several components,
including:
1. File System Structure: The file system structure refers to how the files and
directories are organized and stored on the physical storage device. This includes the
layout of file systems data structures such as the directory structure, file allocation 1. I/O Control level – Device drivers act as an interface between devices and OS, they
table, and inodes. help to transfer data between disk and main memory. It takes block number as input
2. File Allocation: The file allocation mechanism determines how files are allocated on and as output, it gives low-level hardware-specific instruction.
the storage device. This can include allocation techniques such as contiguous 2. Basic file system – It Issues general commands to the device driver to read and write
allocation, linked allocation, indexed allocation, or a combination of these techniques. physical blocks on disk. It manages the memory buffers and caches. A block in the
3. Data Retrieval: The file system implementation determines how the data is read buffer can hold the contents of the disk block and the cache stores frequently used file
from and written to the physical storage device. This includes strategies such as system metadata.
buffering and caching to optimize file I/O performance. 3. File organization Module – It has information about files, the location of files and
4. Security and Permissions: The file system implementation includes features for their logical and physical blocks. Physical blocks do not match with logical numbers
managing file security and permissions. This includes access control lists (ACLs), file of logical blocks numbered from 0 to N. It also has a free space that tracks unallocated
permissions, and ownership management. blocks.
5. Recovery and Fault Tolerance: The file system implementation includes features 4. Logical file system – It manages metadata information about a file i.e includes all
for recovering from system failures and maintaining data integrity. This includes details about a file except the actual contents of the file. It also maintains via file
techniques such as journaling and file system snapshots. control blocks. File control block (FCB) has information about a file – owner, size,
File system implementation is a critical aspect of an operating system as it directly permissions, and location of file contents.
impacts the performance, reliability, and security of the system. Different operating
systems use different file system implementations based on the specific needs of the Advantages
1. Duplication of code is minimized.
57 58
Operating System Operating System
2. Each file system can have its own logical file system. 8. Per-process open-file table – It contains information opened by that particular
3. File system implementation in an operating system provides several advantages, including: process and it maps with the appropriate system-wide open-file.
4. Efficient Data Storage: File system implementation ensures efficient data storage on a 9. Linear List – It maintains a linear list of filenames with pointers to the data blocks.
physical storage device. It provides a structured way of organizing files and directories, It is time-consuming also. To create a new file, we must first search the directory to be
which makes it easy to find and access files. sure that no existing file has the same name then we add a file at the end of the
5. Data Security: File system implementation includes features for managing file security and directory. To delete a file, we search the directory for the named file and release the
permissions. This ensures that sensitive data is protected from unauthorized access. space. To reuse the directory entry either we can mark the entry as unused or we can
6. Data Recovery: The file system implementation includes features for recovering from attach it to a list of free directories.
system failures and maintaining data integrity. This helps to prevent data loss and ensures 10.Hash Table – The hash table takes a value computed from the file name and returns
that data can be recovered in the event of a system failure. a pointer to the file. It decreases the directory search time. The insertion and deletion
7. Improved Performance: File system implementation includes techniques such as buffering process of files is easy. The major difficulty is hash tables are its generally fixed size
and caching to optimize file I/O performance. This results in faster access to data and and hash tables are dependent on the hash function of that size.
improved overall system performance.
8. Scalability: File system implementation can be designed to be scalable, making it possible Implementation Issues
to store and retrieve large amounts of data efficiently.
9. Flexibility: Different file system implementations can be designed to meet specific needs
and use cases. This allows developers to choose the best file system implementation for Management of disc space: To prevent space wastage and to guarantee that files can
their specific requirements. always be stored in contiguous blocks, file systems must manage disc space effectively. Free
10. Cross-Platform Compatibility: Many file system implementations are cross-platform space management, fragmentation prevention, and garbage collection are methods for
compatible, which means they can be used on different operating systems. This makes it managing disc space.
easy to transfer files between different systems. Checking for consistency and repairing errors: The consistency and error-free
In summary, file system implementation in an operating system provides several operation of files and directories must be guaranteed by file systems. Journaling,
advantages, including efficient data storage, data security, data recovery, improved performance, checksumming, and redundancy are methods for consistency checking and error recovery.
scalability, flexibility, and cross-platform compatibility. These advantages make file system File systems may need to perform recovery operations if errors happen in order to restore
implementation a critical aspect of any operating system. lost or damaged data.
Locking files and managing concurrency: To prevent conflicts and guarantee data
Disadvantages integrity, file systems must control how many processes or users can access a file at once.
If we access many files at the same time then it results in low performance. We File locking, semaphore, and other concurrency-controlling methods are available.
can implement a file system by using two types of data structures : Performance optimization: File systems need to optimize performance by reducing file
1. Boot Control Block – It is usually the first block of volume and it contains access times, increasing throughput, and minimizing system overhead. Caching, buffering,
information needed to boot an operating system. In UNIX it is called the boot block prefetching, and parallel processing are methods for improving performance.
and in NTFS it is called the partition boot sector.
2. Volume Control Block – It has information about a particular partition ex:- free Key Steps Involved In File System Implementation
block count, block size and block pointers, etc. In UNIX it is called superblock and in
NTFS it is stored in the master file table.
File system implementation is a crucial component of an operating system, as it provides an
3. Directory Structure – They store file names and associated inode numbers. In
interface between the user and the physical storage device. Here are the key steps involved
UNIX, includes file names and associated file names and in NTFS, it is stored in the
in file system implementation:
master file table.
4. Per-File FCB – It contains details about files and it has a unique identifier number to 1. Partitioning the storage device: The first step in file system implementation is to
allow association with the directory entry. In NTFS it is stored in the master file table. partition the physical storage device into one or more logical partitions. Each partition
5. Mount Table – It contains information about each mounted volume. is formatted with a specific file system that defines the way files and directories are
6. Directory-Structure cache – This cache holds the directory information of recently organized and stored.
accessed directories. 2. File system structures: File system structures are the data structures used by the
7. System-wide open-file table – It contains the copy of the FCB of each open file. operating system to manage files and directories. Some of the key file system

59 60
Operating System Operating System
structures include the superblock, inode table, directory structure, and file allocation d indicates a directory
table.
3. Allocation of storage space: The file system must allocate storage space for each The following nine characters represent permissions for different classes of users. Users on a
file and directory on the storage device. There are several methods for allocating Unix system are assigned to a group or groups, which might correspond to a particular
storage space, including contiguous, linked, and indexed allocation. department, or research group in the real world. Members of a particular group can be
4. File operations: The file system provides a set of operations that can be performed allowed access to files belonging to other members of the group.
on files and directories, including create, delete, read, write, open, close, and seek.
These operations are implemented using the file system structures and the storage The second, third and fourth characters in the permissions string represent permissions that
allocation methods. apply to the owner of the file. The next three characters apply to members of the owner's
5. File system security: The file system must provide security mechanisms to protect group. The last three apply to all other users. The file in this example therefore has rw- for
files and directories from unauthorized access or modification. This can be done by the owner, r-- for the group and r-- for others.
setting file permissions, access control lists, or encryption.
6. File system maintenance: The file system must be maintained to ensure efficient The three characters corresponding to each class of user each represent a different type of
and reliable operation. This includes tasks such as disk defragmentation, disk permission. The first character represents 'read' permission. This means that a user has
checking, and backup and recovery. permission to open a file and view the contents. If there is an r in this position then that class
of users has read permission. In this example all users have read permission. In this, and in
Overall, file system implementation is a complex and critical component of an
every case, a horizontal bar character (-) means that permission is denied.
operating system. The efficiency and reliability of the file system have a significant impact
on the performance and stability of the entire system The second position represents 'write' permission (the right to make changes to a file). In the
What are file permissions? example, only the owner has write permission. Normally, you will not want others to be
allowed to make changes to your files, so write permission is only allowed to the owner.
The Unix file security system can prevent unauthorised users from reading or altering files.
The third position represents 'execute permission'. This means permission to 'execute', or run,
Every file and directory has specific permissions associated with it, giving different a file that works like a command. In this example no-one has execute permission for the
categories of user certain permissions to look at or change a file, and to run executable files. file lookup.icn (it is an Icon program, and it would have to be compiled before it could be
executed, so execute permission would be useless). To summarise the above, this is how the
NOTE Executable files are files containing commands than can themselves be executed as if permissions string is divided up:
the file itself were a command.
- rw- r-- r--
The file permissions can be displayed using the command: type of file owner group others

% ls -l [filename] Here is another example, this time an executable file:

For example, to display the permissions on the file lookup.icn, type the command: -rwxr-x--x 1 lnp5jb 562 Jan 10 hello

% ls -l lookup.icn
-rw-r--r-- 1 lnp5jb 777 Dec 18 lookup.icn Changing permission modes

The first set of characters in the output from the command (-rw-r--r--) gives the permissions. In this chapter, we will discuss in detail about file permission and access modes in Unix.
The username in the middle of the line (lnp5jb) is the owner of the file. This is user who File ownership is an important component of Unix that provides a secure method for storing
created the file. The following fields tell you the number of characters in the file, the date it files. Every file in Unix has the following attributes −
was created and the name of the file.
• Owner permissions − The owner's permissions determine what actions the owner of
Note that the first character specifies the file type. This is normally one of the following: the file can perform on the file.
• Group permissions − The group's permissions determine what actions a user, who is
- indicates a file a member of the group that a file belongs to, can perform on the file.
61 62
Operating System Operating System
• Other (world) permissions − The permissions for others indicate what action all other Directory Access Modes
users can perform on the file.
The Permission Indicators Directory access modes are listed and organized in the same manner as any other file. There
are a few differences that need to be mentioned −
While using ls -l command, it displays various information related to file permission as follows
− Read

$ls -l /home/amrood Access to a directory means that the user can read the contents. The user can look at
-rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile the filenames inside the directory.
drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir
Write
Here, the first column represents different access modes, i.e., the permission associated with
a file or a directory. Access means that the user can add or delete files from the directory.

The permissions are broken into groups of threes, and each position in the group denotes a Execute
specific permission, in this order: read (r), write (w), execute (x) −
Executing a directory doesn't really make sense, so think of this as a traverse permission.
• The first three characters (2-4) represent the permissions for the file's owner. For
example, -rwxr-xr-- represents that the owner has read (r), write (w) and execute (x) A user must have execute access to the bin directory in order to execute the ls or
permission. the cd command.
• The second group of three characters (5-7) consists of the permissions for the group to
which the file belongs. For example, -rwxr-xr-- represents that the group has read (r) and Changing Permissions
execute (x) permission, but no write permission.
• The last group of three characters (8-10) represents the permissions for everyone else. For To change the file or the directory permissions, you use the chmod (change mode)
example, -rwxr-xr-- represents that there is read (r) only permission. command. There are two ways to use chmod — the symbolic mode and the absolute mode.
File Access Modes
Using chmod in Symbolic Mode
The permissions of a file are the first line of defense in the security of a Unix system. The
The easiest way for a beginner to modify file or directory permissions is to use the symbolic
basic building blocks of Unix permissions are the read, write, and execute permissions,
mode. With symbolic permissions you can add, delete, or specify the permission set you
which have been described below −
want by using the operators in the following table.
Read
Sr.No. Chmod operator & Description
Grants the capability to read, i.e., view the contents of the file.
1 +
Write Adds the designated permission(s) to a file or directory.

Grants the capability to modify, or remove the content of the file. 2 -


Removes the designated permission(s) from a file or directory.
Execute
3 =
Sets the designated permission(s).
User with execute permissions can run a file as a program.

Here's an example using testfile. Running ls -1 on the testfile shows that the file's
permissions are as follows −
63 64
Operating System Operating System
$ls -l testfile Read and write permission: 4 (read) + 2 (write)
-rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile 6 rw-
=6
Then each example chmod command from the preceding table is run on the testfile,
All permissions: 4 (read) + 2 (write) + 1
followed by ls –l, so you can see the permission changes − 7 rwx
(execute) = 7
$chmod o+wx testfile
$ls -l testfile Here's an example using the testfile. Running ls -1 on the testfile shows that the file's
-rwxrwxrwx 1 amrood users 1024 Nov 2 00:10 testfile permissions are as follows −
$chmod u-x testfile
$ls -l testfile $ls -l testfile
-rw-rwxrwx 1 amrood users 1024 Nov 2 00:10 testfile -rwxrwxr-- 1 amrood users 1024 Nov 2 00:10 testfile
$chmod g = rx testfile
$ls -l testfile Then each example chmod command from the preceding table is run on the testfile,
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile followed by ls –l, so you can see the permission changes −

Here's how you can combine these commands on a single line − $ chmod 755 testfile
$ls -l testfile
$chmod o+wx,u-x,g = rx testfile -rwxr-xr-x 1 amrood users 1024 Nov 2 00:10 testfile
$ls -l testfile $chmod 743 testfile
-rw-r-xrwx 1 amrood users 1024 Nov 2 00:10 testfile $ls -l testfile
Using chmod with Absolute Permissions -rwxr---wx 1 amrood users 1024 Nov 2 00:10 testfile
$chmod 043 testfile
The second way to modify permissions with the chmod command is to use a number to $ls -l testfile
specify each set of permissions for the file. ----r---wx 1 amrood users 1024 Nov 2 00:10 testfile
Changing Owners and Groups
Each permission is assigned a value, as the following table shows, and the total of each
set of permissions provides a number for that set. While creating an account on Unix, it assigns a owner ID and a group ID to each user.
All the permissions mentioned above are also assigned based on the Owner and the
Number Octal Permission Representation Ref Groups.

0 No permission --- Two commands are available to change the owner and the group of files −

1 Execute permission --x • chown − The chown command stands for "change owner" and is used to change the
owner of a file.
2 Write permission -w- • chgrp − The chgrp command stands for "change group" and is used to change the
group of a file.
Execute and write permission: 1 (execute) + 2 Changing Ownership
3 -wx
(write) = 3
The chown command changes the ownership of a file. The basic syntax is as follows −
4 Read permission r--
$ chown user filelist
Read and execute permission: 4 (read) + 1
5 r-x
(execute) = 5 The value of the user can be either the name of a user on the system or the user id (uid) of a
user on the system.
65 66
Operating System Operating System
The following example will help you understand the concept − This is the case with SGID as well. Normally, programs execute with your group
permissions, but instead your group will be changed just for this program to the group owner
$ chown amrood testfile of the program.
$
The SUID and SGID bits will appear as the letter "s" if the permission is available. The
Changes the owner of the given file to the user amrood. SUID "s" bit will be located in the permission bits where the owners’ execute permission
normally resides.
NOTE − The super user, root, has the unrestricted capability to change the ownership of any
file but normal users can change the ownership of only those files that they own. For example, the command −
Changing Group Ownership $ ls -l /usr/bin/passwd
-r-sr-xr-x 1 root bin 19031 Feb 7 13:47 /usr/bin/passwd*
The chgrp command changes the group ownership of a file. The basic syntax is as follows − $
$ chgrp group filelist Shows that the SUID bit is set and that the command is owned by the root. A capital
letter S in the execute position instead of a lowercase s indicates that the execute bit is not
The value of group can be the name of a group on the system or the group ID (GID) of a set.
group on the system.
If the sticky bit is enabled on the directory, files can only be removed if you are one of the
Following example helps you understand the concept − following users −
$ chgrp special testfile • The owner of the sticky directory
$ • The owner of the file being removed
• The super user, root
Changes the group of the given file to special group.
To set the SUID and SGID bits for any directory try the following command −
SUID and SGID File Permission
$ chmod ug+s dirname
Often when a command is executed, it will have to be executed with special privileges in $ ls -l
order to accomplish its task. drwsr-sr-x 2 root root 4096 Jun 19 06:45 dirname
As an example, when you change your password with the passwd command, your new Unix standard files:
password is stored in the file /etc/shadow.

As a regular user, you do not have read or write access to this file for security reasons, but Unix file system is a logical method of organizing and storing large amounts of
when you change your password, you need to have the write permission to this file. This information in a way that makes it easy to manage. A file is a smallest unit in which the
means that the passwd program has to give you additional permissions so that you can write information is stored. Unix file system has several important features. All data in Unix is
to the file /etc/shadow. organized into files. All files are organized into directories. These directories are organized
into a tree-like structure called the file system. Files in Unix System are organized into
Additional permissions are given to programs via a mechanism known as the Set User ID multi-level hierarchy structure known as a directory tree. At the very top of the file system
(SUID) and Set Group ID (SGID) bits. is a directory called “root” which is represented by a “/”. All other files are “descendants”
of root.
When you execute a program that has the SUID bit enabled, you inherit the permissions of
The Unix file system is a hierarchical file system used by Unix-based operating systems to
that program's owner. Programs that do not have the SUID bit set are run with the
store and organize files and directories. It is a tree-like structure that starts with a single
permissions of the user who started the program.
directory called the root directory, which is denoted by a forward slash (/) character.

67 68
Operating System Operating System
The Unix file system uses a directory hierarchy that allows for easy navigation and • /media : Default mount point for removable devices, such as USB sticks, media
organization of files. Directories can contain both files and other directories, and each file players, etc.
or directory has a unique name. • /mnt : Stands for “mount”. Contains filesystem mount points. These are used, for
example, if the system uses multiple hard disks or hard disk partitions. It is also often
Unix file system also uses a set of permissions to control access to files and directories.
used for remote (network) filesystems, CD-ROM/DVD drives, and so on.
Each file and directory has an owner and a group associated with it, and permissions can be
• /proc : procfs virtual filesystem showing information about processes as files.
set to allow or restrict access to these entities.
• /root : The home directory for the superuser “root” – that is, the system
administrator. This account’s home directory is usually on the initial filesystem, and
One of the most important features of the Unix file system is its support for hence not in /home (which may be a mount point for another filesystem) in case
symbolic links, which are pointers to other files or directories. This allows for flexible specific maintenance needs to be performed, during which other filesystems are not
organization of files and directories without having to physically move them around. available. Such a case could occur, for example, if a hard disk drive suffers physical
failures and cannot be properly mounted.
Overall, the Unix file system is a robust and flexible system that has been used for decades • /tmp : A place for temporary files. Many systems clear this directory upon startup; it
and continues to be the foundation for many modern operating systems. might have tmpfs mounted atop it, in which case its contents do not survive a reboot,
or it might be explicitly cleared by a startup script at boot time.
• /usr : Originally the directory holding user home directories,its use has changed. It
now holds executables, libraries, and shared resources that are not system critical,
like the X Window System, KDE, Perl, etc. However, on some Unix systems, some
user accounts may still have a home directory that is a direct subdirectory of /usr,
such as the default as in Minix. (on modern systems, these user accounts are often
related to server or system use, and not directly used by a person).
• /usr/bin : This directory stores all binary programs distributed with the operating
system not residing in /bin, /sbin or (rarely) /etc.
• /usr/include : Stores the development headers used throughout the system. Header
files are mostly used by the #include directive in C/C++ programming language.
• /usr/lib : Stores the required libraries and data files for programs stored within /usr
or elsewhere.
• /var : A short for “variable.” A place for files that may change often – especially in
size, for example e-mail sent to users on the system, or process-ID lock files.
• /var/log : Contains system log files.
Directories or Files and their description – • /var/mail : The place where all the incoming mails are stored. Users (other than
• / : The slash / character alone denotes the root of the filesystem tree.
root) can access their own mail only. Often, this directory is a symbolic link to
• /bin : Stands for “binaries” and contains certain fundamental utilities, such as ls or
/var/spool/mail.
cp, which are generally needed by all users. • /var/spool : Spool directory. Contains print jobs, mail spools and other queued tasks.
• /boot : Contains all the files that are required for successful booting process.
• /var/tmp : A place for temporary files which should be preserved between system
• /dev : Stands for “devices”. Contains file representations of peripheral devices and
reboots.
pseudo-devices.
• /etc : Contains system-wide configuration files and system databases. Originally also
contained “dangerous maintenance utilities” such as init,but these have typically
been moved to /sbin or elsewhere.
• /home : Contains the home directories for the users.
• /lib : Contains system libraries, and some critical files such as kernel modules or
device drivers.

69 70
Operating System Operating System
Types of Unix files – The UNIX files system contains several different types of files • When a block special file is used for device Input/Output(I/O), data is transferred in
large fixed-size blocks. This type of access is called block device access.
For terminal devices, it’s one character at a time. For disk devices though, raw access
means reading or writing in whole chunks of data – blocks, which are native to your
disk.
• In long-format output of ls -l, character special files are marked by the “c” symbol.
• In long-format output of ls -l, block special files are marked by the “b” symbol.
4. Pipes – UNIX allows you to link commands together using a pipe. The pipe acts a
temporary file which only exists to hold data from one command until it is read by
another.A Unix pipe provides a one-way flow of data.The output or result of the first
command sequence is used as the input to the second command sequence. To make a
pipe, put a vertical bar (|) on the command line between two commands.For
example: who | wc -l In long-format output of ls –l , named pipes are marked by the “p”
symbol.
5. Sockets – A Unix socket (or Inter-process communication socket) is a special file
: which allows for advanced inter-process communication. A Unix Socket is used in a
1. Ordinary files – An ordinary file is a file on the system that contains data, text, or client-server application framework. In essence, it is a stream of data, very similar to
program instructions. network stream (and network sockets), but all the transactions are local to the
• Used to store your information, such as some text you have written or an image you filesystem. In long-format output of ls -l, Unix sockets are marked by “s” symbol.
have drawn. This is the type of file that you usually work with. 6. Symbolic Link – Symbolic link is used for referencing some other file of the file
• Always located within/under a directory file. system.Symbolic link is also known as Soft link. It contains a text form of the path to
• Do not contain other files. the file it references. To an end user, symbolic link will appear to have its own name,
• In long-format output of ls -l, this type of file is specified by the “-” symbol. but when you try reading or writing data to this file, it will instead reference these
2. Directories – Directories store both special and ordinary files. For users familiar operations to the file it points to. If we delete the soft link itself , the data file would still
with Windows or Mac OS, UNIX directories are equivalent to folders. A directory file be there.If we delete the source file or move it to a different location, symbolic file will
contains an entry for every file and subdirectory that it houses. If you have 10 files in a not function properly. In long-format output of ls –l , Symbolic link are marked by the
directory, there will be 10 entries in the directory. Each entry has two components. (1) “l” symbol (that’s a lower case L).
The Filename (2) A unique identification number for the file or directory (called the
inode number) Advantages or Disadvantages:
• Branching points in the hierarchical tree.
• Used to organize groups of files.
Advantages of the Unix file system include:
• May contain ordinary files, special files or other directories.
• Never contain “real” information which you would work with (such as text).
Basically, just used for organizing files. 1. Hierarchical organization: The hierarchical structure of the Unix file system makes it
• All files are descendants of the root directory, ( named / ) located at the top of the
easy to organize and navigate files and directories.
tree. 2. Robustness: The Unix file system is known for its stability and reliability. It can
In long-format output of ls –l , this type of file is specified by the “d” symbol. 3. Special handle large amounts of data without becoming unstable or crashing.
Files – Used to represent a real physical device such as a printer, tape drive or terminal, 3. Security: The Unix file system uses a set of permissions that allows administrators to
used for Input/Output (I/O) operations. Device or special files are used for device control who has access to files and directories.
Input/Output(I/O) on UNIX and Linux systems. They appear in a file system just like an 4. Compatibility: The Unix file system is widely used and supported, which means that
ordinary file or a directory. On UNIX systems there are two flavors of special files for files can be easily transferred between different Unix-based systems.
each device, character special files and block special files :
• When a character special file is used for device Input/Output(I/O), data is transferred
one character at a time. This type of access is called raw device access.
71 72
Operating System Operating System
Disadvantages of the Unix file system include: ▪ /dev/random -- This is a virtual file which contains random numbers (subject to
the limitations of Random Number Generators in Computing). It uses system
1. Complexity: The Unix file system can be complex to understand and manage, noise to generate random numbers and blocks if not enough entropy in the noise
especially for users who are not familiar with the command line interface. is available. Random is commonly used more by programs that absolutely
2. Steep learning curve: Users who are not familiar with Unix-based systems may find need high quality random data (such as SSH to generate an encryption key).
it difficult to learn how to use the Unix file system.
3. Lack of user-friendly interface: The Unix file system is primarily managed through ▪ /dev/urandom -- Same as /dev/random, except it always returns random
the command line interface, which may not be as user-friendly as a graphical user
numbers, even if there is not enough entropy in the system noise available. In
interface.
4. Limited support for certain file systems: While the Unix file system is compatible the latter case, pseudorandom numbers are generated, which are based on an
with many file systems, there are some file systems that are not fully supported. algorithm, depending on the type of Unix system.
Directory structure:
▪ /home -- contains the home directories for the users. On some Unices, this is
The Unix directory is a tree-like structure, usually drawn as an inverted tree, with at under /usr/home
the top a single directory, the root, from which subdirectories branch out. Each
subdirectory in turn can be the origin of a set of subdirectories. See the figure for a very ▪ /mnt -- This is the default location to mount external devices like hard disk
schematic illustration. drives, pen drives etc.
What follows is a generalized overview of common locations of files in a Unix system:
▪ /lib -- This is the depository of all integral UNIX system libraries.
▪ / (root) -- The / notes the "root" of the filesystem, where the entire system is
▪ /root -- the home directory for the superuser root.
contained. Unlike Microsoft Windows, where each drive has its own root directory
named by a letter, such as C:\ or F:\, Unix holds the entire system in this single top- ▪ /tmp -- a place for temporary files. Many Unices clear this directory upon start
level directory, including each device and document. Thus, it is commonly said that in up.
Unix, "everything is a file." Note that Unix uses the forward slash ( / ) rather than the
backslash ( \ ) commonly used in Windows. ▪ /usr -- originally the directory holding user home directories, its use has
changed, and it now holds executables, libraries, and shared resources that are
▪ /bin -- Stands for "binaries"; Contains some fundamental utilities needed by a not system critical: X11, KDE, PERL, LaTeX etc. (The name "Unix System
system administrator. But also user commands as cp (file copy), rm (file Resources" is a post hoc backronym.)
delete), ls (list files in directory), etc. As a failsafe, these were placed in a
separate directory so that they could be placed on a separate disk or disk ▪ /usr/bin -- This directory stores the executables that live in /usr.
partition in case the main drive failed.
▪ /usr/include -- /usr/include stores the development headers used throughout the
▪ /etc -- Contains configuration files and some system databases. system.

▪ /dev -- short for devices. Contains file representations of every peripheral device ▪ /usr/lib -- The required libraries for executables within /usr or elsewhere for that
attached to the system. matter, live here.

▪ /dev/null -- Also known as the "bit bucket" or "black hole", this virtual file ▪ /var -- short for "variable." A place for files that may change often, such as the
discards all contents written to it. This is typically used to throw away unwanted storage to a database, the contents of a database, log files (usually stored
data streams, such as log files. in /var/log), email stored on a server, etc.

▪ /var/log/ -- Storage for the system log files.


73 74
Operating System Operating System
▪ /var/mail/ -- the place where all the incoming mails are stored. The user can • If the files are smaller in size, searching will become faster.
access his/her own mail only unless he/she has admin rights. • The operations like file creation, searching, deletion, updating are very easy in such a
directory structure.
▪ /var/spool/ -- contains print jobs, mail spools and various other tasks that have • Logical Organization: Directory structures help to logically organize files and

been queued , waiting for some related task to finish. directories in a hierarchical structure. This provides an easy way to navigate and
manage files, making it easier for users to access the data they need.
• Increased Efficiency: Directory structures can increase the efficiency of the file
Types of Directories:
system by reducing the time required to search for files. This is because directory
A directory is a container that is used to contain folders and files. It organizes files structures are optimized for fast file access, allowing users to quickly locate the file
and folders in a hierarchical manner.
they need.
• Improved Security: Directory structures can provide better security for files by
allowing access to be restricted at the directory level. This helps to prevent
unauthorized access to sensitive data and ensures that important files are protected.
• Facilitates Backup and Recovery: Directory structures make it easier to backup and
recover files in the event of a system failure or data loss. By storing related files in
the same directory, it is easier to locate and backup all the files that need to be
protected.
• Scalability: Directory structures are scalable, making it easy to add new directories
and files as needed. This helps to accommodate growth in the system and makes it
easier to manage large amounts of data.
Disadvantages:
• There may chance of name collision because two files can have the same name.

There are several logical structures of a directory, these are given below. • Searching will become time taking if the directory is large.
• This can not group the same type of files together.
1) Single-level directory: 2) Two-level directory:
As we have seen, a single level directory often leads to confusion of files names
The single-level directory is the simplest directory structure. In it, all among different users. The solution to this problem is to create a separate directory for
files are contained in the same directory which makes it easy to support and understand. each user.
A single level directory has a significant limitation, however, when the number of files In the two-level directory structure, each user has their own user files directory
increases or when the system has more than one user. Since all the files are in the same (UFD). The UFDs have similar structures, but each lists only the files of a single user.
directory, they must have a unique name. If two users call their dataset test, then the System’s master file directory (MFD) is searched whenever a new user id is correct.
unique name rule violated.

Advantages:
• Since it is a single directory, so its implementation is very easy.

75 76
Operating System Operating System

Advantages:
Advantages:
• The main advantage is there can be more than two files with same name, and would
• This directory structure allows subdirectories inside a directory.
be very helpful if there are multiple users.
• The searching is easier.
• A security would be there which would prevent user to access other user’s files.
• File sorting of important and unimportant becomes easier.
• Searching of the files becomes very easy in this directory structure.
• This directory is more scalable than the other two directory structures explained.
Disadvantages:
Disadvantages:
• As there is advantage of security, there is also disadvantage that the user cannot share
• As the user isn’t allowed to access other user’s directory, this prevents the file
the file with the other users.
sharing among users.
• Unlike the advantage users can create their own files, users don’t have the ability to
• As the user has the capability to make subdirectories, if the number of subdirectories
create subdirectories.
increase the searching may become complicated.
• Users cannot modify the root directory data.
3) Tree Structure/ Hierarchical Structure:
• If files do not fit in one, they might have to be fit into other directories.

Tree directory structure of operating system is most commonly used in our personal 4) Acyclic Graph Structure:
computers. User can create files and subdirectories too, which was a disadvantage in the
previous directory structures.
As we have seen the above three directory structures, where none of them have the
This directory structure resembles a real tree upside down, where the root directory is at
capability to access one file from multiple directories. The file or the subdirectory could be
the peak. This root contains all the directories for each user. The users can create
accessed through the directory it was present in, but not from the other directory.
subdirectories and even store files in their directory.
A user do not have access to the root directory data and cannot modify it. And, even in this This problem is solved in acyclic graph directory structure, where a file in one directory
directory the user do not have access to other user’s directories. The structure of tree can be accessed from multiple directories. In this way, the files could be shared in between
directory is given below which shows how there are files and subdirectories in each user’s the users. It is designed in a way that multiple directories point to a particular directory or
directory. file with the help of links.
In the below figure, this explanation can be nicely observed, where a file is shared between
multiple users. If any user makes a change, it would be reflected to both the users.

77 78
Operating System Operating System

Advantages:
• Sharing of files and directories is allowed between multiple users.
• Searching becomes too easy.
• Flexibility is increased as file sharing and editing access is there for multiple users.
Disadvantages:
• Because of the complex structure it has, it is difficult to implement this directory structure.
• The user must be very cautious to edit or even deletion of file as the file is accessed by
multiple users.
• If we need to delete the file, then we need to delete all the references of the file inorder
to delete it permanently.

79 80
Operating System

81

You might also like