5 DERECHA

Interview Questions 본문

Operating System

Interview Questions

kay30 2023. 10. 22. 00:36

https://www.geeksforgeeks.org/oops-interview-questions/

1. What is Operating System ?

  An operating system is an interface that manages hardware resources and serves as a bridge between hardware and applications or software(e.g. service daemon) that run on it by using kernel.  It coordinates various hardware resources, such as the CPU, GPU, memory, storage devices, and input/output peripherals(keyboard, mouse), to ensure efficient and secure execution of programs. Essentially it makes the system user-friendly and functional.

 

2. What is Kernel ?

 The kernel is the core part of the operating system that lives in memory and is a resource manager that allows users to use computer resources through System Call.

The primary aim of the kernel is to oversee both the physical (hardware) resources and abstract resources of the computer. Abstraction(Virtualization) is a method that transforms one physical piece of hardware into what appears to be multiple parts, allowing multiple users to utilize it in turn.

  • Task(Process) Management : 물리적 자원인 CPU를 추상적 자원인 Task로 제공
  • Memory Management : 물리적 자원인 메모리를 추상적 자원인 Page 또는 Segement로 제공
  • File System : 물리적 자원인 디스크를 추상적 자원인 File로 제공
  • Network Managment : 물리적 자원인 네트워크 장치를 추상적 자원인 Socket으로 제공
  • Device Driver Management : 각종 외부 장치에 대한 접근
  • Interrupt Handling : 인터럽트 핸들러
  • I/O Communication : 입출력 통신 관리

Monolithic Kernel:

A monolithic kernel handles most system services directly within the kernel, making it large and vulnerable to errors affecting the whole system. However, it efficiently shares resources among services and modern versions allow for easier updates.

Examples: Unix, Embedded Linux, OSEK, WinMobile.

Micro Kernel:

A micro kernel is lightweight, retaining only core services in the kernel and moving the rest to separate server-like entities. This structure relies on inter-process communication and can lead to more context switches and increased system load with system complexity.

Advantages include the ability to add or modify features without changing the kernel itself and isolation of services, preventing failures from affecting others.

Examples: MacOS, Windows NT.

 

3. Can you explain the structure of memory(RAM) based on different regions?

1) Code area (text area):
  The code area of the program to be executed is stored, also called the 'text' area. The CPU takes the instructions stored in the code area one by one and processes them.

2) Data area (static area):
  The area where global and static variables are stored, assigned at the start of the program and extinguished at the end of the program. Or, .bss is for unitializaed vars.

3) Hip area (Heap):
  This is a user-managed area that dynamically allocates in heap memory space.This is decided size on Runtime.

4) Stack Area:
  The area where local variables and parameters are stored according to the function's call, and the size is determined when compiled. It is assigned with the call of the function, and disappears when the call of the function ends.

 

4. Explain the process and thread, and the difference between the two.

Processes are standalone programs with their own memory and CPU. Threads are smaller units of  execution  within a process, sharing memory with other threads in the same process.

Key differences:

Isolation: Processes are isolated; threads share memory.
Synchronization: Threads may need synchronization; processes often do not.
Context Switching: Threads switch context more efficiently.
Creation Time: Threads are quicker to create.
Error Impact: Thread errors can affect others in the same process, while process errors usually don't.

 

5. Explain context switching and explain why context switching is necessary.

Context switching is like changing tasks on your computer. Imagine you're working on something, and then you need to switch to a different task. Here's why it's necessary:

1) Speed Difference: Your computer's "thinking" (CPU) is way faster than "doing" (I/O operations like reading from a hard drive). So, when one task is waiting for slow I/O, your CPU can do other things.

2) Efficiency: Context switching lets your computer switch between tasks or threads, making better use of the CPU. It's like juggling multiple tasks.

3) Steps:
   3-1 )  The system saves what you were doing in a special file (PCB).
   3-2  )  It picks the next task to do from a queue.
   3-3  )  It loads what you were doing into the program counter and picks up where you left off with the new task.
   3-4  )  In a nutshell, context switching is essential for efficient multitasking. It keeps the CPU busy even when some tasks are waiting around.

 

6. Please describe the process control block (PCB) in more detail.

The Process Control Block (PCB) is a fundamental data structure within an operating system, providing crucial information for process management. Let's delve deeper into its components and functions:

- Unique Identification: When a process is created, the OS generates a distinct PCB to represent it.

- Protected Storage: The PCB is securely stored in a protected memory area, safeguarded from general user access.

- Context Switching: During a process's execution, it is allocated CPU time. If a context switch occurs (e.g., due to time allocation or an interrupt), the PCB captures the process's current state. When the process resumes execution, the PCB restores this state, allowing the process to pick up from where it left off. This mechanism is known as context switching.

- Key Information: PCBs house critical information, including:

   1) Process Identifier (PID): A unique identification number for each process.
   2) Process Status: The current status of the process, such as whether it's new, ready, running, waiting, or terminated.
   3) Program Counters: The memory address of the next command the process will execute.
   4) CPU Registers: A snapshot of the CPU's register contents.
   5) CPU Scheduling Details: Information about the process's priority and its position in the scheduling queue.
   6) Memory Management Information: Data structures like page tables or segment tables, crucial for memory access.
   7) Input/Output Status: Information about I/O devices and open files assigned to the process.
   8) Accounting Information: Metrics like CPU time consumed, time limits, and account numbers.


In essence, the PCB serves as a process's detailed profile, allowing the operating system to efficiently manage processesswitch between them, and maintain their individual states.

 

7. Compare multi-threads and multi-processes.

1) Multi-Threads:

  Multi-threading involves breaking a single process into multiple threads that work concurrently while sharing resources.
It's memory-efficient and offers fast context switching, but there's a challenge with synchronization. If one thread encounters an error, it can impact the entire thread group.


2) Multi-Processes:

  Multi-processing organizes a program into separate processes that work independently in parallel. Each process  is  isolated, so if one process fails, it doesn't affect the others. However, this method consumes more memory than multi-threads.


3) When to Use Multi-Threads:

  Multi-threading is advantageous for efficiently handling multiple tasks within a single program. It's faster due to minimal overhead during context switching, and it efficiently manages resources by reducing the need to allocate resources when creating processes.


For I/O-heavy operations, multi-threading can be highly effective.
For CPU-intensive operations, multi-processing can parallelize tasks effectively.

 

* Overloading(static으로 사용해야하는 경우 생김 - unresolved overloading type)(함수 이름은 같고 리턴타입이나 파라미터가 다른거) vs Overriding(함수 상속(Inheritance)할때)(파라미터랑 리턴타입이랑 이름이랑 다 같아야함)

* Unordered_map구현 알아보기

 

 

참고 : https://hoons-dev.tistory.com/95

'Operating System' 카테고리의 다른 글

Operating System (Memory Manager)  (1) 2023.04.17
Operating System (Hardware Initialization)  (0) 2023.04.11
Operating System  (0) 2023.03.06