Operating System Part-1

bandejibandeji
6 min read

Why we need OS?

  • For better Resource management of cpu,gpu,memory,etc.

  • Maintain sync between I/O devices and the system itself to use applications by users simultaneously.

  • It also make sure use of DRY principle(Don't Repeat Yourself) by removing redundant code for each application which is required by the to run on the system.

  • To maintain isolation and security among the applications.

What is an OS?

An OS is piece of software that acts as an interface between the user applications and the system hardware , for efficient use of resources .It acts as a underlying resource manager to execute the application by hiding the hidden complexity.

What are the Goals of an OS?

  • Maximum CPU utilization .

  • High Priority Task execution.

  • No Process Starvation.

What are the types of OS?

  • Single Processing OS (e.g. MS-DOS)

  • Batch Processing OS (e.g. ATLAS)

  • Multiprogramming Processing OS (Important) (Context Switching) (e.g. THE)

  • Multitasking Processing OS (Important)(Use of time quantum makes it different from other so alternate processes are executed) (e.g. CTSS)

  • Multiprocessing OS (Important)(Use of multiple CPU makes different form other unlike all other above processes run on single CPU) (e.g. WINDOWS)

  • Distributed OS (e.g. SOLARIS)

  • Real Time OS (used at ATC , nuclear plants,etc)

What is Process and Thread?

Program under execution is called a process .

Single sequence stream within a process is called thread, its lightweight and has an independent path of execution in a process .(e.g. multiple tabs open in a browser, while writing over a text editor and formatting text, spell check ,etc all other stuff are handled by different threads.)

Explain Multitasking V/s Multithreading .

MultitaskingMultithreading
The execution of more than one task simultaneously is called multitasking.A process is divided in multiple subtasks called threads, having its own path of execution , is called multithreading
More than 1 processes run at a same time.More than 1 threads run at a same time.
Isolation and Memory Protection as different programs are allocated separate memory on RAM.No Isolation and Memory Protection as same memory is allocated to all the threads of the process so they share the memory.
Processes are scheduled.Threads are scheduled.
No. of CPU =1No. of CPU >=1

Explain Thread Context Switching V/s Process Context Switching.

Thread CSProcess CS
OS saves current state of thread and switches to another thread and restores its state.OS saves current state of process and switches to another process and restores its state.
Doesn't include switching of memory address space.Includes switching of memory address space.
Fast switching as no memory address space is switched.Slow switching as memory address space is switched.
Cache is preserved as same process threads may need the info.Cache is flushed due to isolation and security.

What are the Components of OS ?

  • Userspace (CLI , GUI)

  • Kernel

  • Hardware

What are the functions of the Kernel ?

  1. Process Management

    • Process creation, termination.

    • Process communication and synchronization.

    • Process scheduling and thread scheduling.

  2. Memory Management

    • Allocate/Deallocate memory.

    • Free space management.

  3. File Management

    • Creating/Deleting file, making directory ,etc.
  4. I/O Management

    • Managing all I/O devices together.

    • Spooling (the overlapping of output of one job with input of other jobs). (e.g. printing 10 pages to printer)

    • Buffering (storing data temporarily while it is being transferred).(e.g. youtube video buffering)

    • Caching (storing parts of data in faster storage for performance).

What are the types of Kernel ?

The userspace and kernel together make a OS. The user is switched between the user mode and the kernel mode using software interrupt.(e.g. a new folder is created on the GUI the command is taken to kernels file management component to create a directory and return the user with the folder. So there is a switching of user mode and kernel mode here.)

  1. Monolithic Kernel

    • All the kernel components are binded inside a single kernel .

    • Advantages are fast communication between different components as they are present together.

    • Disadvantages are kernel becomes bulky and less reliable.

    • e.g. Linux , unix , ms-dos , etc.

  2. Micro Kernel

    • The user space is binded with I/O management system and File management system while the kernel space is binded with memory management system and process management system.

    • Advantage is more reliable and stable .

    • Disadvantage is performance is reduced as overhead of user space and kernel space occurs.

    • e.g. L4 Linux , Symboian OS, etc

  3. Hybrid Kernel

    • The user space is binded with File management system while the kernel space is binded with memory management system , I/O management system and process management system.

    • e.g. MacOs , Windows , etc.

  4. Nano/Exo Kernel.

How communication is being done between user mode and kernel mode ?

Communication is established using IPC - Inter Process Communication ,this mainly occurs in two ways either using shared memory or message passing.

What is System Call?

  • Apps interacts with the Kernel using system call.

  • It is the only way to enter a process into the kernel mode from a user mode.

  • A system call is a mechanism through which a user program can interact with the kernel and other I/O devices.

What are the types of System Calls?

  1. Process Control (e.g. execute ,abort)

  2. File Management (e.g. create file, delete file)

  3. Device Management (e.g. request or release device)

  4. Information Maintenance (e.g. get time or date)

  5. Communication Management (e.g. send and receive messages)

How OS boots up or PC starts?

  1. First we give power supply to the system.

  2. CPU initializes a firmware program called BIOS or UEFI

  3. BIOS runs and makes sure presence of all hardware and initializes a boot loader which is the present as a first program stored on the storage.

  4. Bios handles the further process to start the kernel to the bootloader of the OS.

  5. The bootloader is the light program that runs the kernel and starts the OS.

32 bit V/s 64 bit processor ?

32 bit processor64 bit processor
A 32 bits OS has 32 bits register.A 64 bits OS has 64 bits register.
4 bytes of data is processed in one instruction cycle so adding a extra RAM won't make any difference.8 bytes of data is processed in one instruction cycle hence adding a extra RAM would increase the CPU performance.
There are 2^32 addressable memory address space.There are 2^64 addressable memory address space.

What are the types of Storage ?

  1. As we move up cost increases, storage capacity decreases and speed or performance increases.

  2. Primary memory is volatile and secondary memory is non-volatile.

0
Subscribe to my newsletter

Read articles from bandeji directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

bandeji
bandeji