Sunday, 5 April 2020

Operating System - Linux

Operating System - Linux

Operating System - Linux

 
Linux is one of popular version of UNIX operating System. It is open source as its source code is freely available. It is free to use. Linux was designed considering UNIX compatibility. Its functionality list is quite similar to that of UNIX.

Components of Linux System

Linux Operating System has primarily three components
·        Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It consists of various modules and it interacts directly with the underlying hardware. Kernel provides the required abstraction to hide low level hardware details to system or application programs.
·        System Library − System libraries are special functions or programs using which application programs or system utilities accesses Kernel's features. These libraries implement most of the functionalities of the operating system and do not requires kernel module's code access rights.
·        System Utility − System Utility programs are responsible to do specialized, individual level tasks.
Kernel Mode vs User Mode
Kernel component code executes in a special privileged mode called kernel mode with full access to all resources of the computer. This code represents a single process, executes in single address space and do not require any context switch and hence is very efficient and fast. Kernel runs each processes and provides system services to processes, provides protected access to hardware to processes.
Support code which is not required to run in kernel mode is in System Library. User programs and other system programs works in User Mode which has no access to system hardware and kernel code. User programs/ utilities use System libraries to access Kernel functions to get system's low level tasks.

Basic Features

Following are some of the important features of Linux Operating System.
·        Portable − Portability means software can works on different types of hardware in same way. Linux kernel and application programs supports their installation on any kind of hardware platform.
·        Open Source − Linux source code is freely available and it is community based development project. Multiple teams work in collaboration to enhance the capability of Linux operating system and it is continuously evolving.
·        Multi-User − Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.
·        Multiprogramming − Linux is a multiprogramming system means multiple applications can run at same time.
·        Hierarchical File System − Linux provides a standard file structure in which system files/ user files are arranged.
·        Shell − Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs. etc.
·        Security − Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.

Architecture

The following illustration shows the architecture of a Linux system −

The architecture of a Linux System consists of the following layers −
·        Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).
·        Kernel − It is the core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.
·        Shell − An interface to kernel, hiding complexity of kernel's functions from users. The shell takes commands from the user and executes kernel's functions.
·        Utilities − Utility programs that provide the user most of the functionalities of an operating systems.

Operating System - Security

Operating System - Security

Operating System - Security

 
Security refers to providing a protection system to computer system resources such as CPU, memory, disk, software programs and most importantly data/information stored in the computer system. If a computer program is run by an unauthorized user, then he/she may cause severe damage to computer or data stored in it. So a computer system must be protected against unauthorized access, malicious access to system memory, viruses, worms etc. We're going to discuss following topics in this chapter.
  • Authentication
  • One Time passwords
  • Program Threats
  • System Threats
  • Computer Security Classifications
