Operating System Interview Questions and Answers

Here you will get list of 60+ commonly asked operating system interview questions and answers. These os questions are helpful for freshers as well as experienced.

1. What is operating system?

Operating system can be defined as an interface between user’s program and hardware.

2. What is main purpose of operating system?

The main purpose of OS is to manage hardware and software resources and provides common services for our programs. It provides a suitable platform to execute our program (jobs).

3. What are different types of operating system?

There are generally two types of operating system which are as follows:

  1. Batch Operating System.
  2. Multiprogramming Operating System

Now this Multiprogramming Operating System can be broadly classified as:

  •  Multitasking Operating System
  • Multiprocessing Operating System
  • Real Time Operating System

4. What are different components of operating system?

The main components of operating system are:

  1. Kernel
  2. Process Management
  3. File System
  4. Memory Management
  5. I/O Management

Thus operating system is not an individual component but it has may sub components as stated above which makes our job easier.

5. What are the goals of OS?

Basically there are two goals of Operating System, those are:

  1. Primary : Convenience
  2. Secondary : Efficiency

6. Explain the different types of Operating System?

  • Batch Operating System:

In this type of Operating System all the jobs are submitted to computer at once and are executed in the order of submission without any preemption (means no job can be taken out until they complete).

  • Multiprogramming Operating System

It’s an extension of Batch OS where several jobs would be in the main memory at once and would be executed in some order for some specified amount of time.

Now we will look into its sub types:

  • Multi-tasking Operating System:

In this type of Operating System more than one task are executed simultaneously on a single processor machine. In fact there is a switching of CPU among the processes (jobs) at a very sharp pace that it seems to done parallel to the end user.

  • Multiprocessing Operating System:

It is the ability of an operating system to execute more than one process simultaneously on a multi-processor machine. In this, a computer uses more than one CPU at a time.

  • Real Time Operating System:

In such operating System there is a specified time allotted for each job. It’s useful in critical application like military, satellite etc.

7. What is kernel?

Kernel is the core part of the Operating System responsible for managing the communication between the software (user level applications) and the hardware (CPU, disk memory etc.). The main tasks of the kernel are:

  • Process management
  • Device management
  • Memory management
  • Interrupt handling
  • I/O communication
  • File system etc.

8. What are different types of kernel?

We have three important types of kernel named:

  • Monolithic Kernel:

It can be seen as a whole kernel that is full-fledged kernel, with all the services running.

Example: UNIX

  • Micro Kernel:

It is kernel with a limited services that is with some important services running.

Example: QNX-real time OS

  • Hybrid Kernel:

It combines the aspect of both monolithic as well as micro kernel.

Example: Microsoft NT kernel

9. What is user space and kernel space?

These are two important region of a memory.

User space: It is a region of memory where normal user processes run (i.e. everything other than Kernel).

Kernel space: It is a region of memory where code of kernel resides and executes. It is considered to be privileged part of a memory invoked by system calls. It is also known as System space.

10. What is process?

A running program is called as a process or it’s an active instance of program that is under execution.

A process is an entity created by Operating system to execute the program.

In Linux, we can use “ps” command to see running process.

Example: Any .exe in windows OS is a process like skype.exe etc

11. What are different type of process?

There are two types of process that is i) user space process and ii) Kernel space process.

12. What is difference between a program and a process?

A program is a set of instructions that are to perform a designated task, whereas the process is an operation which accepts the given instructions and perform the task as per the code, called ‘execution of instructions’.

Thus a program is a passive entity residing at secondary memory and a process is an active entity residing in the main memory.

13. Explain the different states of a process?

A process can go through following states in its lifecycle:

  • New:

This is the first state when a process is created or just started. It resides in secondary memory.

  • Ready:

This state signifies that the process is ready to be assigned to the processor that is ready to execute.

  • Running:

This state signifies that process has been given to the processor and its instruction are getting executed.

  • Waiting:

