ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Unix System Overview
    Linux 2023. 3. 24. 02:35
    반응형

    본 자료는 상명대학교 신동하 교수님의 수업을 정리한 것임을 밝힙니다.

    Unix System Overview

    무엇을 공부하나

    1. OS가 application에게 제공하는 아래 3가지 service

      file input / output

      process creation, termination

      IPC ( inter-process communication )

    1. developer 관점의 Unix System

    Unix Architecture

    kernel의 service를 이용하여 프로그래밍을 하는 방법을 배웁니다.

    application사용자에게 기능을 제공하는 프로그램. Unix는 multi-programming system이다
    shellapplication의 하나로 유닉스 명령어 혹은 다른 프로그램을 수행 시키기위한 명령어 처리 프로그램 ( command interpreter ) 언어이다!
    library라이브러리
    kernel유닉스 운영체제의 중심 부분 (비전문가들에게 운영체제라고 불리움)

    Logging in

    Unix OS는 system에 등록된 각 사용자에 대한 정보

    /etc/passwd

    에 저장돼있다.

    하나의 사용자는 아래와 같은 7개의 정보를 가짐

    real example

    r320은 거의 맨 아래에 있음

    각 자리의 의미 ( “:” 로 구분)

    1.login name
    2. password (보안으로 인해 x 로 표시)
    3. uid: user id
    4. gid: group id
    5.comment
    6. home directory
    7.shell

    Files and Directories

    File System

    1. 많은 파일들을 모아놓은 상자
    1. physical disk는 여러개의 file system을 가질 수 있다. (partition = 논리적 장치) 논리적 장치에 access 할 수 있다.
    1. directory와 files는 hierarchical하다
    1. directory는 다른 directory의 entry를 저장하고 있다.
    1. directory도 file이다!
    1. 모든 디렉토리는 / 부터 시작
    1. Unix는 7가지의 file을 가진다. 그리고 가장 첫 문자가 이를 나타낸다.
      -regular file
      ddirectory
      ppipe
      ssocket
      ccharacter device
      bblock device
      lsymbolic link

    파일은 file system내에서 유일하게 존재하는 inode 번호를 갖고 있다.

    inode

    unique, non-negative integer

    파일 종류, 접근 권한, uid, gid, timestamps, 파일 크기, 데이터 블록에 대한 주소등에 대한 정보를 갖는다.

    Input and Output

    대상은 device (keyboard(c), mouse(c), printer(c), disk(b) ... etc) 입니다.

    device는 모두 file이다 character device, block device (I/O device)

    File descriptors (FD) ← logical number

    process가 입출력하는 파일을 지정하기 위하여 kernel이 사용하는 non-negative integer

    standard input/output/error

    FD 0 : standard input (keyboard)

    FD 1 : standard output (monitor)

    FD 2 : standard error (monitor)

    input/output의 방법

    unbuffered

    FD를 사용한 read및 write system call

    buffered → 더 효율적이다.

    standard I/O library에서 제공된 파일포인터 (FILE*) 를 사용한 입출력 gets, putc, getchar, putchar, fprintf, fscanf, fread, fwrite등의 함수 사용

    Programs and Processes

    Program: disk에 저장된 executable files (static)

    Process: 수행중인 program (dynamic)

    Thread: 하나의 프로세스는 하나 이상의 thread를 갖는다. 하나의 프로세스 안의 모든 thread는 같은 address space를 공유한다.

    Error Handling

    Unix system에서 오류가 생기면 음의 정수가 return되고 변수 errno에 오류 번호가 저장된다.

    char *strerror (int errnum) → errno.toString()

    errno을 메뉴얼에 명시된 사람이 이해할 수 있는 str으로 변환한다.

    // example code
    fprintf(stderr, "%s %s\n", argv[0], strerror(errno)

    가장 최근에 발생한 system call 이후의 에러는 void perror(char* msg)를 호출해도 된다.

    // easier than above way
    #include <stdio.h>
    ...
    perror(argv[0])

    User Identification

    uid: user id, gid: group id

    Unix에서 각 users는 고유의 uid, 공유 가능한 gid를 가진다.

    # uid/gid 출력
    id

    각 processes는 실행시킨 user의 pid, gid를 가진다.

    각 file은 생성한 user의 uid와 gid를 가진다. → inode에 저장됨

    Signals

    event가 발생했을 때 process에게 전달되는 software interrupt

    process는 다른 process에게 신호를 전달할 수 있다.

    # 사용가능한 신호의 종류가 모두 출력됨
    kill -l

    signal의 default action은 process termination임 → 바꿀 수 있다.

    signal handling routine: 어떤 신호가 전달되었을 때 수행되는 루틴 → 지정할 수 있다.

    Time Values

    Calendar time: 1970년 1월 1일 0시(epoch) 이후 지난 초(sec)

    Process times: process가 수행한 시간

    wall clock time: 사람이 보는 시간 process의 시작, 끝의 시간

    user CPU time: process가 processor를 점유한 시간

    system CPU time: process를 실행하기 위해 실행된 kernel이 실행된 시간

    File times

    mtime: 마지막 modify 시각

    atime: 마지막 access 시각

    ctime: 마지막 change 시각

    ls -l  # mtime
    ls -lu # atime
    ls -lc # ctime

    Library Calls and System Calls

    library call: application → library

    system call: library → kernel & application → kernel

    Unix Manual

    /usr/share/man에 저장됨

    # man [section number] subject
    man 1 ls

    sections

    1. Commands
    2.System Call
    3.Library Calls
    4.Special Files
    5.File Formats and Conversions
    6.Games for Linux
    7.Macro Packages and Conventions
    8.System Management Commands
    9.Kernel Routines


    Uploaded by N2T

    반응형

    'Linux' 카테고리의 다른 글

    File Input & Output System calls  (0) 2023.03.24
    Simple Commands  (0) 2023.03.24
    Shell Programming  (0) 2023.03.24
Designed by Tistory.