20 Operating System Interview Questions & Answers for Freshers & Experienced - Placement Interview

What is an operating system? What does it do?
What are the most popular operating systems at present?
What are the main functions of an operating system?
What is a kernel? What are the different types of Kernels?
What is the difference between Monolithic and Micro Kernel? etc.

1.  What is an operating system? What does it do?

The Operating System (OS) acts as an interface between the user and the computer hardware components. It is system software that provides an environment in which a user can execute programs easily. Every computer system needs an operating system to be able to run programs and interact with the user. Without OS, it would be just one dumb hardware machine. The main functions of Operating System are memory management, file management, I/O management, processor management, device management, security, networking etc.

2. What are the most popular operating systems at present?

Operating System has evolved from slow and expensive systems to fast, powerful and affordable in the modern world. The most popular operating systems at present are as follows:

i) Android: The Android operating system is the world's most used mobile operating system with over 41% of the global market share. Android Operating System is developed by Google for smart phones and tablets. It is free and open-source software.

ii) Windows: Windows is the second most used operating system which accounts for 32% of the global market share. Windows is a proprietary operating system that is owned by Microsoft. Windows currently dominates the Personal Computers (PCs) market which includes desktops and laptops.

iii) iOS: iOS is the operating system of one of the most popular smart phone known as the iPhone. It is a proprietary mobile operating system that is developed and owned by Apple. It accounts for over 16% of the global market share.

3. What are the main functions of an operating system?

The main functions of an operating system are as follows:

i) It provides the interface for the user to interact with the computer components where the user would give commands to the operating system and the operating system would in turn instructs the hardware components to execute the command and perform a specific task.

ii) It organizes and coordinates the processing times of the various processes and programs running simultaneously for smooth execution.

iii) It deals with memory management which allocates and de-allocates memory space to programs in need of memory.

iv) It supervises scheduling of tasks and jobs to different resources.

v) It also deals with various file activities such as organization of files, storage and retrieval of files, naming, sharing and protection of files.

vi) It also maintains security of the system and access rights of the user.

4. What is a kernel? What are the different types of Kernels?

A kernel is a program that is at the core of the operating system. It is the most important part of an operating system and can be thought as a program that controls all the other programs in the system. It facilitates the interaction between the hardware and software components and basically manages operations of memory and CPU time. It is responsible for low level tasks such as disk management, memory management, process management. A kernel is one of the first programs that is loaded when starting up a computer and remains in the system memory until the computer is shutdown.

i) Monolithic kernel such as Unix, Linux etc.
ii) Micro kernel such as L4, Minix, K42 etc.
iii) Hybrid kernel such as Windows NT, Netware etc.
iv) Exo kernel such as Nemesis etc.
v) Nano kernel such as EROS etc.

5. What is the difference between Monolithic and Micro Kernel?

A Monolithic kernel is a kernel where the user services and the kernel services share the same memory space. As a result, the execution of the process is faster in Monolithic Kernels. As there is no separate memory space for user and kernel, the size of the Kernel is increased and that increases the size of the Operating System. But monolithic kernel has its own share of disadvantages. When any of the service fails, it leads to an entire system failure. And when a new service is added, the entire OS needs to be modified. The Linux kernel is an example of monolithic kernel.

In a Microkernel, the user services are kept in user address space, and kernel services are kept under kernel address space. As a result, it reduces the size of kernel and thus, Microkernel is smaller in size. Since the user service shared a different memory space with the kernel, this can cause the operation of the kernel to be slower as compared to monolithic kernels. It is easily extendible, it doesnt require any modification in kernel space if  new service is added to user address space. Microkernels are very uncommon. Minix, Symbian etc. are the examples microkernel.

6. What are device drivers?

A device driver is a piece of software that allows the kernel of the operating system to communicate with different hardware in the system. It facilitates the operation of the kernel. The kernel does not have to know the working details of the hardware but can simply call the device driver of that particular hardware when needed its operations.

7. What is paging?

Paging is a memory management scheme in which data is stored to and retrieved from the secondary storage for use in the main memory. The part of the secondary storage use for paging is known as virtual memory.

In paging, a process is divided into fixed-size contiguous block known as pages and is stored on the secondary storage. A page is the smallest unit of data for memory management use in virtual memory. And the main memory is also divided into fixed-size contiguous blocks known as frames. Pages from the secondary storage are map into frames in the main memory and frames must be kept of same size as the pages in order to have maximum utilization of memory. This process of transferring of pages between main memory and virtual memory is referred to as paging in Windows OS or swapping in Linux.

8. What is a process in operating system?

In operating system, a process is a program in execution. For example, when we write our program in C, we save, compile and run it, the moment we run it, it is transferred to the main memory and becomes a process. When a process executes, it passes through many different stages like Start, Ready, Running, Waiting and Terminated state.

9. What are the various attributes associated with a process?

OS maintains a Process Control Block or PCB. PCB is nothing but a data structure that stores information about a process. There are various attributes stored in PCB, they are as follows:

i) Process ID: It is a unique identifier assigned by the operating system.

ii) Process State: This represents the current state of the process such as ready, running etc.

iii) Priority: Each process has its priority and the one with the higher priority gets the CPU first.

iv) Program counter: Program counter stores the address of the last instruction of the process when the process was suspended. This will help the CPU to know the exact address when resuming the process.

