Post

[OS] Operating System(2-1): Service, Interface, System calls, Link/Loaders

[OS] Operating System(2-1): Service, Interface, System calls, Link/Loaders

๐Ÿ€ ์šด์˜์ฒด์ œ ์ „๊ณต ์ˆ˜์—… ์ •๋ฆฌ

Operating System Services


๐Ÿ“š OS Provide an environment for the execution of programs and services to programs and users

  • Helpful Services to Users
    1. UI(User Interface)
      • Almost all OSes provide a user interface
      • Types of UI:
      1. Command-Line interface(CLI)
      2. Graphics User interface(GUI)
      3. touch-screen
      4. Batch: ์ผ๊ด„ ์ฒ˜๋ฆฌ ๋ฐฉ์‹
    2. Program execution
      • OS must be able to load programs into memory, run them, and terminate them
      • termination can be normal or abnormal(indicating error)
    3. I/O operations
      • Running programs may require I/O operations(Ex: File access, I/O device control)
    4. File-system manipulation
      • OS provides file management services for programs
      • Key function:
      • Reading/Writing files and directories
      • Creating and deleting files
      • Searching and listing file information
      • Managing file permissions
    5. Communication
      • Processes exchange information either on the same computer or over a network
      • Communication methods:
      1. Shared Memory: Multiple processes share a common memory space to communicate
      2. Message Passing: The OS moves packets to facilitate communication(ex: email)
    6. Error detection
      • The OS must continuously monitor and detect errors in the system
      • OS ์—ญํ• :
      • ์˜ค๋ฅ˜ ๊ฐ์ง€ ํ›„ ์ ์ ˆํ•œ ์กฐ์น˜ ์ˆ˜ํ–‰
      • ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ด๋„ ์‹œ์Šคํ…œ์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์œ ์ง€๋˜๋„๋ก ๋ณด์žฅ
      • ๋””๋ฒ„๊น… ๊ธฐ๋Šฅ ์ œ๊ณต: ์‚ฌ์šฉ์ž ๋ฐ ๊ฐœ๋ฐœ์ž์˜ ๋ฌธ์ œ ํ•ด๊ฒฐ ๋Šฅ๋ ฅ ํ–ฅ์ƒ
    7. Resource allocation
      • ์—ฌ๋Ÿฌ ์‚ฌ์šฉ์ž ํ˜น์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๋งŽ์€ ํ”„๋กœ๊ทธ๋žจ์ด๋‚˜ ์žฅ์น˜๋ฅผ ๋™์‹œ์— ๋Œ๋ฆด ๋•Œ, ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค๋Š” ํ•œ์ •์ ์ž„
      • ๊ทธ๋ž˜์„œ ์‹œ์Šคํ…œ ๋ฆฌ์†Œ์Šค๋ฅผ ์ ์ ˆํ•˜๊ฒŒ ํ• ๋‹นํ•ด์•ผํ•จ
      • Key resources managed by the OS:
      • CPU cycle: CPU๋ฅผ ์ตœ๋Œ€ํ•œ ๋ฐฐ๋ถ„ํ•ด์„œ GPU์˜ ํ™œ์šฉ๋ฅ ์„ ๋†’์—ฌ์•ผํ•จ
      • main memory
      • file storage
      • I/O device
    8. Logging
      • Tracks which users consume how many resources
      • Helps optimize system performance and security
    9. Protection and security
      • ๋ฉ€ํ‹ฐ์œ ์ € ์‹œ์Šคํ…œ ๋ฐ ๋„คํŠธ์›Œํฌ ํ™˜๊ฒฝ์—์„œ ์ •๋ณด ์†Œ์œ ์ž๊ฐ€ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ์„ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณด์žฅ
      • ๋™์‹œ์— ์‹คํ–‰๋˜๋Š” ํ”„๋กœ์„ธ์Šค๋“ค์ด ์„œ๋กœ ๊ฐ„์„ญํ•˜์ง€ ์•Š๋„๋ก ๋ณดํ˜ธ
      • protection๊ณผ security๋Š” ๋‹ค๋ฅธ ๊ฐœ๋…
      • protection: Ensures controlled access to system resources
      • security:
        • Protects the system from unauthorized access(requires user authentication)
        • Defends I/O devices from unauthorized access attempts
        • alt text

          View of Operating_System_Service

User and Operating System-Interface


CLI(Command Line Interface)