This state signifies that a process is waiting for some kind of resource or an event be it a user input or waiting for any file to become available.

  • Terminated:

The process can be terminated normally or abnormally.

Normal termination means that process has done with its complete execution whereas abnormal means that process has been terminated without completing its task.

Note: Any process has to go minimum four states (new->ready->running->terminated).

14. Which is the first process to be created by OS?

Init process is the first process to be created by OS. It provides the environment for the other process to be created later.

15. How are process identified?

Any process can be identified by a term called its id that is process id (pid).

16. What is fork ()?

Fork is a system call which is responsible for creating a copy of a current process. The current process is termed as parent process and the created process is termed as child process.

On success it returns pid of the child process to parents process and Zero is returned to child process.

17. What is system call?

It’s like a way by which any user level program ask for the services offered by a kernel.

It acts as an interface between a process and the operating system.

18. What is program counter?

It a pointer which points to the next instruction to be executed by a compiler.

19. What are the different attributes of a process?

Some of the important attributes of a process are:

  • Process id (pid)
  • Parent process id (PPid)
  • Process state
  • Scheduling parameter
  • Program counter and different registers.

This is also referred as context of a process.

20. What is Process control Block (PCB)?

It is like a data structure which hold all information (attributes) of a process.

21. What are different section of a process?

There is four important section of a process as stated below:

  • Stack: contains local variables ,returns address
  • Heap: Dynamically allocated memory via malloc, calloc,realloc
  • Data: contains global and the static variables
  • Code or text: contains code, program counter and content of processor’s register.

Note:

  • Stack and the Heap section are extendible that is stack can grow down and heap can grow up.
  • It is in the same order as mentioned above.

22. What is context switching?

It is switching of a processor from one process/thread to another. It is also called Task switch or process switch.

23. What is inode?

Inode is a data structure which holds all the attributes of a file. It is also called index number.

Some of the attributes of file are:

  • File type
  • Permission
  • File size
  • Time when last it is modified

Note: Please while  reading thread concept, try to relate all this with process, thread will have its own, all those attributes as that of a process like its id(tid), scheduling parameter/policy etc. and  concept like context switching, different section etc. Thus try to relate all thread’s concept with that of a process.

24. What is thread?

Thread is a concurrent unit of execution within a process. A process can have multiple threads where each thread can perform a different task independently, thus increasing the efficiency of a process. A process always has one thread by default called main thread which is executed first.

Example:

  • Word processor, a background thread may check spelling and grammar while a foreground thread processes user input (keystrokes).
  • Web server – Multiple threads allow for multiple requests to be served simultaneously, without having to service requests sequentially.

25. State the benefits of a thread?

Some of the common advantages associated with threads are:

  • Responsiveness:

A process with thread are said to be more responsiveness than a process without thread because even if one thread is blocked or waiting for some resources the other thread still continue to function.

  • Lighter:

A thread is considered to be lighter than a process in terms of resource sharing and run time overhead. Most of the resource of a process are shared by all its thread making it lighter.

  • Throughput:

It improves the throughput of a multithreaded application, multiprocessor environment.

  • Economy:

Creating and managing thread is much faster (context switching is faster) than performing same task for processes.

26. State the disadvantages associated with thread?

  • Robustness:

It’s not as robust as process since if any one thread is terminated abnormally, it leads to entire process termination.

Thus many RTOS (Real Time Operating System) application uses processed over threads.

  • Increased Complexity

It is more complex than a process in terms of synchronization overhead.

27. What is difference between a process and a threads?

Process Thread
Process is used for heavyweight task Threads are used for small task(lightweight)
Processes are less responsive than threads Threads are more responsive than process
Processes are more robust than threads Threads are less robust
Each process will have its own address space. Threads are within a process thus share same address space(memory)
Processes have less synchronization overhead since all have separate address space(memory) Since they share same address space, synchronization is more overhead than process

28. What are different types of threads?

There are two types of threads:

  • User level thread : java thread
  • Kernel level thread: POSIX thread.