v) CPU registers: Each process has its own set of CPU registers which are used to hold the data during the execution of a process.

vi) List of open files: During execution, there are some files that are needed by the process that needs to be present in the main memory. OS maintains those open files.

vii) List of open devices: OS also maintains list of all the devices that are opened during the execution of a process.

10. What is a thread?

A thread is the smallest unit of execution within a process. A process can have multiple threads. A thread is also called as a lightweight process. It breaks up a task into smaller units that can be executed concurrently and thus provides concurrency within a process. It exists within a process and uses process resources such as code, data, and files. Since, a thread is lightweight as compared to a process and helps to improve the execution performance by running in parallel with other threads. And just like a process, each thread have its own attributes such as thread ID, program counter, register set and a stack. Threads enhance the throughput of the system because when a process is split into threads, the function of each thread is considered as one job and then the number of jobs done in the unit time increases. In a multiprocessor architecture, threads can be distributed over a series of processors and can run in parallel on different processors.

11. What is a deadlock?

Deadlock is a situation where two processes are waiting for each other to complete in order to start their operation. This happens when first process is holding a resource and waiting for another resource that is currently being held by the second process and the second process is is waiting for the resource being held by the first process. This will cause them to wait forever and be in a state of deadlock.

12. What are the necessary conditions that can lead to a deadlock situation in a system?

There are four different conditions that result in Deadlock and they are as follows:

i) Mutual Exclusion: A resource cannot be shared between two processes. Only one process can use a particular resource at a time.
ii) Hold and Wait: A process is holding at least one resource and waiting for other resources.
iii) No Preemption: A resource cannot be taken from a process unless the process releases the resource.
iv) Circular wait: A group of processes are waiting for each other to release the resource and no one is releasing their own resource.

13. What is a Banker's algorithm?

Banker's algorithm is a deadlock avoidance algorithm. It manages resources allocation. It is also called as deadlock detection algorithm.

It is named as Banker's algorithm because the banks use the same technique to allocate money and provide loans to their customers so that they never run out of money.

Banker's algorithm checks the following three things before allocation of resources:

i) How many maximum resources can be requested by each process.
ii) How many resources each process currently holds.
iii) How many resources are currently available or not allocated to any process in the system.

It then makes a "S-State" or Safe State check to test for all possible deadlock conditions before deciding whether allocation of resources should be allowed.

14. What is a virtual memory?

Virtual memory is a storage allocation scheme where the secondary storage such as a hard drive can be use as a main memory by the system. This gives the illusion of having a big main memory. It allows users to run large application with less real RAM. This process of using virtual memory is done automatically by the OS. When a new application is to be loaded on the RAM and there is no sufficient space, the system searches for applications on the RAM that are in dormant stage or aren't being used and copies the same on to the hard disk. In this way, the system free up space on the RAM and allows new application to be loaded on RAM.

15. What is demand paging?

Demand paging is a paging technique used in virtual memory system where the pages that are stored in the secondary storage are retrieved only when demanded by the CPU. It is also known as lazy swapper.

16. What is thrashing?

Thrashing is a state where the CPU spends most of its time swapping pages between the main memory and virtual memory, rather than doing productive work such as executing the instructions. By evaluating the level of CPU utilization, a system can detect thrashing and it occurs when the number of pages exceeds the number of frames in the memory, which leads the CPU to address too many page faults and be in a constant state of paging.

17.  What is page fault?

Page fault occurs when the page referenced by the CPU is not found in the main memory and has to be fetched from the secondary storage. Page fault notify the operating system it must retrieved the pages from the virtual memory in order to continue the execution.

18. What is the difference between segmentation and paging?

Segmentation works in a similar manner as paging. It is a memory management technique that divides the main memory into segments of variable size.

The size of a page is fixed.The size of a segment is not fixed.
Procedures and data cannot be separated in pagingProcedures and data can be separated in segmentation.
It is faster It is slower as compared to paging.
The size of the page is determined by the CPU and available memory.The size of the segment is determined by the user.

19. What are the different states of a process?

A process goes through various states during execution and they are as follows:

New: This is the state when a program is picked up by the operating system into the main memory.

Ready: In the ready state, the process is waiting for the processor to be assigned for it to run.

Running: A process is said to be in a running state when it is being executed by the CPU.

Wait: If a process waits for a certain resource or waits for the input from the user it is said to be in a wait state and in the mean time the CPU picks up another process.

Terminate: When a process finishes its execution, it is said to be in a termination stage. In the this state, the process is removed from main memory

20. What is a scheduling algorithm? Name the different types of scheduling algorithms. What is FCFS?

A scheduling algorithm is an algorithm which intends to improve efficiency by reducing the waiting time to a minimum while allocating resources to various competing tasks.

There are various types of scheduling algorithms:

i) FCFS First Come First Serve.
ii) Priority Scheduling.
iii) Round Robin Scheduling.
iv) Multilevel Queue Scheduling.
v) Shortest Remaining Time.
vi) Shortest Job First.

FCFS or First Come First Serve is a type of scheduling algorithm that executes processes in the order that they arrive meaning the process that request the CPU first are allocated first. It is the easiest and simplest scheduling algorithm. However, this algorithm is poor in performance and the general wait time is high.