๐Ÿ“š CLI or Command interpreter: ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ๋ช…๋ น์„ ์ž…๋ ฅํ•˜์—ฌ ์šด์˜์ฒด์ œ์™€ ์ƒํ˜ธ์ž‘์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ์ธํ„ฐํŽ˜์ด์Šค

  • ์ปค๋„ ๋‚ด๋ถ€์—์„œ ๊ตฌํ˜„๋  ์ˆ˜๋„ ์žˆ๊ณ , ์‹œ์Šคํ…œ ํ”„๋กœ๊ทธ๋žจ์œผ๋กœ ๊ตฌํ˜„๋  ์ˆ˜๋„ ์žˆ์Œ.
  • CLI๋Š” ์—ฌ๋Ÿฌ ํ˜•ํƒœ๋กœ ๊ตฌํ˜„๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ Shells์ด๋ผ๊ณ  ํ•จ.
  • Types of CLI Commands:
    • Built-in Commands(๋‚ด์žฅ ๋ช…๋ น์–ด)
      • Commands that are part of the shell itself(Ex: cd, echo, exit)
    • Externel programs(์™ธ๋ถ€ ํ”„๋กœ๊ทธ๋žจ ํ˜ธ์ถœ)
      • The shell executes external programs(Ex: ls, grep, vim)
      • Adding new features does not require modifying the shell

GUI(Graphical User Interface)


๐Ÿ“š GUI: A desktop metaphor interface, designed for user-friendly interaction

  • ๋ณดํ†ต ๋งˆ์šฐ์Šค, ํ‚ค๋ณด๋“œ, ๋ชจ๋‹ˆํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์กฐ์ž‘
  • GUI Components:
    • Icons: Represent files, programs, and actions
    • Mouse interactions: Provide Options, execute functions, open folders, etc
  • Invented at Xerox PARC
  • Modern systems offer **both CLI and GUI**
  • Example:
    • Microsoft Windows โ†’ Primarily GUI, but includes CLI
    • Apple Mac OS X โ†’ Uses Aqua GUI, but supports CLI with UNIX shell
    • Unix and Linux โ†’ Primarily CLI, but support GUI options like CDE, KDE, and GNOME
  • ์ฃผ์š” GUI ํ™˜๊ฒฝ:
    1. KDE(K Desktop Environment) โ†’ Linux ๊ธฐ๋ฐ˜์˜ ๋ฐ์Šคํฌํ†ฑ ํ™˜๊ฒฝ.
    2. GNOME(Gnu Network Object Model Environment) โ†’ Linux ๋ฐ Unix ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉ๋˜๋Š” GUI ํ™˜๊ฒฝ, ๋ฆฌ๋ˆ…์Šค์˜ Graphical User Interface๋Š” GNOME
    3. CDE(Common Desktop Environment) โ†’ LUnix ์‹œ์Šคํ…œ์—์„œ ์‚ฌ์šฉ๋˜๋Š” GUI ํ™˜๊ฒฝ

Touchscreen Interface


  • Touchscreen devices require new interfaces
    • Mouse not possible or not desired
    • Actions and selection based on gestures
    • Virtual keyboard for text entry

System Calls(โญ)


๐Ÿ“š System Calls:

  • **Programming interface** to access services provided by the OS
  • Typically written in high-level languages like C or C++
  • Programs do not use direct system calls
  • Instead, they access system services through high-level API(Application Programming Interface)
  • Common API Types: Win32 API(for Windows), POSIX API(for UNIX, Linux, macOS ๋“ฑ์˜ POSIX-baseed system), JAVA API(for Java Virtual Machine(JVM))

alt text

System call sequence to copy the contents of one file to another file

alt text

Example of Standard API read()

System Call Implementation


  • ๊ฐ ์‹œ์Šคํ…œ ํ˜ธ์ถœ์€ ํŠน์ • ์ˆซ์ž์™€ ์—ฐ๊ด€๋จ
  • System-call interface maintains a table indexed by these number
  • Role of system call interface
    • System call interface invokes(ํ˜ธ์ถœ) the intended system call in the OS kernel
    • Returns the status of the system call and any return values
  • Caller Does Not Need to Know Implementation
    • The caller need know nothing about how the system call is implemented
    • It only needs to follow the API and understand the expected results
    • Most OS interface details are hidden from the programmer by API(information encapsulation/์ •๋ณด ์€๋‹‰ํ™”)
    • System calls are managed by run-time support library(์ปดํŒŒ์ผ๋Ÿฌ์™€ ํ•จ๊ป˜ ์ œ๊ณต๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ)

alt text

