Few Interview Questions on Operating Systems

Operating systems provide the crucial interface between a computer’s hardware and the applications that run on it. It allows us to write programs without bothering much about the hardware. It also ensures that the computer’s resources such as its CPU, hard disk, and memory, are appropriately utilized.

Here we have listed the questions whicah can be asked  in interview on operating systems.

  1. Why paging is used?
  2. What is virtual memory?
  3. What is difference between threads and process ?
  4. What is important aspect of real time operating system ?
  5. What is difference between hard and soft real time system?
  6. What is thrashing?
  7. What is multi-tasking, multi programming, multi-threading ?
  8. What is Fragmentation and its types ?
  9. What does it mean to be a 32 bit Operating System?
  10. Explain the concept of the Distributed Operating Systems?
  11. What is cache-coherency?
  12. What are system calls?
  13. What is a layered approach in operating system and what is its advantage?
  14. What is micro kernel approach and site its advantages?
  15. What are virtual machines and site their advantages?
  16. What is a process?
  17. What is cache memory?

 

1.Why paging is used ?

Paging is a memory management technique in which the memory is divided into fixed size pages.

Paging is used for faster access to data. When a program needs a page, it is available in the main memory as the OS copies a certain number of pages from secondary storage device to main memory.

Paging is solution to external fragmentation problem which is to permit the logical address space of a process to be noncontiguous, thus allowing a process to be allocating physical memory wherever the latter is available.

 

2.What is virtual memory?

Virtual memory is a memory management capability of an OS that uses hardware and software to allow a computer to compensate for physical memory shortages by temporarily transferring data from random access memory to disk storage. 

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

In Virtual memory, it is not necessary that all the pages or segments are present in the main memory during execution.

This means that the required pages need to be loaded into memory whenever required. Virtual memory is implemented using Demand Paging or Demand Segmentation

Pros and cons of using virtual memory

  • Among the primary benefits of virtual memory is its ability to handle twice as many addresses as main memory.
  • It uses software to consume more memory by using the HDD as temporary storage while memory management units virtual memory addresses to physical addresses via the central processing unit.
  • Programs use virtual addresses to store instructions and data; when a program is executed, the virtual addresses are converted into actual memory addresses.

Other advantages of virtual memory are that it frees applications from managing shared memory and saves users from adding more memory modules when RAM space runs out.

However, the use of virtual memory has its trade-offs, particularly with speed. The use of virtual memory slows a computer because data must be mapped between virtual and physical memory, which requires extra hardware support for address translations.

 

3.What is difference between threads and process ?

The Process and Thread are the essentially correlated. The process is an execution of a program whereas thread is an execution of a program driven by the environment of a process.

The difference between them is as follows-

1.The processes and threads are independent sequences of execution, the typical difference is that threads run in a shared memory space, while processes run in separate memory spaces.

2.A process has a self-contained execution environment that means it has a complete, private set of basic run time resources particularly each process has its own memory space. Threads exist within a process and every process has at least one thread.

3.Processes are heavily dependent on system resources available while threads require minimal amounts of resource, so a process is considered as heavyweight while a thread is termed as a lightweight process.

4.On a multiprocessor system, multiple processes can be executed in parallel. Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.

5.Threads have direct access to the data segment of its process but a processes have their own copy of the data segment of the parent process.

6.Changes to the main thread may affect the behaviour of the other threads of the process while changes to the parent process do not affect child processes.

 

4.What is important aspect of real time operating system ?

Real time operating system is a system that promises to deliver certain amount of processing power in certain timeframe.  

A real time system is a time bound system which has well defined fixed time constraints.

Processing must be done within the defined constraints or the system will fail.They either are event driven or time sharing.

Event driven systems switches between tasks based on their priorities while time sharing systems switch the task based on clock interrupts.

Some real time operating system that is specifically used in real time scenario like missile, medical electronics, aerospace, automotive etc.

Example of RTOS

  1. VxWorks
  2. 2.FreeRTOS
  3. Ecos
  4. Integrity
  5. Cocoon etc..,

 

5.What is difference between hard and soft real time system?

