[ OS ] 02. Operating System Structures

38A·2023년 4월 8일
1

Operating System

목록 보기
2/14
post-thumbnail

🖥️ Operating-system services

Operating-System User Interface

  • Command-line interpreter (CLI)
    - Get and execute user-specified command
    • Ex) UNIX shell, MS-DOS Prompt
  • Graphical user interface (GUI)
    - Mouse-based windows-and-menu system → Desktop metaphor, icon, folder, ...
    - History
    • Xerox Alto computer (1973)
    • Apple Macintosh (1980s)
    • MS-Windows
    • Desktops based on X-window (CDE, KDE, GNOME)

Programming Interfaces

  • System calls → S/W Interrupt 2가지중 하나
    - Primitive programming interface provided through interrupt
    - System-call interface

    • Connection between program language(C언어 껍데기) and OS
      Ex) implementations of open(), close(), ...
  • Example) POSIX I/O system calls (declared in unistd.h)
    int open(const char pathname, int flags, mode_t mode); → 이용해서 fopen() 구현
    int close(int fd);
    ssize_t read(int fd, void
    buf, size_t count);
    ssize_t write(int fd, const void *buf, size_t count);
    // size_t: unsigned int, ssize_t: signed int
    ➡️ OS 고급기능은 C에는 X, UNIX system call에는 O

  • System calls: the mechanism used by an application program to request service from OS kernel
    - “Function calls to OS kernel available through interrupt : user mode → kernel mode
    - Generally, provided as interrupt handlers written in C/C++ or assembly.
    - A mechanism to transfer control safely from lesser privilege modes to higher privileged modes.
    Ex) POSIX system calls: open, close, read, write, fork, kill, wait, ...!
    → Interrupt handler와 Sytemcall handler는 약간 다름
    : Interrput handler가 처리할때 Systemcall handler를 호출

Parameter Passing in System Call

  • Internally, system call is serviced through interrupt
    - Additional information can be necessary
  • Parameter passing methods
    - Register (simple information : 정보의 양이 작을 때)
    - Address of block (large information : 정보의 양이 클 때) → 주소를 레지스터에 저장
    - System stack

Types of System Calls

  • Process control
  • File management
  • Device management
  • Information maintenance(유지)
  • Communication

Example

System-Call Interface

  • How to invoke(호출) system calls in high-level language?
    Ex) int open(const char *path, int oflag);
  • System-call interface: link between runtime support system of programming language and OS system calls
    - Implementation of I/O functions available in programming language (ex: glibc, MS libc, ...)
  • Example of system-call interface in Linux
  • Typically(일반적으로), a number is associated(연결되다) with each system call
    c.f. IRQ of system call: 0x80 on Linux, 0x21 on DOS/Windows
    - System-call interface maintains(유지) a table indexed according to these numbers
  • The system call interface invokes intended(의도된) system call in OS kernel and returns status of the system call and any return values.
  • The caller needs to know nothing about how the system call is implemented
    - Just needs to obey(준수) API and understand what OS will do as a result call
    - Most details of OS interface hidden from programmer by API
    • Managed by run-time support library (set of functions built into libraries included with compiler)
  • What does system-call interface do?
    - Passing information to the kernel
    - Switch to kernel mode
    - Any data processing and preparation for execution in kernel mode
  • Cf. System call vs. I/O functions in programming language
    Ex) read(), vs. fread()
    - read(): provided by OS
    - fread(): standard function defined in C language (호환성)
    • fread() is implemented using read()

Examples of System Calls

Application Programming Interface

  • API: interface that a computer system (OS), library or application provides to allow requests for service
    : system call보다 좀 더 큰 단위의 function으로 구성
    - A set of functions, parameters, return values available to application programmers.
    Ex) Win32 API, POSIX API, etc. → MessageBox(..), CreateWindow(...), ...
    - Can be strongly correlated(상관) to system calls
    Ex) POSIX API ~ UNIX system calls
    - Can provide high-level features(기능) implemented with system calls
    Ex) Win32 API is based on system calls
    Ex) POSIX thread library API
    in window OS : API가 호환성⬆️, Linux는 비슷

Process Control: Load / Execution

  • A program can load/execute another program.
    Ex) CLI, Windows Explorer, MacOS Finder
  • While, the parent program can
    - Be lost (replaced by the child program)
    - Be paused
    - Continue execution: multi-programming / multitasking
    • Create process / submit job