29. What is scheduler?

It is one of the component of kernel responsible for scheduling that is deciding when to run which process.

30. What are different types of scheduler?

There are three types of scheduler:

  • Long Term scheduler:

It is also called job scheduler responsible for selecting processes from queue (job pool/secondary memory) and loading them to main memory for execution.

  • Short term scheduler:

It is also called CPU scheduler responsible for selecting a process among processes that are ready to execute and allocate CPU to one of them.

This is nothing but a change of state of process from ready to running state. It is also called dispatcher.

  • Medium term scheduler:

It is also called swapper responsible for swapping a process from main memory to secondary memory in case if some high priority process needs to be given chance for execution.

It reduces the degree of multiprogramming (many processes in main memory).

31. What is preemptive and non-preemptive scheduling algorithm?

A scheduling algorithm is preemptive if, once a process has been given the CPU can take away. The strategy of allowing processes that are logically runnable to be temporarily suspended is called Preemptive Scheduling and allowing the process to run till completion is called non-preemptive scheduling.

32. What are different types of scheduling algorithm?

There are four different types of scheduler:

  • First come First serve(FCFS): First came process is served first
  • Round Robin(RR):Each process is given a quantum amount of time
  • Shortest job first(SJF):Process with lowest execution time is given first preference
  • Priority scheduling (ps): Priority value called (nice value) is used for selecting process. Its value is from 0 to 99. 0 being max and 99 being least.

33. What are different performance metric for scheduler?

There are five performance metric for scheduler, those are as follows:

  • CPU Utilization:

Percentage of time that the CPU is doing useful work (I.e. not being idle). 100% is perfect.

  • Wait time:

Average time a process spends for its turn to get executed.

  • Throughput:

Number of processes completed / time unit.

  • Response Time:

Average time elapsed from when process is submitted until useful output is obtained.

  • Turnaround Time:

Average time elapsed from when process is submitted to when it has completed.

34. What is daemon process?

A daemon process is one which runs at the background unlike the other foreground processes without the intervention of the user. It ends with “d”.

Example: crond is a daemon process in Linux operating system which is responsible for scheduling of an event like sending packets statistics at every 1 hours to server can be done with the help of crond daemon process.

35. What are different types of process in Linux?

There are three different types of process in Linux, those are:

  • Interactive-Foreground
  • Batch
  • Daemon-Background

36. What is deadlock?

A deadlock is a situation where two or more process or threads sharing the same resource are effectively preventing each other from accessing the resource. In simple terms the resource needed by one process/threads are being used by others and so on, thus none of the process can continue executing leading to deadlock.

37. What are the conditions required for deadlock to happen?

There are four conditions required for deadlock which are stated below

Mutual Exclusion: At least one resource is held in a non-sharable mode that is only one process at a time can use the resource. If another process requests that resource, the requesting process has to wait till it is released.

Hold and Wait: There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.

No Preemption: Resources cannot be preempted; that is, a resource can only be released after the process has completed its task.

Circular Wait: There must exist a set {p0, p1,…..pn} of waiting processes such that p0 is waiting for a resource which is held by p1, p1 is waiting for a resource which is held by p2,…, pn-1 is waiting for a resource which is held by pn and pn is waiting for a resource which is held by p0.

Note: All the four conditions mentioned above has to be satisfied for deadlock to happen.

38. What is race condition?

Race condition is an undesirable situation where two or more threads/process are trying to access and change the value of data shared by them and the outcome of the operation depends upon the order in which the execution happens.

Thus it lead to data inconsistency and loss of its value as both threads are racing to change/access the shared data.

Example:

Assume x =5;

Thread 1

x =x+1;

write x;

Thread 2

x=x+10;

write x;

Assume just before first write the first thread is suspended and control comes to second thread thus it increments the value of x by 10 and writes the value that is now x becomes 15.

