OS Concepts
What is an Operating System?
- It is a program that acts as an intermediary b/w user of a computer and computer hardware.
- It is a program that controls the execution of the application program.
- It acts as an interface b/w application & h/w.
- With the presence of the OS, users can easily access the H/W
Main objectives of an OS:
- Convenience
- Ability to evolve
- Efficiency
OS Services:
- It can provide Program development
- Program execution
- It helps the Access I/O devices
- Access to File system access
- Error detection & quick response
The computer has hardware components. To activate the H/W components we need OS. OS is nothing but S/W.
Role of OS:
A computer is a set of resources for the movement, storage & processing of data. The OS is responsible for managing resources.
Computer System Components:
- Hardware(CPU, Memory, I/O)
- Operating System
- Application Programs
- Users(People, machines, other computers)
Basic functionality of OS:
- Process Management: The process is something that is created by an OS it is not executing the program. Before executing a program the process has been created. If two or more processor wants to access the CPU at the same time, then to which process CPU would be allocated for how long that would be taken care of by OS. Many processors are running in the computer system at the same time with the help of OS.
Executable Code includes the current activity represented by the value of the Program Counter.
Data contains variables.
Heap Section Dynamically allocated memory to process during its run time.
Stack contains temporary data, such as function parameters, returns addresses, and local variables.
The attribute of Process:
Process Id: For every process, a unique identifier is assigned by the Operating System.
Program Counter: It contains what is the next instruction that has to be executed without any repetition.
Process State: new, ready, waiting, executing, blocked, suspended, terminated, etc.
General Purpose Registers: They must be saved and restored when a process is swapped in and out of the CPU.
I/O status Information: Device allocated to the process for open files etc.
CPU Scheduling Information: Different processes may have different priorities, Based on the priority CPU scheduled process.
Process:
Every process has a unique process control block (PCB). All the PCBs should be present in the linked list.
Process States:
New: Newly created process
Ready: After creation, the process moves to the ready state(ready to run)
Running: Currently running process in CPU (only one process at a time can be under execution in a single processor).
Wait / Block: When a process requests I/O access.
Complete / Terminated: The process completed its execution.
Suspended Ready: When the ready queue becomes full, some processes are moved to the suspended ready state.
Suspended Block: When the waiting queue becomes full.
Various types of schedulers:
1. Long term scheduler
2. Short term scheduler
3. Medium-term scheduler
Long-term scheduler: From the new state process will be picked and put into the Ready state. So this change is done with the help of a long-term scheduler.
Short-term scheduler: Which process should be picked from the ready state would be decided by the short-term scheduler and it will call the dispatcher and the dispatcher will pick the process from the ready state and put the process into the running state.
Medium-term scheduler: from ready to suspend ready and waiting to suspend wait this process will be done with the help of a medium-term scheduler.
When a process is running and executing on the CPU that time is known as CPU time and when the process is doing some I/O operation that time is known as I/O time.
If the process is running more and more time in the CPU then that process is known as CPU Bound. If the process is performing more and more time during the I/O operation that is known as I/O Bound process.
2. Memory Management(RAM — main memory): To run the process that process must be run in main memory. without allocating space into the main memory no process can execute. The size of the main memory is very limited so which process would be there in main memory and for how long it takes place, is also decided by OS. You can’t put all the processes into the main memory.
Three important criteria in memory management
- Size
- Access time
- Per unit cost
Memory management is an essential function of an Operating System that manages primary memory(RAM).
Memory hierarchy in computers:
* Cache Memory: A small size of memory that is incredibly fast, expensive, and volatile.
* Random Access Memory: A medium-sized memory of a few gigabytes, medium-priced, medium-fast, and volatile.
* HDD or SSD: A large-sized memory of up to a terabyte of storage, cheap, slow, and non-volatile.
Memory manager: OS has a memory manager. It keeps track of the status of each memory location, whether it is allocated or free.
3. I/O device management (keyboard, mouse, printer …): For example, Many computers are attached to one printer. The OS has to manage which user is going to access this printer and at what time. It’s not easy to access every user can access the printer at the same time. So this is the responsibility of OS.
4. Storage Management (Disk — secondary memory): How the data is to be stored permanently in the hard disk and how the data will exist from the hard disk that is also done by OS(with the help of file system — ex) — OS is also used to manage the hard disk
5. Security & Protection: OS takes care that knows an authorized user can access the file. OS saves your password and then when any user enters the password and the password would be matched with a saved password if that is correct then only you can access the file.
- Two processors can not access the CPU at the same time. This is possible by using a multi-core processor or parallel processor.
- No other process will interfere with another process that is taken care of by OS.