Post

Interview_Process/Thread/Deadlock/Paging/Semaphone/Mutex/Segmentation/Virtual Memory

Screenshot 2024-08-08 at 13 05 37

Process πŸ†š Thread

  • Process:
    • program running on memory
    • has own address, resource


  • Thread: work unit in process
    • does not have independent address, resource
    • only has independent stack

πŸ’‘ https://soheeparklee.github.io/posts/OS-2process-thread/

βœ… Why use multi threading instead of multi processing?

System call to create process and allocate resource decrease

  • communication between thread is costless than communication between process(IPC)
  • However, need to take synchronization into account for multi threading

βœ… Context Switching?

ν•˜λ‚˜μ˜ ν”„λ‘œμ„ΈμŠ€κ°€ CPUλ₯Ό μ‚¬μš© 쀑인 μƒνƒœμ—μ„œ λ‹€λ₯Έ ν”„λ‘œμ„ΈμŠ€κ°€ CPUλ₯Ό μ‚¬μš©ν•˜λ„λ‘ ν•˜κΈ° μœ„ν•΄, μ΄μ „μ˜ ν”„λ‘œμ„ΈμŠ€ μƒνƒœλ₯Ό λ³΄κ΄€ν•˜κ³  μƒˆλ‘œμš΄ ν”„λ‘œμ„ΈμŠ€μ˜ μƒνƒœλ₯Ό μ μž¬ν•˜λŠ” μž‘μ—…
ν•œ ν”„λ‘œμ„ΈμŠ€μ˜ λ¬Έλ§₯은 κ·Έ ν”„λ‘œμ„ΈμŠ€μ˜ PCB에 기둝됨

πŸ’‘ https://soheeparklee.github.io/posts/OS-6pcb/

Semaphore πŸ†š Mutex

  • Semaphore:

    • κ³΅μœ μžμ›μ— μ ‘κ·Όν•  수 μžˆλŠ” μ΅œλŒ€ ν—ˆμš©μΉ˜λ§ŒνΌλ§Œ λ™μ‹œμ— μ‚¬μš©μž μ ‘κ·Ό κ°€λŠ₯
    • μŠ€λ ˆλ“œλ“€μ€ λ¦¬μ†ŒμŠ€ μ ‘κ·Ό μš”μ²­
    • μ„Έλ§ˆν¬μ–΄λŠ” μΉ΄μš΄νŠΈκ°€ ν•˜λ‚˜μ”© μ€„μ–΄λ“€κ²Œ 되며 λ¦¬μ†ŒμŠ€κ°€ λͺ¨λ‘ μ‚¬μš©μ€‘μΈ 경우(카운트=0) λ‹€μŒ μž‘μ—…μ€ λŒ€κΈ°
  • Mutex:

    • μ œμ–΄λ˜λŠ” μ„Ήμ…˜μ— ν•˜λ‚˜μ˜ μŠ€λ ˆλ“œλ§Œ ν—ˆμš©
    • ν•΄λ‹Ή μ„Ήμ…˜μ— μ ‘κ·Όν•˜λ €λŠ” λ‹€λ₯Έ μŠ€λ ˆλ“œλ“€μ„ κ°•μ œμ μœΌλ‘œ λ§‰μŒ
    • 첫번재 μŠ€λ ˆλ“œκ°€ ν•΄λ‹Ή μ„Ήμ…˜μ„ λΉ μ Έλ‚˜μ˜¬ λ•ŒκΉŒμ§€ κΈ°λ‹€λ €μ•Ό 함

πŸ’‘ https://soheeparklee.github.io/posts/OS-11semapore/

βœ… What is deadlock?

What is deadlock?

When process cannot get the resource, and cannot work
occurs when several threads are trying to gain access to shared resource

Four conditions of deadlock

  • Mutual exclusion: shared resouce requires exclusive control, inshareable
  • Resource holding: thread is waiting for another resource to be released while holding onto an allocated resource
  • circular wait: each process waiting for a resource held by the next process in the chain
  • no preemption: thread cannot get a resource until the resource is finished by another thread

How to avoid deadlock?

  • prevention: eliminate condition
    (for no-preemtion: let go of the holding resource)
  • avoidance: run algorithm on requests to check for a safe state
  • detection
    > > recovery

πŸ’‘ https://soheeparklee.github.io/posts/OS-9deadlock/

βœ… Memory Hierchy

  • Register
  • Cache
  • RAM
  • Hard Disk

πŸ’‘ https://soheeparklee.github.io/posts/4-WEB_os_architecture/

βœ… Memory Allocation Algorithm

  • First fit:

    • search memory from start
    • allocate the first space that has enough storage
  • Next fit:

    • begin search from the last allocated place
  • Best fit:

    • search all the memory to find the best place to allocate

πŸ’‘ https://soheeparklee.github.io/posts/OS-12paging/

βœ… Paging, Segmentation

βœ”οΈ Paging

  • optimize memory usage
  • divide memory into fixed-size pages

βœ”οΈ Segmentation

  • divide memory into various size, more flexible

πŸ’‘ https://soheeparklee.github.io/posts/OS-12paging/

βœ… Page Fault, Virtual Memory

βœ”οΈ Page Fault

  • when a running program accesses a memory page that is mapped into virtual address space
  • but not loaded on physical memory
  • OS has to replace one of the existing page with newly needed page
  • thus, the need for page replacement algorithm

βœ”οΈ Virtual Memory

  • memory management technique
  • create an illusion of memory using RAM + disk storage
  • μ‹€μ œ λ©”λͺ¨λ¦¬ μ•ˆμ— 곡간이 λΆ€μ‘±ν•˜λ©΄, ν˜„μž¬ μ‚¬μš©ν•˜κ³  μžˆμ§€ μ•Šμ€ 데이터λ₯Ό λΉΌλ‚΄μ–΄ 가상 λ©”λͺ¨λ¦¬μ— μ €μž₯해두고, μ‹€μ œ λ©”λͺ¨λ¦¬μ—μ„  처리만 ν•˜κ²Œ ν•˜λŠ” 것이 가상 λ©”λͺ¨λ¦¬μ˜ 역할이닀.
  • 즉, μ‹€μ œ λ©”λͺ¨λ¦¬μ— 놀고 μžˆλŠ” 곡간이 μ—†κ²Œ 계속 일을 μ‹œν‚€λŠ” 것. 이λ₯Ό λ„μ™€μ£ΌλŠ” 것이 β€˜κ°€μƒ λ©”λͺ¨λ¦¬β€™

βœ… Page Replacement Algoirthm

  • FIFO: keep memory in queue, oldest page is in front
  • LRU: Least recently used 졜근 κ°€μž₯ μ˜€λž«λ™μ•ˆ μ‚¬μš©ν•˜μ§€ μ•Šμ€ νŽ˜μ΄μ§€
  • LFU: Least frequently used μ‚¬μš© λΉˆλ„ 적은 νŽ˜μ΄μ§€
  • MRU: Most recently used

⭐️ Key words in process, thread

  • multi threading, process
  • synchronization

⭐️ Key words in CPU, thread

  • CPU ➑️ thread allocate
  • CPU scheduling
  • preemptive: Round Robin, SRTF
  • non-preemptive: FCFS, SJF, HRN
  • starvation
  • aging

⭐️ Key words in Memory, page

  • Memory ➑️ page
  • paging
  • segmentation
  • internal
  • external segmentation
  • compaction
  • best fit/next fit/first fit

  • page replacement
  • page fault
  • FIFO/LRU/MRU/NUR/LFU/Optimal Place Replacement
This post is licensed under CC BY 4.0 by the author.