Example: FreeBSD UNIX

  • Command interpreter may continue to execute
  • Two cases of parent’s execution
  1. Case 1, continue to execution → nothing
    • New program is executed in background
      • Console input is impossible
  2. Case 2, wait the child → wait()
    • New process takes I/O access
    • When the process terminates (exit()), the control is returned to parent (e.g. shell) with a status code (0 or error code)
  • fork() : return value is pid == 0 is child, > 0 is parent, < 0 is error
  • exec() family functions
    - execlp : Ex execlp("ls", "ls", "-al", "/tmp", NULL);
    - execvp : Ex
    execvp(argv[0], argv);
  • wait() : child 종료시까지 대기, return child pid < 0 is error
  • Controlling new process
    - Get / set process attributes
    - Priority, maximum execution time, ...
    • Terminate process (other user Process는 죽일수 x)
  • Waiting for new job / process
    - Wait for a fixed period of time(정해진 시간 동안)
    - Wait for event / signal event (timer, mouse ..)
  • Debugging
    - Dump
    - Trace: trap after every instruction

Process Control: Termination

  • Normal termination (end) exit()
    - Deallocate resources, information about current process
  • Abnormal(비정상) termination (abort) abort()
    - Dump memory into a file for debugging and analysis
    ➡️ Dump memory : 컴퓨터 메모리의 내용을 파일로 저장하는 것을 의미. 일반적으로 디버깅 용도로 사용, 프로그램이 크래시나 다른 이슈를 일으키는 경우에 메모리 덤프 파일을 분석하여 문제의 원인을 파악하고 해결하는 데 도움. 메모리 덤프 파일은 일반적으로 텍스트 파일이 아니라 이진 파일로 저장되며, 다양한 도구를 사용하여 분석할 수 있습니다.
    - Ask user how to handle ( EX_ 메모리 주소가 잘못된 경우 )

File Management

  • Create / delete files
  • Read / write / reposition
  • Get / set file attribute
  • Directory operation
  • More service file
    - move, copy, ...
    ➔ Functions can be provided by either system calls, APIs, or system (독립적인)programs

Device Management

  • Resources
    - Physical device (disk, tape, ...)
    - Abstract / virtual device (file, ...)
  • Operations
    - Request for exclusive(독점) use → open()
    - Read, write, reposition → read(), write()
    - Release → close()
  • Combined file-device structure
    - Mapping I/O into a special file
    - The same set of system calls on both files and devices
    - Device에 따라 여러가지 version → Device driver가 제공

Information Maintenance ( 유지 )

  • Transfer information between OS and user program
    - Current time, date
    - Information about system
    - # of current user, OS version, amount of free memory / disk space
  • OS keeps information about all it processes
    Ex) /proc of Linux → CPU info, Memstate kernel 속에 있는 데이터 (variable)

System Programs

  • System program: a program to provide a convenient environment(user mode에서만 돌아감) for program development and execution. → User Application
    Ex_ shell, 윈도우 익스플로러, 맥 파인더

🖥️ Components and their interconnections

Operating-System Structure

  • General-purpose OS is very large program
  • Various ways to structure ones
    - Monolithic(단일) structure - MS-DOS, original UNIX, Linux
    - Layered – an abstraction
    - Microkernel – Mach

Simple Structure

  • MS-DOS (1981) → Simple user, single task
    - Started as small, simple limited system
    → Provide most functionality(기능) in least(최소한의) space
    - Interface / level of functionality are not well separated
    • No dual mode(하는일이 별로 없어서) or H/W protection
    • Application program can access I/O directly
    • Vulnerable(취약) to errant(잘못된) program
      • An error in a program can crash all system
    • Limited on specific(특정) H/W

Monolithic(단일) Structure

  • Monolithic kernel
    - Consists of everything below(아래) the system-call interface and above(위) the physical hardware
    - File system, CPU scheduling, memory management, and other operating-system functions; a large number of functions for one level
    - Fast!
  • Ex) Original UNIX(1973)
    - Also limited by H/W functionality
    - Systems programs
    → Shell, commands compiler, interpreter, system library, ...
  • Ex) Linux (1991)

Layered Approach

  • OS composed(구성) of layers

  • Layer
    - Implementation of abstract objects and operation
    - Each layer M can invoke lower-level layers
    - Each layer M can be invoked by higher-level layers

  • Each layer uses functions / services of only lower-level layers

  • Advantages of layered approach: simple to construct(개발) and debug
    - If we develop from lower-level layer to higher-level layer, we can concentrate on only current layer at each stage
    - A layer doesn’t need to know detail of lower-level layer

  • Difficulties of layered approach
    - Defining various layers needs careful planning- How to define hierarchy between the modules requires each other- Inefficiency(비효율)

    • Repeating calls(반복호출) to lower-level layers
  • Remedy(해결책)
    - Apply fewer(더 적은) layers - Take advantage and avoid difficulties

