UNIX Concurrency Mechanisms
Signals
π‘ μ μ λ 벨μ νΈλ€λ§ λ©μΉ΄λμ¦μ΄λΌκ³ μ½κ² λ§ν μ μλ€.
A software mechanism that informs a process of the occurrence of asynchronous events (similar to a hardware interrupt)
βοΈ Sending a signal
- Kernel sends (delivers) a signal to a destination process by updating some state in the context of the destination process
- Kernel sends a signal for one of the following reasons:
- Kernel has detected a system event such as divide-by-zero (SIGFPE) or the termination of a child process (SIGCHLD)
- Another process has invoked the kill system call to explicitly request the kernel to send a signal to the destination provess
βοΈ Receiving a signal
- A destination process receives a signal when it is forced by the kernel to react in some way to the delivery of the signal
- Two possible ways to react
- Default action (ignore, terminate the process, terminate & dump)
- Catch the signal by executing a user-level function called a signal handler
- Akin to a hardware exception handler being called in response to an asynchronous interrupt
Signal Concepts
βοΈ A Signal is pending if it has been sent but not yet received
- There can be at most one pending signal of any particular type
- Signals are not queued
- If a process has a pending signal of type k, then subsequent signals of type k that are sent to that process are discarded
βοΈ A process can block the receipt of certain signals
- Blocked signals can be delivered, but will not be received until the signal is unblocked
βοΈ Kernel maintains pending
and blocked
bit vectors in the context of each process
Memory Management
Terminology
π‘ Frame
A fixed-length block (unit) of main memory
π‘ Page
νμΌμ κ³ μ μ μΈ ν¬κΈ°μ 물리μ κ΅¬μ± λ¨μ
A fixed-length block of a program. It is a unit of transfer between secondary storage and main memory
π‘ Segment
νμΌμ κ°λ³μ μΈ ν¬κΈ°μ λ
Όλ¦¬μ κ΅¬μ± λ¨μ
A variable-length block of a program. An entire segment may be copied into main memory (segmentation) or the segment may be divided into pages which can be individually copied into main memory (segmented paging)
Memory Organization
βοΈ Logical Organization
- Users view programs as a collection of modules
- modules can be written and compiled independently
- different protection (read-only, execute-only) are given to different modules
- module level sharing corresponds to the user's way of viewing the problem
- Segmentation is the tool that most readily satisfies requirement
βοΈ Physical Organization
- Computer memory is organized as main memory and secondary memory
- Main memory is organized as a linear array of bytes
- main memory available for a program may not be sufficient
- programmer does not know how much space will be available
βοΈ Memory management technique involve
- Paging, segmentation, overlaying, and virtual memory, etc
- Overlaying allows various modules to be assigned the same region of memory with a main program responsible for siwtching the modules in and out
Memory partitioning
κ°μλ©λͺ¨λ¦¬ μ΄μ μ λ©λͺ¨λ¦¬ κ΄λ¦¬ κΈ°λ² Memory partitioning μ λν΄ μ΄ν΄λ³Έλ€.
βοΈ Fixed partitioning
- Physical Memoryλ₯Ό κ³ μ μ μΈ ν¬κΈ°μ νν°μ
μΌλ‘ μμ€ν
μ΄ μμ±λ λ μͺΌκ°λ λ°©λ²μ΄λ€. ν νλ‘μΈμ€λ μμ μ μ΄λ―Έμ§λ³΄λ€ μκ±°λ ν° νν°μ
μ λ‘λ©λλλ° μ΄ λ°©λ²μ ꡬνμ΄ μ½μ§λ§ κ½€ λΉν¨μ¨μ μ΄λ€.
- Problem
- Internal Fragmentation : wasted space inside a fixed partition (λλΉλλ 곡κ°)
- νν°μ
μμ λ°λΌ μ€νκ°λ₯ν νλ‘μΈμ€μ μ (degree) κ° μ ν΄μ Έμλ€.
βοΈ Buddy System
- Use both fixed and dynamic partitioning (μ μΆ©μ)
βοΈ Dynamic partitioning
- λ€μν ν¬κΈ°λ₯Ό κ°μ§ μ μλ νλ‘μΈμ€μ λ§μΆ μ μλ€.
- νλ‘μΈμ€ μ΄λ―Έμ§μ λ°λΌμ νλ‘μΈμ€κ° μμ²ν λ§νΌ ν λΉνλ€. νν°μ
μμ λ°λΌ μ€νκ°λ₯ν νλ‘μΈμ€μ μκ° μ λμ μΌλ‘ λ³νλ€.
- Problem
- External Fragmentation (hole) : Memory becomes more and more fragmented
- Compaction
- Technique to overcome External Frangmentation
- It is a overhead time consuming process, wasting CPU time
π‘ Process Image
νλ‘κ·Έλ¨ μ½λ, λ°μ΄ν°μ μκ°μ process μν(λ μ§μ€ν° λ΄μ©, νλ‘μΈμ μν μλ, κΈ°ν) μ μ§ν©μ΄λ©°, μΌμ’
μ μ€λ
μ·μ΄λΌκ³ μκ°νλ©΄ λ λ―νλ€. PCB μλ μ΄λ―Έμ§μ process contextκ° μ μ₯λλ€
(μλ κ·Έλ¦Ό μ°Έκ³ )
Paging
π‘ Paging
- Partition memory into equal fixed-size chunks (page frames)
- Process image is divided into the same fixed-size chunks (pages)
π‘ Page Table
μ΄λ€ νμ΄μ§κ° μ΄λ€ νμ΄μ§ νλ μμ λ‘λλμ΄μλμ§?
- Contains the mapping between pages and frames
- For each page in the process, PTE (page table entry) contains the frame number
- Maintained by operating system for each process
- CPU must access the page table to generate a physical address for the current process
- TLB(MMU) μ μ¬μ© μ΄μ ?
Segmentation
π‘ Segmentation
- A program is divided into variable-length sgments
- The address consists of segment number + offset
- No internal fragmentation
- But, external fragmentation
- Similar to dynamic partitioning
π Reference
νλ‘μΈμ€ μ΄λ―Έμ§μ κ΄ν΄μ μ°Έκ³ ν λΈλ‘κ·Έ
[KUOCW] μ΅λ¦° κ΅μλμ μ΄μ체μ κ°μλ₯Ό μκ°νκ³ μ 리ν λ΄μ©μ
λλ€. μλͺ»λ λ΄μ©μ΄ μλ€λ©΄ λκΈλ‘ μλ €μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€ π