In hard real time system, operating system has to perform its task within or on time bound. Hard Real time system does not allow time delay, if the result is obtained after the deadline, the system is considered to have failed completely.

Example: In case of a robot doing some job like line tracing, etc. If a hindrance comes on its path, and the robot doesn’t process this information within some programmed deadline (almost instant!), the robot is said to have failed in its task.

soft real time operating system also has time bound,but some delay is permitted in soft real time operating system,So even if the result is obtained after the deadline, the results are still considered as valid.

Example: Web browser- We request for certain URL, it takes some time in loading the page. If the system takes more than expected time to provide us with the page, the page obtained is not considered as invalid.

 

6.What is thrashing?

The term thrashing is actually related to the virtual memory, that an operating system uses in order to provide extra amount of memory or space for the processes.

Increase the degree of multiprogramming  means increase number process in memory, in this case every process will be able to store few pages in main memory, and remaining pages will be in secondary memory.

During executions of these multiple processes, if any process refers a page which is not in memory, operating system is responsible making space in memory and bring that page in main memory.

Thrashing is a condition in which excessive paging operations are taking place. A system that is thrashing can be perceived as either a very slow system or one that has come to a halt.

 

7.What is multi-tasking, multi programming, multi-threading ?

Multiprogramming

In a multiprogramming system there are one or more programs loaded in main memory which are ready to execute.

Only one program at a time is able to get the CPU for executing its instructions while all the others are waiting their turn.

The main idea of multiprogramming is to maximize the use of CPU utilization. Indeed, suppose the currently running process is performing an I/O.

Then, the OS may interrupt that process and give the control to one of the other processes are ready to execute

In this way, no CPU time is wasted by the system waiting for the I/O task to be completed, and a running process keeps executing until either it voluntarily releases the CPU or when it blocks for an I/O operation.

Multitasking

Multitasking has the same meaning of multiprogramming but in a more general sense, as it refers to having multiple (programs, processes, tasks, threads) running at the same time.

This term is used in modern operating systems when multiple tasks share a common processing resource (e.g., CPU and Memory). At any time the CPU is executing one task only while other tasks waiting their turn.

The illusion of parallelism is achieved when the CPU is reassigned to another task (i.e. process or thread context switching).

There are subtle differences between multitasking and multiprogramming. A task in a multitasking operating system is not a whole application program but it can also refer to a “thread of execution” when one process is divided into sub-tasks.

Each smaller task does not hijack the CPU until it finishes like in the older multiprogramming but rather a fair share amount of the CPU time called quantum.

Just to make it easy to remember, both multiprogramming and multitasking operating systems are (CPU) time sharing systems.

However, while in multiprogramming one program as a whole keeps running until it blocks, in multitasking time sharing is best manifested because each running process takes only a fair quantum of the CPU time.

Multithreading

Up to now, we have talked about multiprogramming as a way to allow multiple programs being resident in main memory and running at the same time.

hen, multitasking refers to multiple tasks running simultaneously by sharing the CPU time.

Multithreading is an execution model that allows a single process to have multiple code segments (i.e., threads) run concurrently within the “context” of that process.

You can think of threads as child processes that share the parent process resources but execute independently.

Multiple threads of a single process can share the CPU in a single CPU system or run in parallel in a multiprocessing system.

 

8.What is Fragmentation and its types ?

Fragmentation occurs in a dynamic memory allocation system when many of the free blocks are too small to satisfy any request.

External Fragmentation:

External Fragmentation happens when a dynamic memory allocation algorithm allocates some memory and a small piece is left over that cannot be effectively used. If too much external fragmentation occurs, the amount of usable memory is drastically reduced.

Total memory space exists to satisfy a request, but it is not contiguous.

Internal Fragmentation:

Internal fragmentation is the space wasted inside of allocated memory blocks because of restriction on the allowed sizes of allocated blocks.

Allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.

 

9.What does it mean to be a 32 bit Operating System?

32-bit operating system works on 32-bit processor, which means the operating system and software work with data units that are 32 bits wide.

