This Tutorial will provide you information on working of operating system. Main topics are following and further sub-topics are discussed in detail.
1. Kernel Architecture.
2. Initialization of operating system.
3. Process of operating system.
4. Management in operating system.
5. File system.
6.Security in operating system.
7.Interface in operating System.
3. OPERATING SYSTEM
⢠OS is a system software that runs the hardware.
⢠It enables the application to interact with hardware.
⢠It handles input output ,control peripheral devices, manage processes and
communicates with resources.
⢠Found on cellular phones, web servers, automobile,
video game consoles and PCs.
⢠Windows OS, Embedded OS, Unix OS ,Linux OS
5. Kernel:
⢠Kernel is a central module of operating system.
⢠It is the first program loaded on start up and remains in main memory.
⢠Kernel connects application software to hardware and provide
services.
⢠Typically responsible for Memory Management, Device Management
and System Calls.
⢠Monolithic kernels, Exokernels, Micro kernels,
Hybrid kernels etc.
6. Types of kernels:
Typically based on the security level or abstraction level.
â˘Monolithic Kernel:
ďź Entire operating system works in
Kernel Space.
ďź It is fast but larger than other kernels
and difficult to debug.
ďź Linux, Unix , DOS, Windows 95 and
many more.
â˘Micro Kernel:
ďź Small in size divided the servers in
kernel space and user space.
ďź Slower than Monolithic kernel but easy
to debug and secure.
ďź Symbian, iOS, MINIX 3, XNu
8. Hybrid kernel:
⢠Combination of Monolithic kernel and Micro kernel Architecture.
⢠Both technology architectures are used to take benefits.
⢠Two layers are being setup user space and kernel space.
⢠Windows NT, Windows Server 2012, Xbox one, Windows phone 8
11. Initialization:
⢠Initialization is the process of how the computer boots and loads.
⢠Computer initialization runs a series of tests to verify efficiency and load
drivers for the system
⢠Two processes discussed
⢠Bootloader
⢠Hardware Initialization
12. Interrupts:
⢠Interrupt is a signal to the processor emitted by hardware or software
indicating an event that needs immediate attention
⢠The interrupt handler prioritizes the interrupts
⢠Interrupts give the user better control over the computer.
⢠2 types of interrupts
⢠Hardware Interrupts are generated by hardware
devices
⢠A software interrupt is caused by an exceptional
condition in the processor
13. Context switching:
⢠Switching of the CPU from one process or thread to another.
⢠Also called âprocess switch or a task switchâ
⢠Essential feature of multitasking operating systems
⢠Requires considerable processor time
14. Scheduling:
⢠Act of determining which process in the ready state should be moved to
the running state
⢠The prime aim of the process scheduling system is to deliver minimum
response time for all programs & make the system efficient, fast and fair.
⢠Scheduling allows multiple users to share system resources effectively
⢠Scheduler figures out which program to give control to next.
15. Difference between preemptive and non
preemptive scheduling:
â˘Preemptive
⢠The process with the highest
priority should always be the one
currently using the resources.
⢠Resources are only allocated for a
limited time and the process can be
interrupted in between
⢠Scheduling which takes place when
a process switches from running
state to ready state or vice versa
â˘Non-preemptive
⢠A process runs to completion when
scheduled
⢠Once resources are allocated to a
process, the process holds it till it
completes its time
⢠The scheduling which takes place
when a process terminates or
switches from running to waiting
state
16. Concurrent processes:
⢠Computing model in which multiple processes executing during the same
period of time
â˘Advantages:
⢠Increased program throughput
⢠High responsiveness for input/output
⢠More appropriate program structure
17. Inter process communication (IPC):
⢠Mechanism that allows the exchange of data between processes
â˘Advantages:
⢠Helps a programmer organize the activities among different
processes.
⢠Allows one application to control another application, thereby
enabling data sharing without interference.
⢠Facilitates efficient message transfer between processes
⢠Enables data communication by allowing to share memory and
information
19. Hardware initialization:
⢠All processor based boards need testing to confirm the correctness of
hardware design and proper functioning of various peripherals
⢠It is a process used to check the proper functioning of all the hardware
components in a system.
20. Bootloader (boot process/bootstrap):
⢠Bootloader is a piece of code that runs before any operating system is
running.
⢠It is loaded by the computer's BIOS ROM
⢠It is highly processor and board specific.
⢠The bootloader performs the necessary initializations to prepare the system
for the operating system.
⢠It tells the computer what to do after the system is turned on.
21. Scheduling criteria:
⢠CPU utilization
⢠Throughput
⢠Turnaround time
⢠Waiting time
⢠Load average
⢠Response time
22. Scheduling:
â˘First come first served
⢠Jobs are executed on first come, first serve basis.
⢠Easy to understand and implement
⢠Poor in performance as average wait time is high.
⢠Shortest remaining time
⢠Selects the process for execution which has the
smallest amount of time remaining until completion .
⢠It mostly gives minimum average waiting time.
23. Scheduling:
â˘Round Robin Scheduling
⢠Very common base policy.
⢠Run each process for its time duration (scheduling
quantum)
⢠After each time slice (duration), moves the running
process to the back of the queue.
⢠Priority Scheduling
⢠Priority scheduling is a method of scheduling processes
based on priority
⢠Processes with higher priorities are carried out first
⢠Priority can be decided based on memory requirements,
time requirements or any other resource requirement.
24. Scheduling:
â˘Shortest job next
⢠Also known as shortest process next, shortest job first, or
SJF
⢠Best approach to minimize waiting time.
⢠The shortest job is executed first
⢠Preemptive SJF is called SRTF - shortest remaining time
ďŹrst.
25. Deadlock:
⢠Deadlocks are a set of blocked processes each holding a resource and
waiting to acquire a resource held by another process.
⢠Deadlock occurs if any one of the condition is true
⢠Mutual exclusion condition
⢠Hold and wait condition
⢠No preemption condition
⢠Circular wait condition
⢠Deadlock causes a process to freeze.
⢠Deadlock causes starvation
26. Starvation and livelock:
â˘Starvation:
⢠A process is in starvation when it is waiting for a resource that
is continuously given to other processes.
⢠The entire system of processes hasn't come to halt in
starvation
â˘Livelock:
⢠situation in which two or more processes continuously change
their state in response to changes in the other process(es)
without doing any useful work.
⢠Neither process is blocked or waiting for resources in case of a
livelock
29. Locks & signals:
â˘Locks:
⢠used to prevent multiple threads from accessing a resource at
the same time
â˘Signals:
⢠The mechanism whereby processes are made aware of events
occurring
⢠Sent to the current process telling it what it needs to do
30. Semaphores:
⢠Non negative integer variable used to do the following tasks
⢠check the availability of resources for a task
⢠control access to a common resource by
multiple processes
⢠A system to ensure process cannot enter critical
region if another process is in itâs
⢠2 types
⢠Binary semaphore(value either 0 or 1)
⢠Counting semaphore(value greater than 1)
34. What does mutual exclusion (mutex) mean?
⢠A mutual exclusion (mutex) is a program object that prevents
simultaneous access to a shared resource
⢠. This concept is used in concurrent programming with a critical section,
a piece of code in which processes or threads access a shared resource
⢠. Only one thread owns the mutex at a time, thus a mutex with a unique
name is created when a program starts
35. Physical memory:
⢠Physical memory refers to the actual RAM of the system,.
⢠Also called primary memory.
⢠it is the only storage type directly accessibly to the CPU.
⢠Holds the instructions of programs to execute.
36. Segmentation:
⢠A segment has a set of permissions, and a length, associated with it.
⢠It may also have a flag indicating whether the segment is present in
main memory or not; if the segment is not present in main memory,
an exception is raised, and the operating system will read the
segment into memory from secondary storage
⢠A memory management unit (MMU) is responsible for translating a
segment
37. Virtual memory:
⢠Virtual memory is a memory management technique that offers two
main benefits:
⢠Each process "thinks" it has all the system's memory to itself
⢠It becomes possible to access more memory than the actual physical
amount
⢠Virtual memory is very useful and is implemented in most operating
systems by using the memory management unit (MMU) in the CPU.
38. Paging:
⢠In computer operating systems there are various ways in which the
operating system can store and retrieve data from secondary storage for
use in main memory.
⢠One such memory management scheme is referred to as paging.
⢠In the paging memory-management scheme, the operating system
retrieves data from secondary storage in same-size blocks called pages.
39. Swapping:
⢠Swapping concept comes in terms of process scheduling.
⢠Medium term scheduler removes process from CPU for duration and reduce the
degree of multiprogramming.
⢠After some time these process can again be reintroduced into main memory.
⢠Process execution will again be resumed from the point it left CPU.
⢠This scheme is called swapping.
⢠More generally we can say swapping is removing of process from memory to
secondary memory and again back to main memory.
40. ⢠Memory management handles primary memory and moves processes
back and forth between main memory and disk during execution.
⢠Memory management keeps track of each and every memory location.
⢠It checks how much memory is to be allocated to processes.
⢠It decides which process will get memory at what time.
⢠It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
Memory management:
41. Fault tolerance:
⢠Fault tolerance is the property that enables a system to continue
operating properly in the event of the failure of (or one or more faults
within) some of its components.
⢠If its operating quality decreases at all, the decrease is proportional to
the severity of the failure, as compared to a naively designed system in
which even a small failure can cause total breakdown.
42. File system, Abstraction:
⢠A file system is a way of organizing information on a physical drive or other
media (e.g. RAM) for access. In general, file systems can be divided into several
groups:
⢠With a filesystem, we can organize our data into files, directories, and other
constructs, and manipulate them in various ways.
⢠To open a file, you need only its path; it's not necessary to figure out the exact
location on disk and instruct the hard drive controller to move the read head to
that position.
43. Allocation algorithm:
⢠Effective utilization of file space and fast access of the files.
There are three types of allocation:
1.contiguous allocation
2.linked allocation
3.indexed allocation
⢠In addition to storing the actual file data on the disk drive, the file system
also stores metadata about the files: the name of each file, when it was last
edited, exactly where it is on the disk, and what parts of the disk are "free".
Free areas are not currently in use by the file data or the metadata, and so
available for storing new files. (The places where this metadata is stored are
often called "inodes", "chunks", "file allocation tables", etc.)
44. Fault tolerance:
⢠fault-tolerance refers to the ability of something to continue to function
(though perhaps at reduced levels) after something as gone wrong.
⢠Many things can go wrong in a storage system, especially one with
moving parts like hard disk drives.
⢠Bad sectors only prevent the use of a few sectors, while a head crash can
permanently ruin an entire disk.
45. Raid:
⢠RAID (Redundant Array of Independent Disks) is a method of storing
data combines multiple physical drives into one unit.
⢠Data is distributed and duplicated across the drives in various ways.
⢠The term has now come to mean any technology that divides and
replicates data over multiple drives.
46. Journaling:
⢠Journaling is a technique for fault tolerance in file systems.
⢠It works by keeping track of all changes in a log (a "journal") before
committing the changes themselves to disk.
⢠This makes crashes and power failures easier to recover from and less
likely to cause permanent data loss or space leakage.
48. New technology file system, ext4:
⢠NTFS is a file system by Microsoft. This is default file system of Windows NT,
Windows Server, Windows XP, and Windows Vista, Windows 7.
⢠There are open-source applications that are able to reliably read/write to it.
⢠ext4 is the open source file system used on many Linux distributions,
including Android 2.3 and later. It is a journaled file system, like its
predecessor ext3.
49. Otherâs file system:
⢠Operating systems tend to recommend using
(and so support natively) file systems
specifically designed for them; for example,
NTFS in Windows and ext3 and ReiserFS in
Linux. However, in practice, third party drivers
are usually available to give support for the
most widely used file systems in most general-
purpose operating systems (for example, NTFS
is available in Linux through NTFS-3g, and
ext2/3 and ReiserFS are available in Windows
through third-party software).
50. Security:
⢠It is the process of ensuring OS
Integrity, confidentiality and
availability.
⢠OS security refers to specified
steps or measures used to protect
the OS from threats, viruses,
worms, malware or remote hacker
intrusions
52. User interface (UI):
⢠The means by which the user and a computer system interact, in particular the
use of input devices and software.
⢠System users often judge a system by its interface rather than its functionality.
⢠Poor user interface design is the reason why so many software systems are
never used
⢠Types : 1. CLI 2. GUI
53. CLI:
a. User types commands to instruct
system e.g. Unix
b. May be implemented using cheap
terminals.
c. Easy to process using compiler
techniques
d. Commands of arbitrary complexity can
be created by command combination.
GUI :
a. Fast, full-screen interaction
b. The user may switch quickly from one
task to another
c. Interact with several different
applications.
They may have just received some data (e.g., keystrokes on the keyboard or an data on the ethernet card); or they have just completed a task which the operating system previous requested, such as transferring data between the hard drive and memory.
Without interrupts, a user may have to wait for a given application to have a higher priority over the CPU to be ran. This ensures that the CPU will deal with the process immediately.
They are signals sent to the CPU by external devices, normally I/O devices.
Interrupts tell the CPU to stop its current activities and execute the appropriate part of the operating system.
and saves them in a queue if more than one is waiting to be handled.
Software interrupts e.g. divide by zero generates a flag in the micro processor that something is not right i.e. the instruction given is not valid which in turn generates the interrupts that something is not right i.e. the instruction given to the processor is incorrect or invalid. They can be any kind of math error
A context is the contents of a CPU's registers and program counter at any point in time.
A multitasking operating system is one in which multiple processes execute on a single CPU seemingly simultaneously and without interfering with each other.
In computing, a context switch is the process of storing and restoring the state (more specifically, the execution context) of a process or thread so that execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU and is an essential feature of a multitasking operating system.
Processes
A process (also sometimes referred to as a task) is an executing (i.e., running) instance of a program
Used to carry out every task that needs to be performed by the computer.
The time lagged between the input and the output signal which depends upon the value of passive components used is the response time
Scheduling makes it possible to have computer multitasking with a single CPU
A "ready" or "waiting" process has been loaded into main memory and is awaiting execution on a CPU
A process moves into the running state when it is chosen for execution
CPU scheduling is a process which allows one process to use the CPU while the execution of another process is on hold(in waiting state) due to unavailability of any resource like I/O etc., thereby making full use of CPU.Â
If a process is currently using the processor and a new process with a higher priority enters, the ready list, the process on the processor should be removed and returned to the ready list until it is once again the highest-priority process in the system
ability of the operating system to preempt (that is, stop or pause) a currently scheduled task in favor of a higher priority task
Tasks are broken down into subtasks that are then assigned to separate processors to perform simultaneously, instead of sequentially as they would have to be carried out by a single processor
Increased program throughputâparallel execution of a concurrent program allows the number of tasks completed in a given time to increase.
High responsiveness for input/outputâConcurrent programming allows the time that would be spent waiting for input or output operations to complete to be used for another task.
More appropriate program structureâsome problems and problem domains are well-suited to representation as concurrent tasks or processes
multiple processors execute instructions simultaneously for better performance i.e.
One bootloader is located in the BIOS ROM and the second is located Hard disk
OS booting is done after ROM booting
Boot record is located in Hard disk(boot sector) which loads the OS
Each operating system has a set of bootloaders specific for it.
The role of a boot loader is to load an operating system from a storage device, set up a minimal environment in which the OS can run, and run the operating system's startup procedure
the boot loader is only allowed to have a very small size,
It spawns (or starts) processes that run the display, interact with the keyboard, run the mouse, and interact with disk drives
Scheduling Criteria
There are many different criterias to check when considering the "best" scheduling algorithm :
CPU utilization
To make out the best use of CPU and not to waste any CPU cycle, CPU would be working most of the time
Throughput
It is the total number of processes completed per unit time or rather say total amount of work done in a unit of time.
Turnaround time
It is the amount of time taken to execute a particular process, i.e. The interval from time of submission of the process to the time of completion of the process (Wall clock time).
Waiting time
The sum of the periods spent waiting in the ready queue amount of time a process has been waiting in the ready queue to acquire get control on the CPU.
Load average
It is the average number of processes residing in the ready queue waiting for their turn to get into the CPU.
Response time
Amount of time it takes from when a request was submitted until the first response is produced. Remember, it is the time till the first response and not the completion of process execution (final response).
In general CPU utilization and Throughput are maximized and other factors are reduced for proper optimization.
Required CPU time should be known.
In batch system, required CPU time is known in advance
Easy to implement in Batch systems but impossible to implement in interactive systems
Larger the burst time lower is the priority
Preemptive priority scheduling will preempt the CPU if a high priority job arrives to ready queue
Round robin:
Designed for time-sharing systems
A process is allowed to run until the time slice period called time quantum, is reached
Then a clock interrupt occurs and the running process is dispatched
SJF is optimal i.e. gives minimum average waiting time for a given set of processes
By moving short jobs first it decreases wait times of these more than increase the wait times of long ones
Good for long term scheduling
Determines which programs are to be submitted for processing
Controls the degree of multi-programming
The processer should know in advance how much time process will take.
1- a resource cannot be used by more than one process at a time
2- processes already holding resources may request new resources
3- only a process holding a resource may release it
4- two or more processes form a circular chain where each process waits for a resource that the next process in the chain holds
Two or more processes become deadlocked when each of them is doing nothing while waiting for a resource occupied by another program in the same set
Deadlock: is when all the processes do not get access to resources because every process is waiting for some another process and there is cycle.
Deadlock is where a process is waiting for an event that will never occur.
A process is denied necessary resources to process its work.
A low priority process does not get access to the resources it needs because there is a high priority process accessing the resources.
often used so that multiple programs or threads of a program can share a resource
The area of a process which is sensitive to inter-process complications is called the critical region.
When a task is about to enter critical section or take shared resource, it first take semaphore if one task already has a semaphore, the other task cannot access it
It signals when and if the resource is free
. When a thread holds a resource, it has to lock the mutex from other threads to prevent concurrent access of the resource. Upon releasing the resource, the thread unlocks the mutex.
which usually takes the form of cards (DIMMs) attached onto the motherboard.
Physical memory is linearly addressable; memory addresses increase in a linear fashion and each byte is directly addressable.
Virtual memory adds a layer of abstraction over the physical memory, and offers many benefits such as the ability to maintain separate address spaces (per process perhaps), and the ability to use physical memory as a large cache for the physical disk which makes memory appear limitless (upto 2^(bus width)) from the program/programmers perspective.
Segmentation is one of the most common ways to achieve memory protection
In a computer system using segmentation, an instruction operand that refers to a memory location includes a value that identifies a segment
The information indicating where the segment is located in memory might be the address of the first location in the segment, or might be the address of a page table for the segment, if the segmentation is implemented with paging. In the first case, if a reference to a location within a segment is made, the offset within the segment will be added to address of the first location in the segment to give the address in memory of the referred-to item; in the second case, the offset of the segment is translated to a memory address using the page table.
This usage should not be confused with that of the memory segments used by early x86 processors such as the Intel 8086 and Intel 8088, as they did not provide any protection (any program could access any segment with no restrictions, and a segment consisted of only a starting location and a fixed length of 64 KiB); segmentation in the Intel 80286 and later provided protection.
and offset within that segment into a memory address, and for performing checks to make sure the translation can be done.
The second is accomplished by the MMU setting up a small, contiguous portion of the hard drive and treating it like physical RAM. That is, the operating system will place memory segments or pages into the file as if it were loading it into actual RAM. Thus, it has a place to hold "unused" pages of memory until they are needed and have a place to "Swap Out" memory segments that are no longer needed in memory. This technology is commonly used in paging
The main advantage of paging is that it allows the physical address space of a process to be noncontiguous. Prior to paging, systems had to fit whole programs into storage contiguously which caused various storage and fragmentation problems.
Paging is an important part of virtual memory implementation in most contemporary general-purpose operating systems, allowing them to use disk storage for data that does not fit into physical Random-access memory (RAM). Paging is usually implemented as architecture-specific code built into the kernel of the operating system.
Example: Assume a multiprogramming environment with Round-Robin CPU scheduling algorithm. When a quantum expires, the memory manager will start to swap out the process that just finished, and swap in another piece to the memory space that has been freed. In the meantime, CPU scheduler will allocate a time slice to some other process in memory. When each process finishes its quantum it will be swapped back with another process. Ideally, memory manager can swap process fast enough so that there is always at least one process in memory, ready to execute, when the CPU scheduler wants to reschedule the CPU. The quantum must also be sufficiently large that reasonable amounts of computing are done between swaps.
Swapping can be implemented in various ways. For example, swapping can be priority based. That means if a higher priority process arrives and wants service, the memory manager can swap out the lower priority process to the secondary memory so that it higher priority process can be loaded to main memory for execution. As soon higher priority process finishes, the lower priority process will be swapped back to main memory and execution will be continued. Sometimes swapping is also called roll out, roll in.
Swapping requires a backing store. And this backing store is as fast as disk. This backing store should be large enough to maintain copies of all memory images for all users. Swapping also means copying some data from one memory to another
regardless of either it is allocated to some process or it is free.
this data abstraction is important for several reasons:
Portability; it's not necessary to port every program for all hardware, only the device drivers need to be changed.
Security; the user is not relied on â or even allowed â to access the drive directly.
Convenience; files don't actually exist as separate entities on disk, but it sure makes it easier for people to use computers.
Contiguous allocation
With contiguous allocation, each file occupies contiguous blocks on the disk. The location of a file is defined by the disk address of the first block and its length.
A file allocated disk space using contiguous allocation method
Both sequential access and direct/Random access are supported by the contiguous allocation. We can say that it supports random access as using Disk Block Address we can jump directly on the required location.
The disadvantage of contiguous allocation is that it is often difficult to increase the size of a file as the next contiguous block may not be free. Moreover, one is often not sure of the space required while creating a new file. The various methods adopted to find space for a new file suffer from external fragmentation. Internal fragmentation may exist in the last disk block of a file.
Linked allocation
In linked allocation, each file is a linked list of disk blocks. The directory contains a pointer to the first and (optionally the last) block of the file. For example, a file of 5 blocks which starts at block 4, might continue at block 7, then block 16, block 10, and finally block 27. Each block contains a pointer to the next block and the last block contains a NIL pointer. The value -1 may be used for NIL to differentiate it from block 0.
Indexed allocation
Linked allocation does not support random access of files, since each block can only be found from the previous. Indexed allocation solves this problem by bringing all the pointers together into an index block. One disk block is just used to store DBAs (disk block addresses) of a file.
a file allocated disk space using Indexed allocation Method
Every file is associated with its own index node. If a file is very large then one disk block may not be sufficient to hold all associated DBAs of that file. If a file is very small then some disk block space is wasted as DBAs are less and a single disk block could still hold more DBAs.
Other kinds of crash (software bugs, unexpected loss of electric power, etc.) generally cause no physical damage to the disk. Such crashes often garble the sector(s) that were in the middle of a write at the time of the crash. Because many computer systems buffer writes in RAM and re-order the sequence of writes before the data is stored on non-volatile media, such crashes often lead to inconsistent data.
There are several ways of improving fault tolerance in filesystems:
RAID, which duplicates data.
Journaling, which helps avoid problems in case of a crash.
Dealing with bad blocks, which prevents use of corrupted disk sectors.
The main advantages is in reliability: depending on the RAID level, there is a certain amount of data redundancy, which allows there to be faults and errors without data being lost.
Because filesystem operations (read, write, delete, etc.) can not often be completed atomically, a halt in the middle of one can cause any number of problems. For example, consider a write operation that requires the filesystem to:
Update the file's inode
Write the new data to the disk
Now, consider what would happen if step 1 was completed but the system failed before step 2 could be. We would have an inode that describes a file as having a certain last modified time, size, etc. But the file itself would not reflect these changes! By recording all changes before they happen, journaling filesystems like ext4 can be more fault tolerant than others, like FAT.
information about a file's clusters and other data is stored with each cluster, not just a governing table (as FAT is)
Support for very large files (up to 2 to the 64th power or approximately 16 billion bytes in size)
An access control list (ACL) that lets a server administrator control who can access specific files
Integrated file compression
Support for names based on Unicode
Support for long file names as well as "8 by 3" names
Data security on both removable and fixed disks