Operating Systems

Operating system and its functions: It is a software. It provides the interface to user to use the hardware. The user can be people or process itself. Microsoft, Linux distribution such as Ubuntu, CentOS, Mobile OS, Distributed OS, Real-Time OS are few examples of OS. OS manages File, Memory, Process, Device Management, Security and Access control, Networking and communication.

Types of operating systems: General purpose OS such as Windows OS, Ubuntu. There is network OS such as microtik router OS. We have real-time OS for time-critical systems. Next is Embedded OS used in embedded system like IoT devices, Mobile OS.

Basic components of the Operating Systems: Shell and Kernel makes up the OS. Shell provides the user interface for users to use OS features. Kernel is a core program of an OS. There are two types of kernel monolithic and microkernel. Monolithic kernel contains all the essential process in main memory such as IPC, device drivers, scheduling. Microkernel just has few services active in main memory. Other features of OS are executed in user space. Thus, memory space taken by monolithic is high in comparision to microkernel.  User call service call to access kernel services. Operating system resides in Main Memory in RAM as kernel if device is ON.

Process and Threads: An active program is called process. Active means the program is located in main memory.  Thread is a light-weight version of process. There can be a number of threads of a process. Each thread can be executed parallelly or using context switching. One example to understand can be MS-Word application. Spelling checking, capitalize first word, grammar checking all these can be done once. Thus, if one part is not executed other part of the program which is standalone can be executed. There can be user-defined thread and kernel-defined thread.

Process Management: Process management by OS does having a data structure called process control block (PCB). PCB has PID, states, registers, memory, stack, PC, List of open files, Code, Data fields.

Thread has also its own thread control block. It has its own stack, thread id, PC, data but it shares code, data and file resources with other process. Once process is killed all of its thread dies.

If one thread is block other thread can be executed. Thus, threading is a best option.

Generally, Process has can in one of the five states:

New: Process is created.

Ready: Process is waiting for CPU scheduling.

Running: Process is executed in CPU.

Blocking: Process is waiting for some I/O operations.

Terminating: Process is terminated after its job finished.

 

After blocking operation completed, it goes to ready state waiting for CPU time.

There is also just two states in process management we have seen in text book. They are queuing and running. It may be blocked for I/O operation and send it to queue state.

Process is selected based on scheduling algorithm: first come first serve, priority based, round robin, shortest job first, multilevel …. For calculation, we must know two different definitions .. a Awaiting time b. Turn Around time. Awaiting time is time awaiting for CPU. It is time started to execute – entry time. Then turn around time is process job finish time – process entry time. CPU burst time is time taken by CPU.

Waiting time = TAT - Burst time

First-Come First Serve

Three process p1, p2, p3 are coming at time 0 each having CPU burst time of 24,3,3.  Then awaiting time for p1 is = 0, p2=24 and p3=27. Average awaiting time is = (0+24+27) / 3 =17. Then turn around time for p1= 24, p2=27 and p3=30 . Average turn around time is= (24+27+30)/3. Then we have other question:

Process

Arriving time

Burst time

P1

0

5

P2

2

7

P3

1

6

P4

3

9

Here, waiting time p1= 0, p2 = (11-2) = 9, p3= 5-1=4 , p4=15, Average waiting time is = (0+9+4+15)/4. Turn around time:p1=5,p2=18-2,p3=11-1,p4=27-3

Shortest job first (pre-emptive version)

For above question:

Process

Arriving time

Burst time

P1

0

5

P2

2

1

P3

1

3

P4

3

9

 

Waiting time (TAT-burst time): p1: =9-5=4,   p2=1-1=0,   p3=4-3=1,   p4=15-9=6

Turn around time: p1=9, p2=1, p3=4, p4=18-3=15

 

Round robin

Process

Arriving time

Burst time

P1

0

5

P2

2

1

P3

1

3

P4

3

9

 