Windows 95, 98, and XP are all 32-bit operating systems.

The CPU register stores memory addresses, which is how the processor accesses data from RAM. One bit in the register can reference an individual byte in memory, so a 32-bit system can address a maximum of 4 GB (4,294,967,296 bytes) of RAM. 

The actual limit is often less around 3.5 GB, since part of the register is used to store other temporary values besides memory addresses.

Most computers released over the past two decades were built on a 32-bit architecture; hence most operating systems were designed to run on a 32-bit processor.

 

10.Explain the concept of the Distributed Operating Systems?

Distributed Operating System is a model where distributed applications are running on multiple computers linked by communications.

A distributed operating system is an extension of the network operating system that supports higher levels of communication and integration of the machines on the network.

This system looks to its users like an ordinary centralized operating system but runs on multiple, independent central processing units (CPUs).

Distributed systems provide the following advantages:

  1. Sharing of resources.
  2. Reliability.
  3. Communication.
  4. Computation speedup.

 

11.What is cache-coherency?

Cache coherence is the regularity or consistency of data stored in cache memory.

Maintaining cache and memory consistency is imperative for multiprocessors or distributed shared memory (DSM) systems.

Cache management is structured to ensure that data is not overwritten or lost. Different techniques may be used to maintain cache coherency, including directory based coherence, bus snooping.

To maintain consistency, a DSM system imitates these techniques and uses a coherency protocol, which is essential to system operations. Cache coherence is also known as cache coherency or cache consistency.

 

12.What are system calls?

System calls provide an interface between user programs and operating system.It is a programmatic way in which a computer program requests a service from the kernel of the operating system.

System calls often use a special machine code instruction which causes the processor to change mode (e.g. to “supervisor mode” or “protected mode”). This allows the OS to perform restricted actions such as accessing hardware devices or the memory management unit.

 

13.What is a layered approach in operating system and what is its advantage?

  • The operating system is divided into a number of layers (levels), each built on top of lower layers.  
  • The bottom layer (layer 0) is the hardware; the highest (layer N) is the user interface.
  • With modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers.

Advantages of layered operating systems are:

  • It allows good maintenance, where you can make changes without affecting layer interfaces.
  • It provides different level of abstraction.

 

14.What is micro kernel approach and site its advantages?

Micro kernel approach is a step towards modularizing the operating system where all nonessential components from the kernel are removed and implemented as system and user level program, making the kernel smaller.

The benefits of the micro kernel approach include the ease of extending the operating system. All new services are added to the user space and consequently do not require modification of the kernel.

And as kernel is smaller it is easier to upgrade it.

Also this approach provides more security and reliability since most services are running as user processes rather than kernel’s keeping the kernel intact.

 

15.What are virtual machines and site their advantages?

Virtual Machine is a completely separate individual operating system installation on your usual operating system.

It is implemented by software emulation and hardware virtualization. Virtual machine is a software implementation of a physical machine – computer – that works and executes analogically to it.

Frequently multiple virtual machines with their own OS’s are used in server consolidation, where different services are run in separate virtual environments, but on the same physical machine.

The main advantages of virtual machines:

  • Multiple OS environments can exist simultaneously on the same machine, isolated from each other;
  • Virtual machine can offer an instruction set architecture that differs from real computer’s;
  • Easy maintenance, application provisioning, availability and convenient recovery.

16.What is a process?

A program in execution is called process. It is an active entity. A process consists of –

  • An address space, containing
  • the code (instructions) for the running program .
  • the data for the running program (static data, heap data, stack) – CPU state, consisting of
  • The program counter (PC), indicating the next instruction
  • The stack pointer
  • Other general purpose register values – A set of OS resources
  • open files, network connections, sound channels.

In other words, everything needed to run the program.

 

 

17.What is cache memory?

The function of the cache memory is to speed up the Main Memory data access and the most important in multiprocessor systems, with shared memory, to reduce the system bus and Main Memory traffic that are the major parts of this system.

It is a fast and relatively small memory, not visible to the software, that is completely handled by the hardware, that stores the most recently used pages from main memory.