Microkernels

  • Smaller kernel → 최대한 kernel을 작게
  • All unessential(불필요한) components are not implemented in kernel but as system/user-level programs
    • Only essential components are included in kernel
    • Other components are provided by system / user programs
  • Generally, process / memory management, communication facility(기능) are in the kernel.
  • System calls are provided through message passing
    - Clients and services are running in user space
    - Kernel provides only a message passing facility between client and server
  • Advantages of microkernel → kernel 양이 작아서 문제가 생길 확율이 작음 (안전성이 높음)
    - Ease of extending(확장)
    - Ease to port
    - Security and reliability(신뢰성)
    • Most services are on user space
  • Disadvantages
    - Performance decrease due to(~로 인한) increased system function overhead.

Modules (Kernel Module)

  • Loadable kernel modules (LKM)
    - Uses object-oriented approach
    - Each core(핵심) component(구성요소) is separated
    - Each talks to the others over known(잘 알려진) interfaces(를 통해)
    - Each is loadable as needed within the kernel
    Ex) Linux, Solaris, etc.
    • 사용하는 module만 끼웠다 뺐다할 수 있다
    • flexible : 실행 중에도 빠르다
  • Advantages
    - Provides core services
    - Allows certain features to be implemented dynamically
  • Comparison with layered structure
    - More flexible (any module can any other modules)
  • Comparison with microkernel- Each module can run in kernel mode
    - Modules don’t need to invoke message passing
    - 약간 위험

Hybrid Systems

  • Most modern operating systems are actually not one pure model
    - Hybrid combines multiple approaches to address performance, security, usability(유용성) needs
    - Linux and Solaris kernels in kernel address space, so monolithic, plus modular for dynamic loading of functionality
    - Windows mostly monolithic, plus microkernel for different subsystem personalities
  • Apple Mac OS X hybrid, layered, Aqua UI plus Cocoa programming environment
    - Below is kernel consisting of Mach microkernel and BSD Unix parts, plus I/O kit and dynamically loadable modules (called kernel extensions)

MacOS, iOS

  • User experience(경험) layer
    - Defines the software interface that allows users to interact with the computing devices.
    - Aqua UI (MacOS), Springboard UI (iOS)
  • Application frameworks layer
    - Provide an API for the Objective-C and Swift programming languages
    - Cocoa (MacOS), Cocoa Touch (iOS) frameworks
  • Core frameworks
    - Defines frameworks that support graphics and media including Quicktime and OpenGL
  • Kernel environment (Darwin): hybrid structure
    - A layered system that consists primarily(주로) of the Mach microkernel and the BSD UNIX kernel

Android

  • Android Run-Time (ART)
    - Ahead-of-time (AOT) compilation
  • Java native interface (JNI)
  • Native libraries
  • H/W abstraction layer (HAL)
    - Consistent view independent of specific H/W
  • Bionic: standard C library for Android
    - Android version of glibc

🖥️ Virtual Machines

  • Virtual machine: software that creates a virtualized environment (machine) between the computer platform and its operating system, so that the end user can operate(작동) software on an abstract machine
  • Abstract H/W of single computer into several different execution environment
    - A number of different identical execution environments(여러가지 동일한 실행환경) on a single computer, each of which exactly emulates the host computer
  • Implementation problems
    - Exact duplication of underlying machine requires much work
    - Support for dual mode operation: virtual dual mode
    Cf. VM S/W can run in kernel mode, but VM itself is executed in user mode
    • Virtual user mode / virtual kernel mode
      - System call from virtual user mode is simulated by VM monitor
    • Many CPUs support more than two privilege levels
  • Each process seems to have its own CPU and memory
    - CPU scheduling + virtual memory technologies
    • Virtual memory allows software to run in a memory address space whose size and addressing are not necessarily tied to the computer's physical(실제) memory
  • Major difficulty: disk space
    - It is impossible to allocate same disk drive to each virtual machine
    - Solution: virtual disks (minidisks)
    • Identical(동일) in all respects(부분) except size
  • Benefits of VM
    - Complete protection of various system resources (외부와 단절)
    cf. Sharing between VM’s
    • Shared minidisk
    • Virtual network connection
  • Perfect vehicle for operating-systems research, development, and education
    - Changing OS is dangerous -> test is very important
    - Working on VM, system programmer don’t have to stop physical machine
  • Inevitable(불가피한) differences from host system
    - Disk size
    - Execution time
    • Multiprogramming among many VM’s can slow down VM’s in unpredictable ways
    • Privileged instructions on VM are slow because they are simulated
    • Virtual I/O can be faster (spooling) or slower (interpreted)

HGU 전산전자공학부 김인중 교수님의 23-1 운영체제 수업을 듣고 작성한 포스트이며, 첨부한 모든 사진은 교수님 수업 PPT의 사진 원본에 필기를 한 수정본입니다.

profile
HGU - 개인 공부 기록용 블로그

0개의 댓글