Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Top 50 OS interview questions and answers

Last Updated on April 8, 2022 by Ria Pathak

![](https://prepbytes-misc-images.s3.ap-south-1.amazonaws.com/assets/1645528391966-B_449-OS.png)
  1. Explain the main purpose of the Operating system?
    Ans. OS is used for communication between the computer systems and their peripherals and also provides an environment for the development and execution of programs. It also provides a means by which a user can give instructions to the computer system.
  2. What are the differences between UNIX and Linux Operating systems?
    Ans. The major differences are –
    • Linux is a UNIX clone, the Kernel of which is created by Linus Torvalds.
    • Open-Source Operating System
    • Free of Cost
    • Compatibility and Flexibility
  3. Describe what is Bash.
    Ans. BASH stands for Bourne Again Shell. BASH is the UNIX shell for the GNU operating system. So, BASH is the command language interpreter that helps you to enter your input, and thus you can retrieve information. In a straightforward language, we can say that it is a program that will understand the data entered by the user and execute the command, and gives output.
  4. Describe stack in the memory management of an OS.
    Ans. The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block (also called stack frame) is reserved on the top of the stack for local variables and some bookkeeping data. When that function returns, the block becomes unused and can be used the next time a function is called. The stack is always reserved in a LIFO order; the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack; freeing a block from the stack is nothing more than adjusting one pointer.
  5. What is virtual memory?
    Ans. The virtual memory technique virtualizes the main storage available to a process or task, as a contiguous address space that is unique to each running process or virtualizes the main storage available to all processes or tasks on the system as a contiguous global address space.
  6. What is a lock?
    Ans. A lock is an object which allows the manipulation or prevents manipulation of an object by one thread. Only that thread that has the key can unlock it and use or change it.
  7. Describe a Mutex and its application.****
    Ans. Mutex is basically a lock but it is used between multiple processes which also provides synchronization services. It also provides mutual exclusion and someway prevents deadlocks.
  8. What do you know about Semaphore?
    Ans. Semaphores are basically the mechanisms that tell a process that a current process is done and the next can enter for execution. Mostly used with the critical section of the code to synchronize resource access and avoid deadlocks. It can be considered as a generalized mutex.
  9. What is a process?
    Ans. The process is a program in execution. It has its own set of basic resources like the stack, text section, heap, data, etc. A process is known by its characteristics like Process ID, process state, I/O information, CPU scheduling information. Each such process has also a different memory space, address memory, etc.
  10. What are threads?
    Ans. Threads are basically called lightweight processes. It is a path of execution with a process. Many threads can be contained in one process sharing some of the resources in common. Threads shared code section, data, OS resources, etc with each other in a process but have their own stack, PC, register, etc.
  11. What are the different types of threads present?
    Ans. There are two types of threads present –
    • user-level thread: This is implemented by a user but is dependent on threads.
    • Kernel level thread: Kernel threads are implemented by OS and are independent in nature.
  12. What is kernel?
    Ans. It is the very core of an Operating System. It connects applications to the processing data and manages communication between the software and hardware components.
  13. If a Kernel Level Thread is blocked will that stop all other processes?
    Ans. No, Kernel level threads are implemented by OS, and hence if one gets blocked OS can schedule the operation to different other processors in a multiprocessor system, and hence all other processes can be performed easily.
  14. What are the advantages of multithreaded programming?
    Ans. There are various advantages ranging for improvement in responsiveness, resource sharing in process, economy of the system.
  15. Describe the 7 states of a process.
    Ans. The following 7 states are –
    • New: Process is about to be created but yet not created.
    • Ready: Process after creation in between new and ready is picked up by the OS to the main memory and is getting ready for dispatch for execution.
    • Run: Process is running after being selected by the CPU.
    • Waiting: The process might require I/O and hence needs to wait for the completion of that I/O operation. This waiting does not require CPU but remains in the main memory.
    • Exit: When the process is complete or terminated
    • Suspended ready: When a process is swapped out of the ready state from the main memory to go into the secondary memory by the scheduler is known as suspended ready state.
    • Suspended blocked: Similar to suspended ready, but swaps the process which was using I/O operation and lack of memory cause this swapping.
  16. Describe a PCB block.
    Ans. PCB- Process Control Block consists of characteristics of a process. Each process has a PCB which stores the following –
    • Process ID
    • Process State
    • I/O operations
    • Scheduling information
    • Registers
    • Program Counter
    • Memory Limits
    • Accounts and data status
  17. What are sockets?
    Ans. A socket is basically an end point in of a communication link between two process. These processes can be on the same machine or different and this is a part of IPC (Inter Process Communication) existing on the network layer.
  18. What do you mean by Context Switching?
    Ans. Context Switching refers to the process of saving the context/PCB information of a process and loading another process from the ready state into the main memory. This may occur due to the following reasons –
    • Any interrupt occurs
    • User and Kernel model switch
    • Pre-emptive Scheduling
  19. What are the different types of Schedulers?
    Ans. There are 3 main kind of schedulers –
    • Long term Schedulers or Job scheduler: This works as a selector of processes in the ready state. It brings multiple processes in the ready state. This also control the degree of multiprogramming.
    • Medium term Schedulers: This is responsible for the swapping in and out of the processes from the main memory to secondary memory and vice-versa. This is necessary if the main memory goes overloaded, we need to free it up for further executions.
    • Short term schedulers: These are also called CPU schedulers which is responsible for selecting a process from the ready state and dispatch it to processor for execution. It does not load the process in the processor but it dispatched it only. The loading is done by Dispatcher. Context Switching is done by this dispatcher.
  20. What do you mean by pre-emption?
    Ans. Pre-emption means removing a process from the CPU. It is also known as time sharing and multi-tasking.
  21. Describe the various types of time present in OS.
    Ans. The various types of time –
    • Arrival time: at which the process arrives in ready state.
    • Completion time: at which the process execution is completed.
    • Burst time: duration for process execution.
    • Turn around time: completion time – arrival time.
    • Waiting time: Turnaround time – burst time.
    • Response time: first time when process gets CPU -arrival time
  22. Give the various types of Process Scheduling algorithms.
    Ans. There are various kind of Scheduling algorithms. Some of them are –
    • First Come First Serve (FCFS)
    • Shortest Job First (SJF)
    • Longest Job First (LJF)
    • Shortest Remaining Time First (SRTF)
    • Longest Remaining Time First (LRTF)
    • Round Robin (RR)
    • Multilevel Queueing
    • Multi-level Feedback Queue Scheduling
  23. What is FCFS and describe it.
    Ans. FCFS stands for first come first serve job scheduling algorithm which schedules the process in the ready queue in terms of their arrival time and which ever process arrives first is served first. This implementation is done using a FIFO queue.
  24. Describe Round Robin Scheduling Algorithm.
    Ans. It is a scheduling algorithm in which each process is allotted a fixed time slot called quantum. When one of these processes get over with the fixed time slot (quantum) then they are swapped away with the next process in a circular fashion. You can think this like a circular queue. This swapping is called the context switch. It does not need to calculate the burst time and hence it is more practical in nature but uses a lot of overhead cost for this context switching.
  25. What is the race condition?
    Ans. Many processes access and manipulate the same data concurrently and without the presence of any locking or preventive mechanism the result of these process over the data depends on which order the processes have occurred. Let me give an example suppose we store a=5, now we increment it 5 times a=25 after which we substract 2 so out final a=23, again if we interchange these two operations a=5-2=3 and then a=3×5=15, hence we can see that both the operations have different outcomes when there occur in different order. This is called race condition.
  26. What do you mean by critical section of a code?
    Ans. Critical section of the code is basically the section which can be accessed by only process at a time. This section has to synchronise its variables with the program variables to maintain consistency.
  27. What is a deadlock?
    Ans. A deadlock is a situation where a thread is waiting for a resource that another thread holds, while the second thread is waiting for the resource held by the first thread (or an equivalent situation with several threads). Since each thread is waiting for the other to unlock the resource, both threads remain waiting forever.
  28. What are the conditions for Deadlock?
    Ans. These 4 conditions are necessary for deadlock occurrence –
    • Mutual Exclusion: Only one process can access a resource at a given time (or there are limited number of the same resource).
    • Hold and Wait: Processes already holding a resource can request additional resources without releasing their current resources.
    • No Pre-emption: One process cannot forcibly remove another process’ resource.
    • Circular Wait: Two or more processes form a circular chain where each process is waiting on another resource in the chain.
  29. What is starvation?
    Ans. Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by “greedy” threads.
  30. What are Monitors?
    Ans. These are ways for process Synchronisation. It is supported by programming languages to achieve mutual exclusion between processes.
  31. What do you mean by Inter Process Communication?
    Ans. IPC refers to the methods by which processes communicate with each other and synchronise the actions. This can be done by two ways –
    • Shared Memory
    • Message Passing
  32. Is it possible for a thread to acquire more than one lock (Mutex)?
    Ans. Yes, a thread can need more than one resources and hence more locks but it is logically unnecessary to have multiple locks for the same resource for the same thread.
  33. Does a thread always get blocked if its required resource is not available?
    Ans. Not really, if a thread is capable to skipping the particular section and pick up the next section of task it can always do so.
  34. What is a Resource Allocation Graph?
    Ans. To understand the process and state of the processes we need to represent all the processes and their holding or required resource in a graph like structure. This will help us in understanding whether we will arrive at a deadlock kind of situation or not. This graph is known as Resource Allocation Graph (RAG). It has the following components –
    • Process vertex: represented by circle
    • Resource vertex: represented by box
    • Dots in the resource vertex denotes number of instances of that resource present
    • Edges: these are the arrows or directions for assignment or dependency of resources to a process.
  35. What are the various methods of deadlock handling?
    Ans. The various methods are –
    Deadlock prevention – do not send any request that might cause deadlock.
    Deadlock Avoidance – Check the requests before sending to avoid deadlocks.
    Deadlock Detection and recovery – If deadlock occurs, pre-empt the process.
    Avoid deadlock altogether – neglect the whole process, applied when deadlock is not recoverable.
  36. What do you mean by binding?
    Ans. It is defined by which method is to be executed (i.e., connecting a method call to a method body).
    Static Binding – Occurs when the method call is bound at compile time.
    Dynamic Binding – The selection of the method body to be executed is delayed until runtime (based on the actual object being referred).
  37. What is the load time?
    Ans. It is basically the physical address getting time. If during compile time the physical address if nor known then the new relocatable address is generated. At this time binding occurs and once it is loaded it cannot be relocated.
  38. What is paging?
    Ans. It is basically a scheme by which it is not necessary to store data or instructions in contiguous memory locations. The physical address is mapped to virtual address of different pages, these pages contain the physical address of instructions which can be stored in non-contiguous memory locations. This is done by Memory Management Unit.
  39. What are overlays?
    Ans. It is used to enable a process to use more memory than it has already been allocated.
  40. What do you mean by Fragmentation?
    Ans. It refers to the free memory spaces which are broken into pieces due to loading and removal of processes from the memory. After some time, the processes cannot be allocated to memory blocks considering small sizes, this Is known as Fragmentation.
  41. What is Segmentation?
    Ans. Segmentation is a technique in which each job gets divided into segments of different sizes and groups where each such groups are made considering the same type of functions that it performs. Each such segments are a different logical address space of the program. This is quite similar to paging but here the segments are of variable lengths.
  42. When does thrashing occurs?
    Ans. Thrashing occurs when there are a greater number of pages to be accessed than the actual execution.
  43. What is caching?
    Ans. It refers to the storing of some of the processes or data for faster access for the next time. Most popular example of such caching is Least Recently Used cache which stores the processes which are recently used int the cache.
  44. What do you mean by interrupts?
    Ans. Interrupts are basically hardware mechanism which sends request to the CPU which are handled by interrupt handlers which tells the CPU to take actions accordingly to solve these interrupts.
  45. What are the types of CPU registers in a typical OS?
    Ans. These are –
    • Accumulators
    • Index Registers
    • Stack Pointer
    • General Purpose registers
  46. What are the different types of Operating systems?
    Ans. The various types of OS are –
    • Multi-programmed OS
    • Timesharing OS
    • Distributed OS
    • Batched OS
    • Real-time OS
  47. What is demand paging?
    Ans. It specifies that if a particular area of memory is not being used then it is swapped to the disk to make room for other application needs.
  48. What is spooling?
    Ans. This is a process in which data us temporarily gathered and executed by a device or program. It is generally associated with printing.
  49. Do you know about Belady’s Anomaly?
    Ans, It is also called FIFO anomaly. When we increase the number of frames allocated to a virtual memory then process execution becomes faster due to lesser page faults. But sometimes when the number of page faults increases this leads to slower executions which is known as Belady’s Anomaly.
  50. What do you mean by aging in OS?
    Ans. Aging is basically a technique to avoid starvation, it implies that the priority of a process keeps on increasing the more it stays in the memory for execution and hence at certain point it gets executed. This is basically done to avoid starvation i.e.; a process does not get CPU time and waits.

This article tried to discuss Top 50 OS interview questions and answers. Hope this blog helps you understand the concept. To practice problems you can check out Practice Important Interview Questions.

Leave a Reply

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