Quantum time = 2 TAT P1=9-0=9   ;; p2= 5-2=3 ;; p3= 10-1 =9:: p4= 17-3=14

WT= TAT-burst time P1= 9-5=4:: p2=3-1=2:: p3= 9-3=6:: p4=14-9=5

 

Memory Management techniques

Operating system manages main memory. Indirectly, it manages hard disk also in swapping and in virtual memory concept. But the major concentration is managing memory which is RAM. Due to multiprogramming, user want more and more process in main memory.

Memory management works using memory management unit (MMU). Memory management are done in following works… partition of memory, mapping of logical to physical address, swapping, virtual memory concept such as demand paging and segmentation.

In partition, there are fixed and variable partition. If program size is less than available fixed space then unused memory of that partition can’t be used by other program. Therefore, fixed partition suffers from internal fragmentation. Variable partition suffers from external fragmentation. Coalescing and Compaction are the ways to solve external fragmentation. However, extra overhead works are done. Coalescing joins continuous free memory. Less overhead work is done than in Compaction. Compaction merges discontinuous free space to create a large free space. More work are needed to do in compaction.

Logical to physical address: CPU generates logical address. MMU generates physical address combining base address and offset address. Late binding, compile time binding and execution time binding of program takes place.

Virtual memory: OS can have capability of extending main memory using demand paging and segmentation technique. In demand paging, a page table is created to store basic information for frame number with page number. Page size is equal to frame size. There are equal number of frame number for that process according to page number.

In segmentation, there is segmentation of program such as code, data, variables etc. Segmentation table has base address and limit. CPU segment number and offset value.

File System Management

Operating system manages File system. OS keeps record in data structure. Data structure can have value such as file name, size, pointer, location, file type, creation date, permission etc. File system can be different for different OS. Some are FAT, NTFS, ext. Directories contains folder and files. Some OS have single level directory, two level directory, user specific directory. They keep record in block. I have heard that iscan, index, inode like that,….CLOOK, SCAN… terms are seen….. Some has index number or .. linked list block number having a data structure… some are continuous,

It is necessary to learn some algorithm managed by OS for serving I/O request. Algorithms such as LOOK, SCAN, FCFS. SCAN algorithm it serves like elevator (go up and reverse and serves in reverse order) (end to end). But in Look algorithm it can reverse from middle. There are two ends and head pointer. Look algorithm is more efficient.

Deadlock:

In process scheduling, or resource management, sometimes OS can’t move forward on deciding for scheduling, reserving resource. This stage is called deadlock. OS intends that it never enter into deadlock situation. Four conditions are required to arise deadlock situation: every process are mutually exclusive, no preemption, hold and wait by each process, circular of reserving and waiting the resources. Deadlock prevention, deadlock ignorance, deadlock handling, deadlock avoidance are four different ways to handle deadlock. Deadlock ignorance is simple. It just ignores anything. Ostrich algorithm is an example for this. Deadlock avoidance is banker’s algorithm. Similarly, how loan is provided by banker they first look customer’s capability to reimburse payment periodically. It is first calculated before providing the resources. Deadlock handling is killing some of the process. Deadlock prevention does not allow process to be eligible in all above four steps to occur deadlock (Any one condition is not fulfilled).

There is a term of safe/unsafe in deadlock avoidance.

Security:

OS provides security in different aspects: network, user, permission, ACL and kernel access. Let me discuss on user authentication: MFA, 2level password, biometrics. Network by firewall, port. Access control DAC, MAC which user or process can access which resource. ACL by in linux like EWR(execute-write-read) permission is 777.

Distributed systems: User feel like one standalone system but behind there may be multiple applications, calls of service, SOA. Distributed system is a concept where software application realizes and take/provide service among different physical nodes or different application that may in heterogeneous or homogeneous environment. One example is Netflix; we view videos of movies from Netflix site. However, payment is linked with other parties that is managed by third party cash settlement. Thus, video management is one thing which is totally owned by Netflix whereas payment is done through other parties which provides solution to like Netflix. But, for user it is simply one site where user doesn’t take care about it behind what is happening. Internet is the backbone is most of the cases where message passing is done or where nodes are in different locations.

