Operating System Operating System
Operating System Operating System
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.
Unit III
Synchronization: Background, The critical section problem.
Unit IV
Memory Management: Background, Basic hardware, Address Binding, Swapping,
Contiguous memory allocation,
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.
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
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.
10. Job accounting: Keeping track of time & resource used by various job and users.
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:
• 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.
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.
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.
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
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
P1 P2 P3 P4 P5 P6 P7 P8 P9
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
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:
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
then the effective access time would be = m(page table) + m(page in page table)
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
F0 P2 P1
F1 P0 P1
F1
0
F3 F2
1
2 F0 F5
F4
3
• 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.
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
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.
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 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
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
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:
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.
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.
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
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.
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.
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