Authentication
Authentication refers to identifying each user of the system and associating the executing programs with those users. It is the responsibility of the Operating System to create a protection system which ensures that a user who is running a particular program is authentic. Operating Systems generally identifies/authenticates users using following three ways −
·        Username / Password − User need to enter a registered username and password with Operating system to login into the system.
·        User card/key − User need to punch card in card slot, or enter key generated by key generator in option provided by operating system to login into the system.
·        User attribute - fingerprint/ eye retina pattern/ signature − User need to pass his/her attribute via designated input device used by operating system to login into the system.
One Time passwords
One-time passwords provide additional security along with normal authentication. In One-Time Password system, a unique password is required every time user tries to login into the system. Once a one-time password is used, then it cannot be used again. One-time password are implemented in various ways.
·        Random numbers − Users are provided cards having numbers printed along with corresponding alphabets. System asks for numbers corresponding to few alphabets randomly chosen.
·        Secret key − User are provided a hardware device which can create a secret id mapped with user id. System asks for such secret id which is to be generated every time prior to login.
·        Network password − Some commercial applications send one-time passwords to user on registered mobile/ email which is required to be entered prior to login.
Program Threats
Operating system's processes and kernel do the designated task as instructed. If a user program made these process do malicious tasks, then it is known as Program Threats. One of the common example of program threat is a program installed in a computer which can store and send user credentials via network to some hacker. Following is the list of some well-known program threats.
·        Trojan Horse − Such program traps user login credentials and stores them to send to malicious user who can later on login to computer and can access system resources.
·        Trap Door − If a program which is designed to work as required, have a security hole in its code and perform illegal action without knowledge of user then it is called to have a trap door.
·        Logic Bomb − Logic bomb is a situation when a program misbehaves only when certain conditions met otherwise it works as a genuine program. It is harder to detect.
·        Virus − Virus as name suggest can replicate themselves on computer system. They are highly dangerous and can modify/delete user files, crash systems. A virus is generatlly a small code embedded in a program. As user accesses the program, the virus starts getting embedded in other files/ programs and can make system unusable for user
System Threats
System threats refers to misuse of system services and network connections to put user in trouble. System threats can be used to launch program threats on a complete network called as program attack. System threats creates such an environment that operating system resources/ user files are misused. Following is the list of some well-known system threats.
·        Worm − Worm is a process which can choked down a system performance by using system resources to extreme levels. A Worm process generates its multiple copies where each copy uses system resources, prevents all other processes to get required resources. Worms processes can even shut down an entire network.
·        Port Scanning − Port scanning is a mechanism or means by which a hacker can detects system vulnerabilities to make an attack on the system.
·        Denial of Service − Denial of service attacks normally prevents user to make legitimate use of the system. For example, a user may not be able to use internet if denial of service attacks browser's content settings.
Computer Security Classifications
As per the U.S. Department of Defense Trusted Computer System's Evaluation Criteria there are four security classifications in computer systems: A, B, C, and D. This is widely used specifications to determine and model the security of systems and of security solutions. Following is the brief description of each classification.
S.N.
Classification Type & Description
1
Type A
Highest Level. Uses formal design specifications and verification techniques. Grants a high degree of assurance of process security.
2
Type B
Provides mandatory protection system. Have all the properties of a class C2 system. Attaches a sensitivity label to each object. It is of three types.
·        B1 − Maintains the security label of each object in the system. Label is used for making decisions to access control.
·        B2 − Extends the sensitivity labels to each system resource, such as storage objects, supports covert channels and auditing of events.
·        B3 − Allows creating lists or user groups for access-control to grant access or revoke access to a given named object.
3
Type C
Provides protection and user accountability using audit capabilities. It is of two types.
·        C1 − Incorporates controls so that users can protect their private information and keep other users from accidentally reading / deleting their data. UNIX versions are mostly Cl class.
·        C2 − Adds an individual-level access control to the capabilities of a Cl level system.
4
Type D
Lowest level. Minimum protection. MS-DOS, Window 3.1 fall in this category.

Operating System - File System

Operating System - File System
Operating System - File System


  • File

A file is a named collection of related information that is recorded on secondary storage such as magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits, bytes, lines or records whose meaning is defined by the files creator and user.

  • File Structure

A File Structure should be according to a required format that the operating system can understand.
·        A file has a certain defined structure according to its type.
·        A text file is a sequence of characters organized into lines.
·        A source file is a sequence of procedures and functions.
·        An object file is a sequence of bytes organized into blocks that are understandable by the machine.
·        When operating system defines different file structures, it also contains the code to support these file structure. Unix, MS-DOS support minimum number of file structure.

File Type

File type refers to the ability of the operating system to distinguish different types of file such as text files source files and binary files etc. Many operating systems support many types of files. Operating system like MS-DOS and UNIX have the following types of files −

Ordinary files

  • These are the files that contain user information.
  • These may have text, databases or executable program.
  • The user can apply various operations on such files like add, modify, delete or even remove the entire file.

Directory files

  • These files contain list of file names and other information related to these files.

Special files

  • These files are also known as device files.
  • These files represent physical device like disks, terminals, printers, networks, tape drive etc.
These files are of two types −
·        Character special files − data is handled character by character as in case of terminals or printers.
·        Block special files − data is handled in blocks as in the case of disks and tapes.

File Access Mechanisms

File access mechanism refers to the manner in which the records of a file may be accessed. There are several ways to access files −
  • Sequential access
  • Direct/Random access
  • Indexed sequential access

Sequential access

A sequential access is that in which the records are accessed in some sequence, i.e., the information in the file is processed in order, one record after the other. This access method is the most primitive one. Example: Compilers usually access files in this fashion.

Direct/Random access

·        Random access file organization provides, accessing the records directly.
·        Each record has its own address on the file with by the help of which it can be directly accessed for reading or writing.
·        The records need not be in any sequence within the file and they need not be in adjacent locations on the storage medium.

Indexed sequential access

  • This mechanism is built up on base of sequential access.
  • An index is created for each file which contains pointers to various blocks.
  • Index is searched sequentially and its pointer is used to access the file directly.

Space Allocation

Files are allocated disk spaces by operating system. Operating systems deploy following three main ways to allocate disk space to files.
  • Contiguous Allocation
  • Linked Allocation
  • Indexed Allocation

Contiguous Allocation

  • Each file occupies a contiguous address space on disk.
  • Assigned disk address is in linear order.
  • Easy to implement.
  • External fragmentation is a major issue with this type of allocation technique.

Linked Allocation

  • Each file carries a list of links to disk blocks.
  • Directory contains link / pointer to first block of a file.
  • No external fragmentation
  • Effectively used in sequential access file.
  • Inefficient in case of direct access file.

