Operating Systems 2015
Operating Systems Sem VI Third Year B.Tech. Computer Engineering
- 1 Instructor
- 2 Virtual Box Resources
- 3 Common Linux Commands
- 4 System Calls
- 5 Shell and Kernel
- 6 CPU Scheduler
- 7 File Systems
- 8 Synchronisation
- 9 Memory Management
Prof. Abhijit A.M is the instructor for this course.
Virtual Box Resources
- Virtual Box Tricks
- Virtual Machine Troubleshooting
- Installing VirtualBox and Creating Virtual Machine
- Windows 10(TechPreview) Setup using VirtualBox
- Android Setup using Virtual Box
- Chrome OS Setup using Virtual Box
- BackBox OS Setup using Virtual Box
- Solaris 11.1 installation using VirtualBox
- Fedora 16 installation using VirtualBox
- MAC OS X Snow Leopard installation using VirtualBox
- Windows 7 installation using VirtualBox
- Slackware installation using VirtualBox
- OpenSUSE installation using virtualbox
- Kali-Linux installation using virtualbox
- Facts about VDI,VHD and VMDK formats of Hard Disk
- Virtual Box Guest Additions
- Dual boot system in Virtual Box
- Ubuntu 14.10 Setup Using VirtualBox
- Tiny core Setup Using VirtualBox
- Damn Small Linux 4.11.r1 installation using VirtualBox
- Open solaris Setup using Virtualbox
- BSD Setup Using VirtualBox
Common Linux Commands
Shell and Kernel
What Kernel Is?
- Kernel is heart of Linux Os.
- It manages resources of Linux OS.
- Resources means facilities available in Linux. For e.g. Facility to store data, print data on printer, memory, file management etc .
- Kernel decides who will use this resource, for how long and when.
- It runs your programs (or set up to execute binary files).The kernel acts as an intermediary between the computer hardware and various programs/application/shell.
- It's Memory resident portion of Linux. It performs following tasks :-
- I/O management
- Process management
- Device management
- File management
- Memory management
What is Linux Shell?
Computer understand the language of 0's and 1's called binary language.In early days of computing, instruction are provided using binary language, which is difficult for all of us, to read and write. So in OS, there is special program called Shell. Shell accepts your instruction or commands in English (mostly) and if its a valid command, it is passed to kernel.Shell is a user program or it's a environment provided for user interaction. Shell is an command language interpreter that executes commands read from the standard input device (keyboard) or from a file.Shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
What is Shell Script?
Normally shells are interactive. It means shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.Shell script defined as:"Shell Script is series of command written in plain text file. Shell script is just like batch file is MS-DOSbut have more power than the MS-DOS batch file."
Variables in Shell
To process our data/information, data must be kept in computers RAM. RAM is divided into small locations, and each location had unique number called memory location/address,which is used to hold our data. Programmer can give a unique name to this memory location/address called memory variable or variable (Its a named storage location that may take different values, but only one at a time).
In Linux (Shell), there are two types of variable:
- System variables - Created and maintained by Linux itself. This type of variable defined in CAPITAL LETTERS.
- User defined variables (UDV) - Created and maintained by user. This type of variable defined in lower letter
- Whenever the CPU becomes idle, it is the job of the CPU Scheduler to select another process from the ready queue to run next.
- The storage structure for the ready queue and the algorithm used to select the next process are not necessarily a FIFO queue.
- CPU scheduling decisions take place under one of four conditions:
1. When a process switches from the running state to the waiting state, such as for an I/O request or invocation of the wait( ) system call.
2. When a process switches from the running state to the ready state, for example in response to an interrupt.
3. When a process switches from the waiting state to the ready state, say at completion of I/O or a return from wait( ).
4. When a process terminates.
- For conditions 1 and 4 there is no choice A new process must be selected.*For conditions 2 and 3 there is a choice To either continue running the current process, or select a different one.*If scheduling takes place only under conditions 1 and 4, the system is said to be nonpreemptive, or cooperative. Under these conditions, once a process starts running it keeps running, until it either voluntarily blocks or until it finishes. Otherwise the system is said to be preemptive.
- Note that preemptive scheduling can cause problems when two processes share data, because one process may get interrupted in the middle of updating shared data structures.
- Preemption can also be a problem if the kernel is busy implementing a system call ( e.g. updating critical kernel data structures ) when the preemption occurs.
- There are several different criteria to consider when trying to select the "best" scheduling algorithm for a particular situation and environment, including:
- CPU utilization : Ideally the CPU would be busy 100% of the time, so as to waste 0 CPU cycles. On a real system CPU usage should range from 40% ( lightly loaded ) to 90% ( heavily loaded ).
- Throughput : Number of processes completed per unit time. May range from 10 / second to 1 / hour depending on the specific processes.
- Turn around time : Time required for a particular process to complete, from submission time to completion.
- Waiting time : How much time processes spend in the ready queue waiting their turn to get on the CPU.( Load average The average number of processes sitting in the ready queue waiting their turn to get into the CPU. Reported in 1 minute, 5 minute, and 15 minute averages by "uptime" and "who". )
- Response time: The time taken in an interactive program from the issuance of a command to the commence of a response to that command.
One of the major tasks involved in scheduling is picking the right scheduling algorithm. There are many ways one could decide to schedule tasks. But there are many factors to be considered while making such a decision.
This is a simple description of the UNIX system, which is also applicable to Linux systems -
"On a UNIX system, everything is a file; if something is not a file, it is a process."
Types of Files
There are various types of files in Linux:
- Regular files: Text files, executable files, input or output to or from a program and so on.
- Directories: Files that are lists of other files.
- Special Files: The mechanism used for input and output. Most special files are in /dev, we will discuss them later.
- Links: A system to make a file or directory visible in multiple parts of the system's file tree. We will talk about links in detail.
- (Domain) Sockets: A special file type, similar to TCP/IP sockets, providing inter-process networking protected by the file system's access control.
- Named Pipes: Act more or less like sockets and form a way for processes to communicate with each other, without using network socket semantics.
Types of File Systems
A file system (or filesystem) is a means to organize data expected to be retained after a program terminates by providing procedures to store, retrieve and update data, as well as manage the available space on the device(s) which contain it. A file system organizes data in an efficient manner and is tuned to the specific characteristics of the device.
There are a variety of file systems that can be used between multiple operating systems based on what a user wants. Some types of file systems are:
- Ext2 - Second Extended File System. Used by Linux
- Ext3 - Third Extended File System. Used by Linux
- Ext4 - Fourth Extended File System. Used by Linux
- NTFS - Used by Windows.
Creating a Filesystem
Filesystems are created by using the mkfs command.There is actually a seperate program for each filesystem type.mkfs is just a front end that runs the appropriate program depending on the desired file system type. The type is selected with the -t fstype option.
The programs called by mkfs have slightly different command line interfaces. some of them are enlisted below (refer manpages for more):
- -t fstype
Select type of filesystem
Search for bad block and initializa the bad block list accordingly
- -l filename
Read the initial bad block list from the name file
Mutex is shortform for mutual exclusion. This is the simplest solution for critical-section problem. Mutex lock is used to protect critical sections and race condition. Mutex lock suggests that a process should acquire the lock before entering a critical section and release the lock while leaving critical section.
Semaphore is another solution for race condition. A semaphore S is an integer variable that, is accessed through two standard atomic operations: wait() and signal(). For binary semaphore S can be either 0 or 1. When one process is modifying the semaphore value, no other process can simultaneously modify that same semaphore value.
Classic Synchronisation Problems
In Operating system Memory Management is the function responsible for management and handling of computers primary memory.This function keeps the track of each and every memory location whether allocated or free. It checks how memory is allocated to the processes and also decides that which process should get memory at which time. It also tracks whether any memory is unallocated or freed and update the status of the memory corrospondingly.
Memory Management uses two registers (base and limit registers). Base register holds smallest legal physical memory address and limit register specifies the size of the range.Consider the following diagram to get this:
The mapping of symbolic names is done in following ways:
If it is known at compile time where a program will rwside in physical memory, then absolute code can be generated by the compiler, containing actual physical addresses. However if the load address changes at some later time, then the program will have to be recompiled.
If the location at which a program will be loaded is not known at compile time, then the compiler must generate relocatable code, which refers addresses relative to the start of the program. If that starting address changes, then the program must be reloaded but not recompiled.
If a program can be moved around in memory during the course of execution, then binding must be delayed untill execution time. This requires special hardware, and is the method implemented by most of the modern operating systems.
In dynamic loading, a routine of program is not loaded until it is called by program. All routines are kept on disk in relocatable format. The main program is loaded into memory and is executed. Other routines methods or modules are loaded on request. Dynamic Loading makes better memory space utilization and unused routines are never get loaded.
The term linking deals with the process of collecting and combining various modules of code and data into a executable file that can be loaded into memory and executed. Operating system can link system level libraries to a program. When it combines the libraries at load time, the linking is called static linking and when this linking is done at the time of execution, it is called as dynamic linking.
In static linking, libraries linked at compile time, so program code size becomes bigger whereas in dynamic linking libraries linked at execution time so program code size remains smaller.
Paging is a memory management technique in which the memory is divided into fixed size pages. Paging is used for getting a faster access to data. When a program needs a page, it is available in the main memory as the OS copies a certain number of pages from the storage device to main memory. Paging allows the physical address space of a process to be non-contiguous.
OS performs an operation for storing and retrieving data from secondary storage devices for use in main memory. Paging is one of such techniques for memory management. Paging is to deal with external fragmentation problem.
When a program (or task) references a logical address in memory, the processor translates the address into a linear address and then uses its paging mechanism to translate the linear address into a corresponding physical address.
If the page containing the linear address is not currently in physical memory, the processor generates a page fault exception. The exception handler for the page fault exception typically directs the operating system to load the page from disk storage into physical memory. When the page has been loaded in physical memory, a return from the exception handler causes the instruction that generated the exception to be restarted. The information that the processor used to map linear address into physical address space and to generate page fault exceptions (when necessary) is contained in page directories and page tables stored in memory.
Operating system copies a disk page into physical memory only if page fault occurs(page is not in mem ory).
Steps are as follows-
Attempt to access page
If page is valid then continue processing if its invalid a page fault occurs.
If memory reference is valid then page in the required page else terminate the process.
Schedule the disk operation to read the page into main memory.
Restart the instruction.
Sometimes also called "swap prefetch", preloads a process' non-resident pages that are likely to be referenced in near future. It attempts to reduce the number of page fault.