Distributed message passing: Even distributed system may tightly or loosely coupled, the communication between users/users, process/process or application/application can be done through sending messages. Distributed systems work in asynchronous mode which means sender and receiver do not require to operate on same time. Sometimes, just sharing memory (shared memory) concept also works for distributed system. RPC (Remote procedure call): A node can call remote node as if it is local procedure. Network connection is mandatory.  Clusters: A group of nodes sharing the resources. It is called clusters. A node can be either heterogeneous or homogeneous. Resources such as CPU, RAM, Storage, can be shared among the processes. Clusters help on scalability, availability and fault tolerance. Redundancy is achieved in clusters.

 

Second version note of Operating System: 

 

Operating System

5.1. Function of Operating System, Processes and Threads

Memory management as resource management is the main function of OS. Process management, scheduling, virtual memory, file management, security, networking are other functions of OS.

A program which is active and is in execution is called process. OS maintains a process control block (PCB) for process management containing fields such as process ID, state, PC, list of files, stack pointer, and registers. Thread is a light-weight version of a process. A process can have one or multiple threads. Threads can be created by user process or by kernel. Thread has its own stack, register context but shares code, list of files and data.

Kernel is essential program of OS which always resides in main memory. Actually, main memory is logically divided in two parts as: user space and kernel space. Monolithic kernel contains all components in main memory such as scheduling, IPC, device driver. Space requirement is more than microkernel. If essential components such as scheduling, IPC just are in kernel space, while device driver and other services execute from user space. This method of kernel is microkernel.

5.2. CPU scheduling, IPC and Deadlock

Scheduling can be understood simply as providing processor time for executing a process. There are long term scheduling, short term scheduling and medium term scheduling. Long term scheduling admits jobs into main memory and place it in queue. Short term scheduling is actually a CPU scheduler which obtain processor. Medium term scheduler swaps to control the degree of multiprogramming.  

OS supports IPC through communication among coordination or independent process through shared memory or message passing. RPC is one way of IPC.

Deadlock is a state where resources can’t be served to process. Deadlock occur if four conditions occur: mutually exclusive, non-preemptive process, cyclic wait, hold and wait.  Deadlock handling, Deadlock prevention, Deadlock avoidance, Deadlock Ignorance.

5.3. Memory Management

Memory management by OS by virtual manager and partition of memory itself.

Virtual memory can be achieved by demand paging or segmentation. Page table maps page number of a process to the corresponding frame number in main memory. This supports demand paging. On the other hand, segmentation loads segment (code, data, stack segments) on main memory with segment number and offset of segment in segment table.

On partition there is fixed partition and variable partition. Fixed partition divides main memory in equal block size. This can create internal fragmentation. Similarly, variable partition creates non-fixed block size in main memory. Thus, external fragmentation may occur. Coalescing and compaction are two steps used to solve this problem. If contiguous memory are empty they can be combined. This is coalescing. However if main memory blocks are empty but not contiguous then compaction is done to make larger space where new process can accommodate.

 

Some definition of terminology: Where should focus on process or CPU

Multiprocessor: There can be more than one CPU on one chip or multiple chips. Thus, it supports to execute more than one program same time.

Multiprocessing: It supports multiple processes to execute simultaneously if both multiple cores exists and OS supports.

Multiprogramming: Main memory can accommodate many programs at a same time. The execution can be uni-processing or multiprocessing.

Multithreading: Multiple threads of a process can execute simultaneously if there are many cores or if just one core is present thread can share in time basis.

Multitasking: It can happen even in single core. It is actually about can CPU save context and switch to other process.  

 

Scheduling

Time Around Time: Admit of job to finish of job

Burst time: Actual time CPU take to execute.

Waiting time: TAT-BT