open() ์‹œ์Šคํ…œ ์ฝœ์„ ์š”์ฒญํ•˜๋ฉด ๋ฒˆํ˜ธ์— ๋”ฐ๋ผ์„œ table์— mapping์„ ํ•œ๋‹ค
๊ทธ๋ฆฌ๊ณ  ๊ทธ ์ธ๋ฑ์Šค์— ์žˆ๋Š” ์ฃผ์†Œ๊ฐ’์„ ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ณ  ๋ฆฌํ„ด์„ ํ•ด์ค€๋‹ค

System Call Parameter Passing


  • System Calls often require more information
  • Exact type and number of parameters vary depending on OS and system call

  • Three Methods for Passing Parameters to the OS
    • (1) Registers
      • register์— parameter๋ฅผ ์ €์žฅํ•˜์—ฌ ์ „๋‹ฌ, ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๊ณ  ๋น ๋ฆ„(CPU๊ฐ€ ๊ฐ€์žฅ ๋นจ๋ฆฌ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ)
      • table์ด๋‚˜ block ๊ฐ™์€ ํฐ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๊ธฐ์—๋Š” register ์šฉ๋Ÿ‰์˜ ํ•œ๊ณ„๊ฐ€ ์žˆ์Œ
    • (2) Address of Block/Table
      • Parameters are stored in a block(or table) in memory
      • The **address** of the block is passed in a register (Call by reference of C/C++)
      • Used by Linux and Solaris
    • (3) Stack
      • Parameters are pushed onto the stack by the program
      • The OS pops them from the stack to retrieve the values
    • Block and stack methods do not limit the number or length of parameters

alt text

1๋ฒˆ์งธ ๋ผ์ธ์€ register, 2๋ฒˆ์งธ๋Š” x์ฃผ์†Œ์˜ table์„ passingํ•œ ๋ผ์ธ

Types of System Calls


Process control

  • create/terminate process
  • end, abort
  • load, execute
  • get/set process attributes
  • wait for time
  • wait event, signal event
  • allocate and free memory
  • Dump memory error
  • Debugger for determining bugs, single step execution
  • Locks for managing access to shared data b/w processes
    • ๋‹ค์ค‘ ํ”„๋กœ์„ธ์Šค ํ™˜๊ฒฝ์—์„œ ๊ณต์œ  ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ๋™์‹œ ์ ‘๊ทผ์„ ๋ฐฉ์ง€(Lock)
    • ์—ฌ๋Ÿฌ process๊ฐ€ ๊ฐ™์€ ๋ฐ์ดํ„ฐ์— read/write๋ฅผ ํ•œ๋‹ค๋ฉด ๋ฐ์ดํ„ฐ๊ฐ€ ์—‰ํ‚ค๊ธฐ๋•Œ๋ฌธ

File management

  • Device management์˜ ์ถ”์ƒํ™”(์ƒ์œ„ ๊ฐœ๋…)
  • Create/delete file
  • open/close file
  • read, write, reposition
  • get and set file attributes

Device management

  • request/release device
  • read, write, reposition
  • get and set device attributes
  • logically attach or detach devices

Information maintenance

  • get/set time or date
  • get/set system data
  • get and set process, file, or device attributes

Communications

  • create, delete communication connection
  • send, receive messages
    • message passing model: to send messages to a host name or process name(Ex: client โ†’ server)
    • Shared-memory model: Allows processes to create and access shared memory
  • transfer status information
  • attach and detach remote(์›๊ฒฉ) devices

Protection

  • Control access to resources
  • get and set permissions
  • allow and deny user access
  • alt text

alt text

printf๋ฅผ ์“ฐ๊ฒŒ ๋˜๋ฉด I/O๊ฐ€ ๋ฐœ์ƒ๋˜์–ด OS service๋ฅผ ๋ฐ›๊ฒŒ ๋จ printf์˜ write๋ผ๋Š” system call์„ ์‚ฌ์šฉํ•จ (์ง์ ‘ write๋ฅผ ์“ฐ๋ ค๋ฉด fd, buf๋“ฑ์„ ์ง์ ‘ ์ง€์ •ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒˆ๊ฑฐ๋กœ์›€)

System Services(=System Utilities)


