[OS] Operating System(1-2): Operation, Resource Management, Virtualization
π μ΄μ체μ μ 곡 μμ μ 리
OS-Operations
- Bootstrap program - simple code to initialize the system, load the kernel(μ»΄ν¨ν°λ₯Ό μ΄κΈ°ν(λΆν )νλ μν μ νλ κ°λ¨ν μ½λ)
- Kernel load
- Starts system daemons
- λ°±κ·ΈλΌμ΄λμμ μ€νλλ μλΉμ€ νλ‘κ·Έλ¨
- 컀λμ΄ λ‘λλ ν, system daemonsκ° μ€νλλ©° μ΄μ 체μ μ μ£Όμ κΈ°λ₯μ λ΄λΉ
- 컀λ μΈλΆμμ μ 곡λλ μλΉμ€λ€λ‘, OSκ° μ μμ μΌλ‘ λμνλλ‘ μ§μ
- Kernel interrupt driven(κΈ°λ°)
- Hardware interrupt by one of the devices - μ»΄ν¨ν°μ deviceκ° CPUμκ² μμ
μμ²μ λ³΄λΌ λ λ°μ
- ex: ν€λ³΄λλ₯Ό λλ₯΄λ©΄ CPUκ° μ΄λ₯Ό κ°μ§νκ³ μ λ ₯μ μ²λ¦¬, νλλμ€ν¬μμ λ°μ΄ν°λ₯Ό μ½μ λ CPUμκ² μλ£ μ νΈλ₯Ό 보λ
- Software interrupt (exception or trap)- Softwareμμ νΉμ ν μ΄λ²€νΈκ° λ°μν κ²½μ° CPUκ° μ²λ¦¬νλ interrupt (λκΈ°μ μ/ ctrl+c κ°μ μΈλΆ interruptλ λΉλκΈ°μ )
- software error (ex: Division by Zero, Segmentation Fault)
- system call - Request for OS service(νλ‘κ·Έλ¨μ΄ μ΄μ 체μ μ κΈ°λ₯μ μ¬μ©νκΈ° μν΄)
- ex: νμΌ μ½κΈ°/μ°κΈ°(
read()
,write()
), νλ‘μΈμ€ μμ±(fork()
), λ©λͺ¨λ¦¬ ν λΉ(malloc()
)
- Other process problems
- ex: Infinite loop, processes modifying each other or the operating system
- Hardware interrupt by one of the devices - μ»΄ν¨ν°μ deviceκ° CPUμκ² μμ
μμ²μ λ³΄λΌ λ λ°μ
Multiprogramming and Multitasking
- Multiprogramming (Batch System)
- Single user cannot keep CPU and I/O devices busy at all times(λ³μ μ§λ£μ²λΌ)
- μ¬λ¬ κ°μ μμ (code, data)μ κ΄λ¦¬νμ¬ CPU always has one to execute(CPUκ° νμ μ€νν μμ μ κ°μ§ μ μλλ‘ ν¨)
- νΉμ§:
- A subset of total jobs in system is kept in memory
- One job selected and run via job scheduling
- When it has to wait (for I/O for example), OS switches to another job (λ€λ₯Έ μμ μΌλ‘ μ ννμ¬ CPUκ° λμ§ μλλ‘ ν¨)
- Timesharing (multitasking)
- logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing
- νΉμ§:
- Response time should be < 1 second
- Each user has at least one program executing in memory -> process
- If several jobs ready to run at the same time -> CPU scheduling (CPU schedulingμ ν΅ν΄ μ¬λ¬ κ°μ μ€λΉλ μμ μ€ νλλ₯Ό μ ν ν μ€ν)
- If processes donβt fit in memory, swapping moves them in and out to run
- Virtual memory allows execution of processes not completely in memory
Multiprogramming vs Multitasking λΉκ΅
κ°λ | Multiprogramming | Multitasking |
---|---|---|
λ°©μ | νλμ νλ‘κ·Έλ¨μ΄ CPUλ₯Ό μ μ νλ©΄, λ€λ₯Έ νλ‘κ·Έλ¨μ λκΈ° | CPUκ° μ¬λ¬ μμ μ λΉ λ₯΄κ² μ ν, λμμ μ€νλλ κ²μ²λΌ |
λͺ©μ | CPUκ° νμ μμ μ μ€ννλλ‘ μ μ§ | μ¬μ©μκ° μ¬λ¬ νλ‘κ·Έλ¨μ λμμ μ¬μ©ν μ μλλ‘ μ§μ |
CPU νμ© | CPUκ° λμ§ μλλ‘ I/O μμ μ΄ λλ λκΉμ§ λ€λ₯Έ μμ μ μ€ν | μ¬μ©μκ° μ€ννλ μ¬λ¬ κ°μ νλ‘κ·Έλ¨μ λΉ λ₯΄κ² μ ν |
λ°μ μλ | μ¦κ°μ μ΄μ§ μμ (λ°°μΉ μ²λ¦¬) | < 1μ΄ (μ¦κ°μ μΈ λ°μ) |
λν μ¬λ‘ | Batch System (λ³μ μ§λ£ μμ½) | μ΄μ체μ μμ μ¬λ¬ νλ‘κ·Έλ¨ μ€ν (Windows, macOS) |
- λ©λͺ¨λ¦¬λ OS μμ, User Process μμμΌλ‘ λλ¨
- OSλ λ©λͺ¨λ¦¬μ max μ£Όμμμ μ€νλλ©°, μμ€ν μ μ μ΄νκ³ κ΄λ¦¬νλ€
- μ¬μ©μ νλ‘μΈμ€(Process 1, 2, 3, 4)λ λ©λͺ¨λ¦¬μ νλ¨λΆν° μμͺ½ λ°©ν₯μΌλ‘ λ‘λλ¨
(μ¦, νλ‘μΈμ€λ μ£Όμ 0μμ μμνμ¬ μμͺ½μΌλ‘ ν λΉλ¨) - λ€μ€ νλ‘κ·Έλλ° μμ€ν μμλ μ¬λ¬ κ°μ νλ‘μΈμ€κ° λμμ λ©λͺ¨λ¦¬μ μ μ¬λμ΄ CPUκ° μμ μ κ΅μ²΄νλ©° μ€νν μ μμ
Dual-mode and Multimode Operation
Dual-mode operation allows OS ot protect itself and other system components
- μ΄μ체μ λ₯Ό 보νΈνκΈ° μν΄ CPUλ λκ°μ§ λͺ¨λμμ μλ:
- User mode: μΌλ° μ¬μ©μ μμ© νλ‘κ·Έλ¨ μ€ν
- Kernel mode: OSκ° μ€ν, νλμ¨μ΄ λ° μμ€ν 리μμ€μ λν μ 체 κΆνμ κ°μ§(priviledged mode, supervised mode, system mode)
- Mode bit: provided by hardware
- Provides ability to distinguis when system is running user code or kernel code
- μ΄μ체μ λ mode bitλ₯Ό νμΈνμ¬ μμ€ν 보νΈλ₯Ό μν
Privileged Instruction only executable in kernel mode
- Increasingly CPUs support multi-mode operations
- Virtual Machine Manager(VMM) λͺ¨λ μ§μ
- VMM has more priviledges than user processes but fewer than the kernel
Transition from User to kernel Mode
Timer to prevent infinite loop / process hogging resources
- Timer Set: To interrupt the computer after some time period
- Keep Counter: Decremented(κ°μ) by the physical clock
- Operating system set the counter (privileged instructionμΌλ‘λ§ κ°λ₯)
- When counter zero, generate an interrup
Set up before scheduling process to regain control or terminate program that exceeds allotted time
- μλ λ°©μ
User Mode
μμ μ€ν μ€μΈ νλ‘μΈμ€κ° System Call(ex: νμΌ μ½κΈ°, λ€νΈμν¬ μμ², λ©λͺ¨λ¦¬ ν λΉ λ±)
- μ¬μ©μκ° System Call β CPUλ
trap
λ°λ -> Kernel modeλ‘ λ³κ²½λ¨(mode bit = 0)
- μμ
μλ£ ν λ€μ User Modeλ‘ λ³κ²½λ¨
(mode bit = 1)
mechanism
Resource Management
Process Management
- Processλ?
- μ€ν μ€μΈ νλ‘κ·Έλ¨
- Programμ λ¨μν μ½λ(passive entity), Processλ μ€ν μ€μΈ μ½λ(active entity)
- Process needs resources to accomplish its task
- CPU, memory, I/O, files, Initialization data
- Process termination(μ’
λ£) requires reclaim of any reusable resources
- μ¦, OSλ μ’ λ£λ processκ° μμμ μ°¨μ§νμ§ μλλ‘ ν΄μ ν΄μΌ ν¨
Single-threaded
vsMulti-threaded
|ββ|ββ| | Single-threaded | νλμ νλ‘μΈμ€λ νλμ Program Counter λ§ κ°μ§ | | ββββββ- |ν λ²μ ν κ°μ λͺ λ Ήμ΄λ§ μ€ν κ°λ₯ (μμ°¨μ μ€ν) | | Multi-threaded | νλμ νλ‘μΈμ€κ° μ¬λ¬ κ°μ μ€λ λλ₯Ό κ°μ§ | | ββββββ |κ° μ€λ λλ λ 립μ μΈ Program Counterλ₯Ό κ°μ§λ©°, λ³λ ¬ μ€ν κ°λ₯ |Concurrency(λμμ±)
- OSλ μ¬λ¬ κ°μ processλ₯Ό λμμ μ€ν
- μΌλΆ νλ‘μΈμ€λ User process, μΌλΆλ OS process
- Concurrency by Multiplexing
- CPUλ μ¬λ¬ processλ₯Ό λΉ λ₯΄κ² Scheduling(μ ν)νλ©° μ€ν(λμμ μ€ννλ κ²μ²λΌ 보μ΄κ²)
Process Management Activities
- Creating and deleting both user and system processes
- Suspending and resuming processes
- Providing mechanisms for process synchronization(λ°μ΄ν°μ μΌκ΄μ±μ μν΄)
- Providing mechanisms for process communication
- Providing mechanisms for deadlock handling
Memory Management
- To execute a program, all (or part) of the instructions(λͺ λ Ήμ΄) must be in memory
- All (or part) of the data that is needed by the program must be in memory
- Memory management determines what is in memory and when
- Optimizing CPU utilization and computer response to users
β Memory management activities
- memory μ¬μ© μΆμ * Keeping track of which parts of memory are currently being used and by whom
- process κ΄λ¦¬ * Deciding which processes (or parts thereof) and data to move into and out of memory
- memory κ³΅κ° ν λΉ λ° ν΄μ * Allocating and deallocating memory space as needed
File-system Management
- OS provides uniform, logical view of information storage
(μΌκ΄λκ³ λ Όλ¦¬μ μΌλ‘ μ 보λ₯Ό μ μ₯, κ΄λ¦¬) - Abstracts physical properties to logical storage unit - file
- Each medium is controlled by device (ex: disk drive, tape drive)
- Varying properties:
- Access speed
- Capacity
- Data transfer rate
- Access method(sequantial or random)
- Varying properties:
**File-system management**:
- Files usually organized into directories
- Access control: most systems use access control to determine who can access what
- OS activities include:
- Creating and deleting files and directories
- Primitives(κΈ°λ³Έ κΈ°λ₯) to manipulate files and directories
- Mapping files onto secondary storage
- Mapping: μ¬μ©μκ° μ§μ ν νμΌ μ΄λ¦μ μ μ₯μ₯μΉμ μ€μ μμΉλ‘ μ°κ²°ν΄μ£Όλ κ³Όμ
- Backup files onto stable(non-volatile) storage media
Mass-storage management
πWhat is Mass-storage?
- Stores data that cannot fit in main memory or needs to be kept for a long period.
(i.e. Hard disk, SSD, optical disk, magnatic tapes)
β OS management Activities
- Mounting/Unmounting: Connecting and disconnecting storage devices
- Free-space Management: Managing available storage space
- Storage allocation
- Disk scheduling: Optimizing input/output operations
- Partitioning: Dividing disks into separate sections
- Protection
- Optical storage, magnetic tapes are slower but requre management by the OS or applications.
Caching(β)
- Caching is an important concpet applied at multiple levels in a computer(H/W, OS, S/W)
π Principle of Caching
- Temporarily copying data from slower to faster storage(cache) for quicker access
β Caching works
- When accessing data, the system checks the cache first
- If found β Use it directly from cache(fast)
- If not β Copy from slow storage to cache, then use it
π Why need Cache Management
- Cache smaller than storage being cached, so efficient management is key
- Design factors:
- Cache size
- Replacement policy(Which data to remove when the cache is full)
Type of Storage
- lower levels(registers, cache) are faster but smaller, while higher levels(SSD, HDD) are slower but larger
- registers are inside the CPU, extremely fast but small
- cache is close to the CPU, faster than main memory but smaller
- main memory(RAM) holds data during program execution
- SSD is faster than HDD but slower than RAM
- magnetic disk(HDD) is the slowest but offers the largest storage capacity\
Data Migration Process
Data Migration Process
- Multitasking Environment
- The system must always use the most recent data, regardless of where it is stored in the storage hierarchy
- Multiprocessor Environment
- Requires cache coherency(μΌκ΄μ±) to ensure that all CPUs have the most recent data in their cache
- Distributed Environment
- The situation is even more complex
- Multiple copies of the same data can exist, requiring proper management strategies
I/O subsystem
- OS is to hide peculiarities of hardware devices from the user
β Responsibilities of the I/O Subsystem
- Memory Management for I/O:
- Buffering: Temporarily stores data while itβs being transferred
- Caching: Stores parts of data in faster storage for better performance
- Spooling: Manages overlapping of job outputs and inputs by placing I/O data in a buffer
(It refers to putting data of various I/O jobs in a buffer.)
- Provides a General Device-Driver Interface
- Ensures that hardware can communicate with the OS
- Drivers for Specific Hardware Devices
Protection and Security
πProtection
- Mechanisms for controlling access to processes or resources as defined by the OS
πSecurity
- Defense against internal and external attacks Types of attacks include:
- denial-of-service(DoS)
- worms and viruses
- identity Theft
- Theft of Service
- User Identification and Management
- Systems distinguish among users, to determine who can do what
- User ID
- Include usernames and unique IDs(one per user)
- Linked to files and processes for access control(IDλ μ¬μ©μμ fileκ³Ό processμ μ°κ²°λμ΄ access controlλ₯Ό κ²°μ )
- Group ID
- Allow management of user groups for access rights
- Associated with processes and files
- Privilege Escalation(κΆν μμΉ)
- Allows users to switch to an effective ID with higher rights
Virtualization
πWhat is virtualization
- Technology that allows an OS to run applications within other OSes
- β Emulation: Used when the source CPU type is different from the target type (i.e. PowerPC β Intel x86 β M1 / Appleμ Rosetta)
- Generally the slowest method
- If the computer language is not compiled to native code(CPUκ° μ§μ μ€νν μ μλ κΈ°κ³μ΄(λ°μ΄λ리 μ½λ)), it uses interpretation(μμ€ μ½λλ₯Ό ν μ€μ© ν΄μνκ³ μ€ννλ λ°©μ)
β Virtualization
- OS is natively compiled for the CPU, and it runs guest OSes that are also natively compiled Example:
- Running Windows XP guests on VMware, with the host OS being Windows XP.
- VMM (Virtual Machine Manager)
- Software that provides virtualization services (e.g., VMware, VirtualBox).
β Use case of virtualization
- Used for exploring and ensuring compatibility(νΈνμ±) when running multiple OSes Examples:
- Running Mac OS X as the host and Windows as the guest on an Apple laptop
- Developing apps for multiple OSes without owning multiple systems β Performing QA testing
- Executing and managing compute environments within data centers
β Native Execution of VMM
- If VMM runs natively, it acts as the host OS itself
- In this case, there is no general-purpose host OS (ex: VMware ESX, Citrix XenServer) β VMMμμ²΄κ° host
Computing Environment - virtualization
Computing Environment - virtualization
- The VMM manages multiple VMs, and each VM operates independently with its own kernel and processes
- This allows multiple OSes to run simultaneously on a single hardware system.
- VMM = Host OS
κ΅¬λΆ | Computing Environment-Non-virtualized(a) | Computing Environment-Virtualized(b) |
---|---|---|
Kernel | λ¨μΌ 컀λ μ¬μ© | κ° VMμ΄ κ°λ³ 컀λ μ¬μ© |
Process | λ¨μΌ OSμ νλ‘μΈμ€ | κ° VMμ΄ λ 립μ μΈ νλ‘μΈμ€ μ€ν |
Management | νλμ¨μ΄λ₯Ό 컀λμ΄ μ§μ κ΄λ¦¬ | VMMμ΄ νλμ¨μ΄ μμμ κ΄λ¦¬νκ³ VMμ ν λΉ |
Distributed Systems
π Distributed Computing
- A collection of separate, possibly heterogeneous systems that are networked together
- Systems typically communicate using TCP/IP Types of networks:
- π Local Area Network(LAN): Connects computers in a small
- π Wide Area Network(WAN): Covers large geographical areas
- π Metropolitan Area Network(MAN)
- π± Personal Area Network(PAN)
π Network Operating System
- Provides features to manage interactions b/w systems across a network Key features:
- Communication Scheme: Allows systems to exchange messages
- Illusion of a Single System: Users perceive the network as a single system
Computing Environment
Traditional
- stand-alone general purpose machines
- Early computers were stand-alone systems with no internet or network connection
- But blurred as most systems interconnect with others (i.e. the Internet)
- Portals
- Provide **web access to internal systems **
- Network computers(Thin Clients: ν΄λΌμ΄μΈνΈ λ¨μμλ μ΅μνμ μ²λ¦¬λ§ μννκ³ , μ£Όμ μμ
μ μ€μ μλ²μμ μ²λ¦¬)
- Thin clients act like web terminals, depending on central servers for processing and data
- Wireless Networks
- Mobile computers connect with each other using wireless networks
- Networking Becoming Ubiquitous(보νΈν)
- Home systems use firewalls to protect against internet attacks.
β Stand-alone β Connected
Mobile
- Handheld smartphones, tablets, and similar portable devices
- Functional difference from Traditional laptops
- Extra Features: Mobile OS offer more features like GPS and gyroscope
- Allows new types of apps like augmented reality(AR)
- Connectivity
- Using IEEE 802.11 wireless networks(Wi-Fi) or cellular data networks(4G, 5G)
- Leaders
- Apple iOS, Google Andriod
Client-Server
Older dumb terminals(:μλ²μμ μ²λ¦¬λ λ°μ΄ν°λ₯Ό λ¨μν μΆλ ₯) have been replaced by smart PCs
π Now many systems act as servers, handling requests generated by clients = Client-Server Computing
β Types of Servers
- Computer-server system: Provides an interface for clients to request services, such as accessing databases.
- File-server system: Provides an interface for clients to store and retrieve files
Client-Server Connection Structure
Peer-to-Peer(P2P)
π P2P is another type of distributed system where nodes connect directly with each other
P2P
β Key feature of P2P
- No distinction b/w clients and servers
- All nodes are treated as peers
- Each node can act as a client, server, or both depending on the situation
- A node must join the P2P network to participate
β How to Join a P2P Network- Register Service: Nodes register their services with a central lookup service on the network
- Broadcast Request: Nodes broadcast service requests and respond to requests using the discovery protocol(λ€νΈμν¬μμ μλΉμ€λ₯Ό μ°Ύκ³ μνΈ μμ©μ λλ protocol)
- Examples of P2P:
- Napster, Gnutella
- VoIP(Voice over IP): like Skype
Cloud Computing
π Cloud Computing: Delivers computing, storage, and applications as services over a network
- Cloud computing is a logical extension of virtualization
- EX: Amazon EC2 - Provides thousands of servers, millions of virtual machines, and massive storage β **Type of Cloud Computing**: 1. π Public Cloud: Available over the Internet to anyone willing to pay 2. π’ Private Cloud: Operated internally by a company for its own use 3. π Hybrid Cloud: Combines public and private cloud components
β **Cloud Service Models**:
- SaaS(Software as a Service)
- Delivers software applications via the Internet (i.e. word processor(Google Docs, Microsoft Office 365))
- PaaS(Platform as a Service)
- Provides a platform for developers to build and deploy applications (i.e. database server)
- IaaS(Infrastructure as a Service)
- Offers infrastructure resources like servers and storage over the Internet(i.e. storage available for backup use)
- Components of Cloud Computing
- Traditional OSes
- VMMs (Virtual Machine Managers)
- Cloud Management Tools
- Internet connectivity requires security tools like firewalls
- Load Balancers: Distribute traffic across multiple applications(to ensure no single server is overloaded)
Cloud Computing
Real-Time Embedded Systems
π Real-Time(μ€μκ°) Embedded Systems
- Most prevalent form of computers today
Use special-purpose OS designed for specific tasks(Ex: Real-Time OS(RTOS))
- Some systems have OS, while others operate without an OS
β Feature of Real-Time OS(RTOS)
- Well-defined, fixed time constraints for processing
- Processing must be completed within the specified time(Failure to meet deadlines results in system errors)
- Correct operation only if constraints met