In this case we can see that value of x depends upon the order in which the thread executes and the first value of x is lost that x=x+1=5+1=6. Thus there is clear inconsistency among the value of x because of race condition. Here x is the shared variable among both the threads upon which both are racing to access/update its value. To avoid such inconsistencies we need a proper synchronization mechanism like semaphore, mutex (discussed later)

39. What is Zombie process?

A zombie process also called defunct process is one which has completed its execution and is in terminated state but still has entry in the process table. It is denoted by “Z”. It shows that still the resources held by process are not freed upon termination.

It is dangerous because at one point of time system may run out of memory.

40. What is synchronization?

As the name suggest it means a proper co-ordination among processes while running in terms of resources. It means sharing system resources by a process in such a way that concurrent access to shared data is handled thereby minimising the chance of inconsistent data as we saw in Race condition.

41. What are different synchronization mechanism?

Some of the common synchronization mechanism are:

  • Semaphore
  • Mutex

42. What is semaphore?

Semaphore is one of the simplest synchronization mechanism used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system.

It’s a variable with a value range between 0 to N where N = maximum resources -1;

43. What are different types of semaphore?

There are two types of semaphore, those are:

  • Binary Semaphore:

Semaphore which can have only two values either 0 or 1. It is also called Boolean semaphore controlling/protecting just one resource.

  • Counting Semaphore:

Semaphore whose value can be in the range of 0 to n where n =max -1; where max is nothing but the maximum resource.

When number of resources a semaphore protects is greater than 1, it’s called counting semaphore.

44. How is synchronization achieved by semaphore or What are different operations performed on semaphore variables?

There are two operations which are performed on semaphore which helps in synchronization, those are:

  • Wait:

If the semaphore value is not negative, decrement the value by 1.

  • Signal:

Increments the value of semaphore by 1.

For example:

Say the value of semaphore variable is initialized by 1 and if one process tries to use the shared variable, it decrements the value by 1 and access it. In the meantime if other process attempts to access it, it finds the semaphore variable 0 thus has to wait till the first process completes its task and increments the value back to 1.

Thus form the above explanation we can see that there is a proper synchronization (controlling one process form another) avoiding any race condition.

45. What is mutex?

Mutex is a locking mechanism which allows only one process to access the resource at a time.

It stands for mutual exclusion and ensure that only one process can enter the critical section at a time.

46. What is critical section of code?

As the name suggest it is that section or part of code which has variables or other resources which is being shared by two process, and if allowed to access may lead to race condition. To avoid this we need a mutex which ensures only one process can enter the critical section of code at a time.

47. Differentiate between semaphore and mutex?

Below stated are some important difference held between mutex and semaphore

                         Semaphore                               Mutex
It is a synchronization mechanism It is a locking mechanism
A Semaphore controls access to a shared pool of resources. It provides operations to Wait () until one of the resources in the pool becomes available, and Signal () when it is given back to the pool. A Mutex controls access to a single shared resource.
The other process can also the release the lock held by others The process which has acquired the lock can only release the lock

48. What do you mean by virtual memory?

Virtual memory is a memory management scheme used by operating system which allows a system to compensate for the shortage of physical memory.

Virtual address space is increased using active memory in RAM and inactive memory in hard disk drives (HDDs) to form contiguous addresses that hold both the application and its data.

49. What do you mean by logical and physical address?

Logical Address:

It can be defined as an address generated by CPU, later these addresses are mapped to physical address with the help of mechanism called paging (discussed later).

Physical Address:

It is nothing but the actual address that belongs to main memory where our program resides for execution.

50. What is paging?

The mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware device and this mapping is known as paging technique.

It ensures that the physical address of space to be non-contiguous. In this the virtual memory is divided into fixed size pages and the physical memory is divided into equal size called page frames.

51. What is the size of each page?

The size of page is 4k.

52. What is demand paging?

It is quite similar to a paging system with swapping where pages are loaded into main memory only on demand ,till then the processes resides in secondary memory.

