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] ์ต๋ฆฐ ๊ต์๋์ ์ด์์ฒด์ ๊ฐ์๋ฅผ ์๊ฐํ๊ณ ์ ๋ฆฌํ ๋ด์ฉ์
๋๋ค. ์๋ชป๋ ๋ด์ฉ์ด ์๋ค๋ฉด ๋๊ธ๋ก ์๋ ค์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค ๐