본문 바로가기
Study/운영체제

2. Operating System Structures - Interfaces for users and programmers

by 이미뇨 2023. 4. 11.

1.Programming Interfaces

System calls :

  • interrupt를 통해 제공되는 Primitive programming interface(원시 프로그래밍 인터페이스) 
  • System-call interface : program language - OS 연결
    • Ex) open(), close(),의 구현
Example) POSIX I/O 시스템 호출 (declared in unistd.h)

int open(const char *pathname, int flags, mode_t mode);
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 kernel에서 서비스를 요청하기 위해 사용하는 메커니즘
    • "interrupt 통해 OS kernel에 대한 함수 호출 사용 가능"
    • 일반적으로 C/C++ 또는 assembly로 작성된 interrupt handlers로 제공
    • 권한이 낮은 모드 -> 권한이 높은 모드로 제어를 안전하게 전환하는 메커니즘
      • Ex) POSIX system calls: open, close, read, write, fork, kill, wait, …

System calls

OS kernel 
privileged instruction 실행할수있음
1.io operation 명령어
2.timer 건드리는 명령

 

2.Parameter Passing in System Call

내부적으로 시스템 호출은 interrupt를 통해 처리

 

Parameter(매개변수) 전달 방법

  • Register (simple information)
  • Address of block (large information)
  • System stack

3.Types of System Calls

  • Process control
  • File management
  • Device management
  • Information maintenance
  • Communication

4.System-Call Interface

System-call interface: 운영 체제(OS)와 응용 프로그램 간의 상호 작용을 가능하게 하는 인터페이스

Example of system-call interface in Linux

  • 일반적으로 각 system call에는 번호가 연결됩니다.
    • c.f. 시스템 호출의 IRQ: Linux의 경우 0x80, DOS/Windows의 경우 0x21
    • System-call interface는 이 숫자에 따라 색인된 테이블을 유지합니다.
  • System-call interface는 OS 커널에서 의도된 시스템 호출을 호출하고 시스템 호출의 상태와 모든 반환 값을 반환합니다.
  • 호출자는 시스템 호출이 구현되는 방법에 대해 아무것도 알 필요가 없습니다.
    • API를 준수하고 결과적으로 OS가 수행할 작업을 이해하기만 하면 됩니다
    • API에 의해 프로그래머에게 숨겨진 OS 인터페이스의 대부분의 세부 정보
      • 런타임 지원 라이브러리에서 관리(컴파일러에 포함된 라이브러리에 내장된 함수 집합)

 

What does system-call interface do?

  • kernel에 정보를 전달
  • kernel mode로 전환
  • kernel mode에서 모든 데이터 처리 및 실행 준비

Cf. System call vs. I/O functions in programming language 

Ex) read(), vs. fread()

  • read():  OS에서 제공
  • fread(): C 언어로 정의된 표준 함수
    • fread()는 read()를 사용하여 구현됩니다

 

5.Application Programming Interface

API: computer system (OS), library or application이 서비스 요청을 허용하기 위해 제공하는 인터페이스

  • application programmers가 사용할 수 있는 functions, parameters, return values(반환값)의 집합
  • system call과 밀접한 상관 관계가 있을 수 있음
  • system call과 함께 구현된 높은 수준의 기능을 제공

Example of API

: ReadFile()에 전달된 parameters에 대한 설명입니다

  • HANDLE file—읽을 파일
  • LPVOID buffer—데이터를 읽고 쓰는 버퍼
  • DWORD bytesToRead—버퍼로 읽을 바이트 수
  • LPDWORD bytesRead—마지막으로 읽은 바이트 수
  • LPOVERLAPPED ovl—중복 I/O가 사용되고 있는지 여부를 나타냄

Examples of System Calls

6.Process Control: Load/Execution

프로그램은 다른 프로그램을 load/execute할 수 있다. ( Ex: CLI, Windows Explorer, MacOS Finder)

 

The parent program can

  • Be lost (분실)(replaced by the child program)
  • Be paused(일시중지)
  • Continue execution: multi-programming/multitasking (Create process/submit job)

Multitasking system / Example: FreeBSD UNIX

Command interpreters는 계속 실행될수있다.

 

Two cases of parent’s execution

  • Case 1, continue to execution
    • 새 프로그램이 백그라운드에서 실행됩니다
    • 콘솔 입력이 불가능
  • Case 2, wait the child
    • 새로운 프로세스로 I/O 액세스 가능
    • 프로세스가 종료되면(exit()) 상태 코드(0 or error code)와 함께 제어가 상위(예: shell)로 반환
더보기

[ Reading Assignment ]

  • fork() : 현재 프로세스를 복제하여 자식 프로세스를 만듭니다. 이때, 부모 프로세스와 자식 프로세스는 독립적인 메모리 공간을 가지고, 각각의 프로세스는 독립적으로 실행
  • exec() family functions
    • execlp() : PATH 환경 변수에서 지정된 디렉토리 중에서 지정된 파일을 실행합니다. 이때, 인자로 전달된 문자열은 실행 파일과 실행 인자들로 구성
    • execvp() : 현재 작업 디렉토리에서 지정된 파일을 실행합니다. 이때, 인자로 전달된 문자열은 실행 파일과 실행 인자들로 구성
  • wait() : 자식 프로세스가 종료될 때까지 부모 프로세스를 대기 상태에 두는 함수
  • Controlling new process
    • Get/set process attributes(프로세스 속성 가져오기/설정) (ex. Priority, maximum execution time, …)
    • Terminate process(프로세스 종료)
  • Waiting for new job/process
    • 정해진 시간 동안 기다림
    • event / signal event 기다림
  • Debugging
    • Dump (시스템이나 프로그램의 메모리나 파일 등을 저장하거나 출력하는 것)
    • Trace: trap after every instruction (모든명령 후 트랩)

 

7.Process Control: Termination

  • Normal termination (end) - 정상종료(종료)
    • 리소스 할당 취소, 현재 프로세스에 대한 정보
  • Abnormal termination (abort) - 비정상종료(중단)
    • 디버깅 및 분석을 위해 메모리를 파일로 덤프
    • 사용자에게 처리 방법 묻기

 

8.File Management

  • Create/delete files
  • Read/write/reposition
  • Get/set file attribute
  • Directory operation
  • More service
    • move, copy, …

=> system calls, APIs, or system programs을 통해 기능을 제공

9.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 (결합된 파일-디바이스 구조)
    • I/O를 특수 파일로 매핑
    • 파일과 장치 모두에서 동일한 system call 집합

10.Information Maintenance

  • OS와 user program 간 정보 전송
    • Current time, date
    • system 에 관한 정보
      • (현재 사용자 수, OS 버전, 사용 가능한 메모리/디스크 공간)
  • 모든 프로세스에 대한 정보를 유지하는 OS  ( Ex) /proc of Linux )

 

11.System Programs

System program : 프로그램 개발 및 실행에 편리한 환경을 제공하기 위한 프로그램

System program

 

시스템 프로그램은 다음과 같이 나눌 수 있다:

  • File manipulation (파일 조작)
  • Status information sometimes stored in a file modification (때때로 파일 수정에 저장되는 상태 정보)
  • Programming language support (프로그래밍 언어 지원)
  • Program loading and execution (프로그램 로드 및 실행)
  • Communications (커뮤니케이션)
  • Background services (백그라운드 서비스)