๐Ÿ“šOS๋Š” System Programs(=System Utilities)์„ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•˜์—ฌ ํŽธ๋ฆฌํ•œ ์‹คํ–‰ ํ™˜๊ฒฝ(convenient environment)์„ ์กฐ์„ฑํ•จ

  • ๋Œ€๋ถ€๋ถ„์˜ ์œ ์ €๋“ค์€ OS๋ฅผ system call์ด ์•„๋‹Œ system programs๋กœ ์ •์˜๋œ๋‹ค.
  1. File manipulation
    • Create, delete, copy, rename, print, dump, and list files
  2. Status Information
    • Retrieve system info(date, time, memory, disk space, users)
    • Performance monitoring, logging, debugging
    • Uses registry to store and retrieve configuration information(์„ค์ • ์ •๋ณด)
  3. File Modification
    • Provide Text editors to create and modify files
    • Commands to search and transform text content
  4. Programming-Language Support
    • Includes compilers, assemblers, debuggers, interpreters
  5. Program Loading and Execution
    • Uses loaders, linkage editors, and debugging systems
  6. Communications
    • Provides virtual connections among processes, users, and systems
    • Enables messaging, remote login, and file transfers
  7. Background Services
    • ์‹œ์Šคํ…œ ๋ถ€ํŒ… ์‹œ ์ž๋™์œผ๋กœ ์‹คํ–‰๋จ
    • ์ผ๋ถ€ ์„œ๋น„์Šค๋Š” ์‹œ์Šคํ…œ ์‹œ์ž‘ ํ›„ ์ข…๋ฃŒ๋˜๋ฉฐ, ์ผ๋ถ€๋Š” ๊ณ„์† ์‹คํ–‰๋จ
    • Includes disk checking, process scheduling, error logging, and printing
    • Runs in user context, not kernel context(์ปค๋„ exec โ†’ background service exec)
    • Known as services, subsystems, daemons
  8. Application Programs
    • User-executed programs that are not part of the OS
    • Launched via command-line, mouse clicks, or other user interactions

Linkers and Loaders (โญ)


Linkers


  • Source code is compiled into relocatable object files
    • relocatable object file: ์ ˆ๋Œ€ ์ฃผ์†Œ๊ฐ’์ด ์•„๋‹ˆ๋ผ ์ƒ๋Œ€ ์ฃผ์†Œ/์‹ฌ๋ณผ๋ง ์ฃผ์†Œ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์–ด๋А ๋ฉ”๋ชจ๋ฆฌ์—๋‚˜ ์žฌ๋ฐฐ์น˜๊ฐ€ ๊ฐ€๋Šฅํ•œ object file
  • Linker combines multiple object files into a single executable file
  • Also includes libraries(โ€˜s code) if necessary

Loaders


  • Executable file is stored in secondary storage
  • ์‹คํ–‰์„ ์œ„ํ•ด ๋ฐ˜๋“œ์‹œ loader๊ฐ€ memory์— ์ ์žฌํ•ด์•ผ ํ•จ
  • memory์— ์ ์žฌํ•˜๊ธฐ ์œ„ํ•ด relocation๊ณผ์ •์—์„œ program์˜ final addresses๋ฅผ assignํ•˜๊ณ , ๊ทธ address์— ๋งž๊ฒŒ code์™€ data๋ฅผ ์ˆ˜์ •ํ•จ

  • Dynamically Linked Libraries(DLLs)
    • ํ”„๋กœ๊ทธ๋žจ๋“ค์€ ๊ฑฐ์˜ ๋‹ค ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•จ
    • ํ”„๋กœ๊ทธ๋žจ๋งˆ๋‹ค ํ‘œ์ค€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋น„ํšจ์œจ์„ ์—†์• ๊ธฐ ์œ„ํ•ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ shareํ•˜๊ธฐ๋กœ ํ•จ
    • Modern OSs donโ€™t embed libraries into executables
    • DLLs๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ **ํ•„์š”ํ•  ๋•Œ๋งŒ ์ ์žฌ**ํ•˜๊ณ , ์—ฌ๋Ÿฌ ํ”„๋กœ๊ทธ๋žจ์—์„œ **shared**
  • The OS knows how to load and execute programs based on standard formats(ํ‘œ์ค€ ์‹คํ–‰ ํŒŒ์ผ ํ˜•์‹)

alt text

link and loaderโ€™s role

โœ… Why Applications Are Operating System Specific

  • A program compiled on one OS usually does not run on another
  • Each OS has unique system calls and file formats ๊ทธ๋Ÿผ OS ๊ด€๊ณ„์—†์ด ๋Œ์•„๊ฐ€๋Š” ํ”„๋กœ๊ทธ๋žจ์€ ์—†๋Š”๊ฐ€?
  • Multi-Operating System Apps
    • interpreted languages(e.g., Python, Ruby)
    • VM-based languages(e.g., Java)
    • standard languages(e.g., C) and compile separately for each OS
  • Application Binary Interface(ABI)
    • API์ฒ˜๋Ÿผ CPU ๋ฐ OS ํ™˜๊ฒฝ์—์„œ binary code๊ฐ€ interactํ•˜๋Š” ๋ฐฉ์‹์„ ์ •์˜
This post is licensed under CC BY 4.0 by the author.