Indexed Allocation

  • Provides solutions to problems of contiguous and linked allocation.
  • A index block is created having all pointers to files.
  • Each file has its own index block which stores the addresses of disk space occupied by the file.
  • Directory contains the addresses of index blocks of files.


Operating System - I/O Softwares

Operating System - I/O Softwares

Operating System - I/O Softwares
I/O software is often organized in the following layers −
·        User Level Libraries − This provides simple interface to the user program to perform input and output. For example, stdio is a library provided by C and C++ programming languages.
·        Kernel Level Modules − This provides device driver to interact with the device controller and device independent I/O modules used by the device drivers.
·        Hardware − This layer includes actual hardware and hardware controller which interact with the device drivers and makes hardware alive.
A key concept in the design of I/O software is that it should be device independent where it should be possible to write programs that can access any I/O device without having to specify the device in advance. For example, a program that reads a file as input should be able to read a file on a floppy disk, on a hard disk, or on a CD-ROM, without having to modify the program for each different device.

Device Drivers
Device drivers are software modules that can be plugged into an OS to handle a particular device. Operating System takes help from device drivers to handle all I/O devices. Device drivers encapsulate device-dependent code and implement a standard interface in such a way that code contains device-specific register reads/writes. Device driver, is generally written by the device's manufacturer and delivered along with the device on a CD-ROM.
A device driver performs the following jobs −
  • To accept request from the device independent software above to it.
  • Interact with the device controller to take and give I/O and perform required error handling
  • Making sure that the request is executed successfully
How a device driver handles a request is as follows: Suppose a request comes to read a block N. If the driver is idle at the time a request arrives, it starts carrying out the request immediately. Otherwise, if the driver is already busy with some other request, it places the new request in the queue of pending requests.
Interrupt handlers
An interrupt handler, also known as an interrupt service routine or ISR, is a piece of software or more specifically a callback function in an operating system or more specifically in a device driver, whose execution is triggered by the reception of an interrupt.
When the interrupt happens, the interrupt procedure does whatever it has to in order to handle the interrupt, updates data structures and wakes up process that was waiting for an interrupt to happen.
The interrupt mechanism accepts an address ─ a number that selects a specific interrupt handling routine/function from a small set. In most architectures, this address is an offset stored in a table called the interrupt vector table. This vector contains the memory addresses of specialized interrupt handlers.
Device-Independent I/O Software
The basic function of the device-independent software is to perform the I/O functions that are common to all devices and to provide a uniform interface to the user-level software. Though it is difficult to write completely device independent software but we can write some modules which are common among all the devices. Following is a list of functions of device-independent I/O Software −
  • Uniform interfacing for device drivers
  • Device naming - Mnemonic names mapped to Major and Minor device numbers
  • Device protection
  • Providing a device-independent block size
  • Buffering because data coming off a device cannot be stored in final destination.
  • Storage allocation on block devices
  • Allocation and releasing dedicated devices
  • Error Reporting
User-Space I/O Software
These are the libraries which provide richer and simplified interface to access the functionality of the kernel or ultimately interactive with the device drivers. Most of the user-level I/O software consists of library procedures with some exception like spooling system which is a way of dealing with dedicated I/O devices in a multiprogramming system.
I/O Libraries (e.g., stdio) are in user-space to provide an interface to the OS resident device-independent I/O SW. For example putchar(), getchar(), printf() and scanf() are example of user level I/O library stdio available in C programming.
Kernel I/O Subsystem
Kernel I/O Subsystem is responsible to provide many services related to I/O. Following are some of the services provided.
·        Scheduling − Kernel schedules a set of I/O requests to determine a good order in which to execute them. When an application issues a blocking I/O system call, the request is placed on the queue for that device. The Kernel I/O scheduler rearranges the order of the queue to improve the overall system efficiency and the average response time experienced by the applications.
·        Buffering − Kernel I/O Subsystem maintains a memory area known as buffer that stores data while they are transferred between two devices or between a device with an application operation. Buffering is done to cope with a speed mismatch between the producer and consumer of a data stream or to adapt between devices that have different data transfer sizes.
·        Caching − Kernel maintains cache memory which is region of fast memory that holds copies of data. Access to the cached copy is more efficient than access to the original.
·        Spooling and Device Reservation − A spool is a buffer that holds output for a device, such as a printer, that cannot accept interleaved data streams. The spooling system copies the queued spool files to the printer one at a time. In some operating systems, spooling is managed by a system daemon process. In other operating systems, it is handled by an in kernel thread.
·        Error Handling − An operating system that uses protected memory can guard against many kinds of hardware and application errors.