[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
- UI(User Interface)
- Almost all OSes provide a user interface
- Types of UI:
- Command-Line interface(CLI)
- Graphics User interface(GUI)
- touch-screen
- Batch: ์ผ๊ด ์ฒ๋ฆฌ ๋ฐฉ์
- Program execution
- OS must be able to load programs into memory, run them, and terminate them
- termination can be normal or abnormal(indicating error)
- I/O operations
- Running programs may require I/O operations(Ex: File access, I/O device control)
- 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
- Communication
- Processes exchange information either on the same computer or over a network
- Communication methods:
- Shared Memory: Multiple processes share a common memory space to communicate
- Message Passing: The OS moves packets to facilitate communication(ex: email)
- Error detection
- The OS must continuously monitor and detect errors in the system
- OS ์ญํ :
- ์ค๋ฅ ๊ฐ์ง ํ ์ ์ ํ ์กฐ์น ์ํ
- ์ค๋ฅ๊ฐ ๋ฐ์ํด๋ ์์คํ ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ ์ง๋๋๋ก ๋ณด์ฅ
- ๋๋ฒ๊น ๊ธฐ๋ฅ ์ ๊ณต: ์ฌ์ฉ์ ๋ฐ ๊ฐ๋ฐ์์ ๋ฌธ์ ํด๊ฒฐ ๋ฅ๋ ฅ ํฅ์
- Resource allocation
- ์ฌ๋ฌ ์ฌ์ฉ์ ํน์ ์ฌ๋ฌ ๊ฐ์ ๋ง์ ํ๋ก๊ทธ๋จ์ด๋ ์ฅ์น๋ฅผ ๋์์ ๋๋ฆด ๋, ์์คํ ๋ฆฌ์์ค๋ ํ์ ์ ์
- ๊ทธ๋์ ์์คํ ๋ฆฌ์์ค๋ฅผ ์ ์ ํ๊ฒ ํ ๋นํด์ผํจ
- Key resources managed by the OS:
- CPU cycle: CPU๋ฅผ ์ต๋ํ ๋ฐฐ๋ถํด์ GPU์ ํ์ฉ๋ฅ ์ ๋์ฌ์ผํจ
- main memory
- file storage
- I/O device
- Logging
- Tracks which users consume how many resources
- Helps optimize system performance and security
- Protection and security
- ๋ฉํฐ์ ์ ์์คํ ๋ฐ ๋คํธ์ํฌ ํ๊ฒฝ์์ ์ ๋ณด ์์ ์๊ฐ ๋ฐ์ดํฐ ์ฌ์ฉ์ ์ ์ดํ ์ ์๋๋ก ๋ณด์ฅ
- ๋์์ ์คํ๋๋ ํ๋ก์ธ์ค๋ค์ด ์๋ก ๊ฐ์ญํ์ง ์๋๋ก ๋ณดํธ
- protection๊ณผ security๋ ๋ค๋ฅธ ๊ฐ๋
- UI(User Interface)
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
)
- Commands that are part of the shell itself(Ex:
- Externel programs(์ธ๋ถ ํ๋ก๊ทธ๋จ ํธ์ถ)
- The shell executes external programs(Ex:
ls
,grep
,vim
) - Adding new features does not require modifying the shell
- The shell executes external programs(Ex:
- Built-in Commands(๋ด์ฅ ๋ช
๋ น์ด)
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 ํ๊ฒฝ:
- KDE(K Desktop Environment) โ Linux ๊ธฐ๋ฐ์ ๋ฐ์คํฌํฑ ํ๊ฒฝ.
- GNOME(Gnu Network Object Model Environment) โ Linux ๋ฐ Unix ์์คํ
์์ ์ฌ์ฉ๋๋ GUI ํ๊ฒฝ, ๋ฆฌ๋
์ค์ Graphical User Interface๋
GNOME
- 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))
System call sequence to copy the contents of one file to another file
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(์ปดํ์ผ๋ฌ์ ํจ๊ป ์ ๊ณต๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ)
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
- (1) Registers
1๋ฒ์งธ ๋ผ์ธ์ register, 2๋ฒ์งธ๋ x์ฃผ์์ table์ passingํ ๋ผ์ธ
Types of System Calls
Process control
create
/terminate
processend
,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
fileopen
/close
fileread
,write
,reposition
get
andset
file attributes
Device management
request
/release
deviceread
,write
,reposition
get
andset
device attributes- logically
attach
ordetach
devices
Information maintenance
get
/set
time or dateget
/set
system dataget
andset
process, file, or device attributes
Communications
create
,delete
communication connectionsend
,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
anddetach
remote(์๊ฒฉ) devices
Protection
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
๋ก ์ ์๋๋ค.
- File manipulation
Create
,delete
,copy
,rename
,print
,dump
, andlist
files
- Status Information
- Retrieve system info(date, time, memory, disk space, users)
- Performance monitoring, logging, debugging
- Uses registry to store and retrieve configuration information(์ค์ ์ ๋ณด)
- File Modification
- Provide Text editors to create and modify files
- Commands to
search
andtransform
text content
- Programming-Language Support
- Includes
compilers
,assemblers
,debuggers
,interpreters
- Includes
- Program Loading and Execution
- Uses loaders, linkage editors, and debugging systems
- Communications
- Provides virtual connections among processes, users, and systems
- Enables messaging, remote login, and file transfers
- 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
- 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(ํ์ค ์คํ ํ์ผ ํ์)
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
- interpreted languages(e.g.,
- Application Binary Interface(ABI)
- API์ฒ๋ผ CPU ๋ฐ OS ํ๊ฒฝ์์ binary code๊ฐ interactํ๋ ๋ฐฉ์์ ์ ์