Operating_System_Interview_Short_Notes-1
Operating_System_Interview_Short_Notes-1
Short Notes
Operating systems are the foundation of modern digital devices. These systems
determine how you see and interact with your machines. Operating systems
determine how we program an application, what software we can use, and how
hardware should be designed. Understanding operating systems is essential for
developers to ensure you’re designing programs that work to the strengths of a
particular operating system.
Today, we’ll break down the basics of operating system components and
functions, starting with the most basic kernel and ending with the more advanced
topic of virtualization. By the end of this article, you’ll have a solid foundation of
operating systems and be ready to jump into intermediate practice.
What is a kernel?
Resource Management
What is a process?
What is a service?
Common Services
Program Execution
Communication
Error Detection
Resource Allocation
Protection
Advanced OS concepts
Process Scheduling
Priority-based Scheduling
Virtualization
However, Linux has a steep learning curve and can be difficult to pick up.
macOS
Kernels rarely change from version to version. In fact, the modern OS uses the
same versions from over 20 years ago with only minor updates or
modernizations.
Resource management
Resource management is one of the most important services of a kernel. The
kernel delegates computer resources like memory and CPU to each process
being executed. By regulating processes, the kernel prevents greedy programs
from starving the system and slowing down other concurrent programs. This
service ensures that all processes have enough resources to function and that
each process makes use of all available resources.
What is a process?
A process is the basic unit of work in an executing program. The developer
doesn’t write processes. Instead, they write programs that become processes
when executed by the machine.
What is a service?
The kernel is our platform to run programs while services provide tools to the
program to do its job. A service is a built-in set of functions that programs can
use to implement common behaviors, like saving to files or sharing data. Without
services, developers would have to write the code for these behaviors in each
program that needs them.
Computer scientists working on OS systems quickly realized that many programs
would benefit from these behaviors and included them in the OS package. This
makes programming for an OS more convenient, as the developer can avoid
writing the most frequently needed behaviors from scratch each time.
Common services
The services included in an operating system vary based from OS to OS, but
some have become standard:
Program execution: This service allows the computer to load, execute, and
produce the output of a program.
Error Detection: Error detection allows computers to scan all processes for
errors by monitoring progress and expected outcomes. This service can also
correct minor errors without user interference.
Resource Allocation: This kernel service allows the computer to grant and
free up resources dynamically as processes are added or completed. It also
allows the computer to create process sequences using CPU schedulers.
Additional types of OS were invented to meet these needs. Each type has unique
strengths and processing algorithms to optimize the system for certain tasks.
Companies need developers to make programs tailored to the adopted type of
OS. It’s essential for you to know how each type of OS works and the unique
challenges each poses to a developer.
Below, we’ll explore the 6 types of OS, what tasks they’re used for, and how you
can optimize your programs for each.
Disadvantages:
When designing programs for a batch system, minimize processing time as any
long process will slow down the work pipeline. However, your program can be
very resource-intensive as the device only runs one process at a time.
Advantages:
Disadvantages:
Difficult to debug
Expensive to set up
Disadvantages:
Prone to errors
When designing programs for distributed operating systems, split the program
into smaller modular tasks to ensure the system can efficiently use its divide and
conquer structure.
Common examples of distributed operating systems can be found in large scale,
response-focused systems like email servers, cell phone networks, and electronic
banking systems.
Advantages:
Durable, the failure of one node will not interrupt other nodes
Disadvantages:
Expensive to set up
This operating system gives each program a given period, with any program that
would exceed that processing time being rejected. This maintains a strict
schedule of processes to ensure certain high importance tasks can always be
performed at a moment’s notice.
Real-time systems differ from time-sharing systems in how many processes can
be completed at once. Real-time operating systems complete only one process at
a time within a certain period. The process is interrupted if the processing time
exceeds its dedicated period. Time-sharing systems, on the other hand, switch
focus between multiple processes and are allowed to take multiple quantums to
complete.
These systems are widely used when responsiveness and strict schedules are
essential, such as in equipment for scientific experiments, air traffic control
systems, or defense systems.
When writing programs for a real-time system, you must know how long each
period is in your system and ensure your program is small enough to complete
Few errors
Disadvantages:
Advanced OS concepts
Process scheduling
The CPU scheduler component in the resource allocation service can use one of 6
algorithms to decide on which process completes first. Each of these algorithms
is either preemptive or non-preemptive.
Preemptive schedulers use a priority system to influence processing. High-priority
processes are scheduled as soon as they reach the ready stage, even if another
process is currently running. If this happens, the high-priority process overrules
the lower priority process.
Below are the 3 common preemptive scheduling algorithms:
First in, first out FIFO The processor completes processes in the order they
came in. This is the simplest algorithm to implement but also results in the
slowest average processing time.
Shortest job next SJN The processor always queues the next shortest job.
This algorithm produces a very low processing time but cannot be
implemented unless both the duration of CPU availability and the processing
time of each process are known. SJN is the non-preemptive equivalent of the
shortest remaining time and is also used in batch OS systems.
Processes Threads
S.No.
Processes carry more unique information Multiple threads within a process share
2.
than threads resources
Virtualization
Virtualization is the technique of making virtual objects that behave as hardware,
such as the switching ability of time-sharing operating systems. The time-sharing
OS can complete multiple processes simultaneously by switching between them
rapidly.
Normally, a computer would need two individual CPUs to complete processes
concurrently. As a result, a time-sharing OS achieves virtualization by using rapid
process switching to emulate an additional CPU.
Virtualization can simulate entire OS instances with individually assigned sections
of the host resources, data, and devices for each container. These containers are
isolated from the host machine and all other hosted virtual machines (VMs). This
larger scale of virtualization is called operating-system-virtualization or, more
commonly, containerization.
Programs run on these containers as though they are a true operating system.
They access resources allocated to the container and execute processes using a
containerized scheduler.
Virtualization, therefore, grants the ability to run multiple concurrent programs
in separate containers while all being hosted on the same physical machine.
Isolated failure, the host system will continue to function even if one or more
of the hosted VMs crash
Disadvantages:
VMs are less efficient than equivalent physical machines as VMs must
indirectly request hardware use through the host OS
Resources are divided among different VMs meaning most machines can only
efficiently run a few at a time
Reference:
Educative.io
If you don’t know Educative is another online learning platform that is gaining a
lot of traction for its text-based, interactive learning courses. Reading is
generally faster than watching and If you prefer reading text than watching
videos then this is the platform to checkout.
If you are preparing/appearing for interviews, then I would highly recommend
Grokking the Coding Interview: Patterns for Coding Questions.