For any process to execute, its pages are loaded into main memory, thus the entire page is not brought into main memory rather the pages are loaded only on demand not in advance. This is referred as demand paging.

Example:

We have a process responsible for database function like insert, query, delete and thus it should be understood that this process is divided into pages say one page for each function and at certain point of time, it needs to perform query so there is no point in loading the entire process (pages) rather just the page related to query function.

53. What is page fault?

As the name suggest, we are looking for certain page in main memory and it is not found, its termed as page fault else page hit.

54. What is page replacement algorithm and name it?

As above we have seen that there might be situation of page fault, in that case we need to bring that page from secondary memory to main memory but if there is no room for new page in the main memory, some page from the main memory has to be replaced with new page form secondary memory. This is called page replacement and one of the common algorithms is Least Recently Used (LRU) that is replace the page that has been unused for longest time.

55. What is cache?

Cache memory is a high speed memory in the CPU that is used for faster access to data. It provides the processor with the most frequently requested data

56. What is TLB?

It is a hardware cache responsible for speeding up the translation of logical address to physical address that is mapping between logical and physical address.

It contains the page table entries which is most recently used, thus before looking into main memory for page, TLB is searched if not found main memory lookup is done for required page.

57. What is fragmentation and state its types?

As we saw above that there is frequent swapping of page in and out form memory, the free space in main memory is broken into small pieces. It happens after sometime the processes cannot be allocated to memory blocks considering their small size and memory blocks remains unused. This problem is called fragmentation.

There are two types of fragmentation:

  • Internal fragmentation:

Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be used by another process.

  • External fragmentation:

Total memory space is enough to satisfy a request or to reside a process in it, but they are  not contiguous, so it cannot be used.

58. What is IPC and state some of them?

IPC means inter process communication- process to process notification, process to process synchronization which allows a programmer to coordinate activities among different program processes that can run concurrently in an operating system

Some of the common IPC mechanism are:

  • Message Queue:

A queue of messages that is maintained between processes used for exchange for messages and other important information among processes.

  • Shared Memory:

In this memory (page) is shared among the processes in user space and one process can write into it and other can read.

  • Pipe:

A pipe is a technique for passing information from one program process to another. Basically, a pipe passes a parameter such as the output of one process to another process which accepts it as input.

Example:

ps –ef | grep “skype”

What it does that the output of “ps –ef” is given as an input to “grep” command with the help of pipe and “ps” is used in Linux to get the running process on system and “grep” is used for search.

  • Signal:

Signals come under IPC mechanisms that are used for notification – notification can be process to process – notification can be system to process.

Kill is the command by which one process can send a signal to other.

Syntax: kill <signal_name> <process_id>

Example:

1)  Kill SIGINT 1234

2) Kill SIGQUIT 1234

Each signal has its own number.

 Signal Name Signal Number Description
SIGINT 2 Issued if the user sends an interrupt signal (Ctrl + C)
SIGQUIT 3 Issued if the user sends a quit signal (Ctrl + D

59. State the purpose of a signal?

Signals serves two important purposes:

  • To make a process aware that a specific event has occurred
  • To force a process to execute a signal handler (customized/user) function included in user’s code.

60. What is interrupt?

An interrupt is a signal to the processor which can be generated by hardware or a software indicating an event that needs immediate attention. An interrupt indicates the processor to a high-priority condition requiring the interruption of the current task

61. What is starvation and aging?

Starvation:

Starvation is a resource management problem where a process is denied of resource or service for a long time or has been repeatedly denied services.

Aging:

This is a solution to starvation which involves gradually increasing the priority of processes that wait in the system for a long time.

The aging factor must increase the requests priority as time passes and must ensure that a request will eventually be the highest priority request (after it has waited long enough) and gets the chance to execute.

Note: It’s not same as deadlock.

Comment below if you have any queries related to above operating system interview questions and answers.

2 thoughts on “Operating System Interview Questions and Answers”

Leave a Comment

Your email address will not be published. Required fields are marked *