본문 바로가기

SSS

SSS-1_2. UNIX 시스템 소개 및 구조

목차

-UNIX 발전 과정

-UNIX의 주요 특징 (Shell, File, Process)

-Block Diagram of the Kernel

-System Call(process, file)

 

교재랑은 정말 아무 관련 없는 목차이다.

 

*강의 듣기 전에 할 것(추천)

7-zip 깔아서

pptx 압축파일 풀어서

ppt>media>media 가면 ppt 장 순서대로 media 파일이 있다.

windows 쓰면 window media player 깔아서 우클릭>고급기능>재생속도설정> 2배속(추천), 4배속 해도 될듯.

 

 

UNIX 발전 과정

(이름은 발전 과정이지만 뭔가 내용물이 다르다. 필요성에 가깝다.)

- UNIX 기반 시스템

UNIX는 서버용 OS, 모바일 OS의 기반이 되었다.

- UNIX의 필요성

Engineer : workstation/server toolbox의 기본 운영체제이며, building block, newtwork s/w에서 UNIX를 사용하기 때문.

Student : 좋은 선생님이다. (내가 이렇게 쓴거 아니고 진짜 이렇게 적혀있었음) >linux가 free software라 그렇습니다.

 

UNIX의 주요 특징

(및 커널)

- Time sharing : 많은 프로그램을 CPU가 쪼개서.

- Conversational System : 사용자 iterrative? 하게. (대충 여러 사용자가 이용 가능하다는 뜻인 듯.)

  • Shell : command interpreter
  • File (UNIX는 file type OS) (regular, directory, special)
  • Process: HDD에 있는 program(file)을 main memory로 loading하여 실행시킨 것

-System Call

파일, 프로세스를 쉽게 관리하는 기능을 제공하는 인터페이스(API)

 

Block DIagram of the Kernel

(Kernel: 운영체제에서 주요한 기능을 하는 부분)

1. Shell : (not kernel!! JUST OS) 사용자가 입력한 command(명령어)를 해석해주는 것. 여러 종류 있음.

장점 : redirection 가능(standard in/out의 방향을 바꿈)

2. File : hierarchical.

파일 포맷, byte stream, write용 API 포함.

특) I/O device도 파일로 취급당함 ->file type OS

protection mechanism - 보안 관점(owner, group, others, rwx)

 

UNIX 구조

위에서 이야기 한 친구들의 전체 모양을 그리자면 이런 모양입니다.

그래서, UNIX Kernel Architecture를 Block Diagram으로 그리자면 다음과 같다.

컴퓨터 구조 열심히 들을걸.

(각각의 구성 요소가 HDD인지 memory인지 헷갈린다. 컴퓨터 구조를 더 열심히 들었어야 했다.)

 

System Call (and library)

kernel에서 제공하는 함수를 user process에서 사용할 때는, system call을 통해 이용한다.

! 이 때, library라는 것이 있다. library가 function을 따로 제공하여 직접 system call을 사용하지 않고도 kernel에서 제공하는 함수를 쓸 수 있다(그림 1.1 화살표 참고). library는 user process. ex)C library func.

 

System Call에 대한 내용을 조금 더 자세히 살펴봅시다. (다음 주까지 System Call 구경하더라.)

 

1. 파일 관련

>File subsystem과 관련된 Data Structure(데이터 구조)

더보기

 *(system이랑 subsystem이랑 무슨 차이인가)

교수님이 File System이라고 말씀하셨지만 설명은 File Subsystem에 대한 내용이므로 subsystem이라고 했다.

각각의 용어는 조금 다른 뜻. 좀 더 자세히 봐야 알겠지만... 일단은 링크.

File System - https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%9D%BC_%EC%8B%9C%EC%8A%A4%ED%85%9C

File SubSystem - https://www.gotothings.com/unix/the-file-subsystem.htm

 - file descriptor, system file table, inode table

  + inode table : inode - file마다 하나씩 갖고 있음.

  + system file table : open file table. sys가 file을 하나씩 open할 때 마다 entry가 하나씩 생김.

  + file descriptor : process마다 자기가 open한 file을 구분하기 위해서 사용. 0/1/2 stdio.

 

>File type

 - regular, directory, special(device file), socket(IPC), symbolic link

  + socket : 통신용. 후반에 또 자세히 합니다.

  + link : copy와 다름. 어떤 파일의 위치를 link하는 것. 찾아가는 길을 제공하는 것. (pointer랑 비슷한 것 같다.)

     inode를 가지고 있으면 hard link, path name를 가지고 있으면 symbolic link.

 

(왜 똑같은거 두 장 있지?)

 

위 내용을 사진으로 보자.

파일 관련 data structure
다른 관점에서 본 사진.

*이 사진에서 v-node라는게 갑자기 등장했는데, file이 local이든 원격이든 구분하기 쉽게 하기 위해서 존재하는 node이다.

 

만약 다른 두개의 독립적인 process에서 같은 file을 open한다면 어떨까?

두 개의 process, 한 개의 file... 삼각관계.

이 경우 File Synch를 맞춰줘야 한다. 이 내용은 뒤에서 배운다.

 

다음 그림은 dup(1)을 사용한 그림인데, dup()은 fd를 copy하는 내용이다. 이는 뒤에서 자세히 나오므로 일단 생략.

 

>FIle 관련 System call

 - file I/O , file and directory

  +basic functions that perform I/O

int open(const char *pathname, int flag, mode_t mode) file access 하기 전에 여는 것(있던 것) fd return (fd table의 index 값)
int create(const chat *pathname, mode_t mode) file access 하기 전에 여는 것(없던 것) fd return (fd table의 index 값)
int close(int filedescriptor)

open() 후 뭔가 하고

 
int lseek(int filedes, off_t offset, int whence) 자기가 원하는 위치로 이동하기 offset 설정
ssize_t read(int filedes, void *buff, size_t nbytes) 읽기  
ssize_t write(int filedes, void *buff, size_t nbytes) 쓰기  
int dup(int filedes) fd 복사  
int dup2(int filedes1, int filedes 2) fd 1을 2로 복사  
int fcntl(int filedes, int cmd.... /*arg*/ file control file의 상태를 get하거나 set할 때
int ioctl(int filedes, int request, ...) io control device의 상태를 get하거나 set할 때

 

각종 flag. 필요할 때 찾아보는게 나을 듯.

 - file sharing : 가능

 - atomic operation : 안 쪼개짐. read와 write가 동시에 일어난다면, 중간에 scheduling이 일어나지 않음. 독점권을 가지고 수행 가능.

 

위의 내용을 이제 진짜 다 합쳐보자!

최종_진짜최종_완성본_수정_최종.jpg

file sharing에 대한 내용도 그림으로 보자.

같은 프로세스
다른 프로세스 ... fork()에 관련된 내용이라 프로세스 할 때 더 자세히 본다

 

>Disk drive, partitions, and a file system

(아까 전 그림에도 달았듯이, 많은 부분이 디스크의 어디에 있는지 복잡하다.

어떤 부분이 어떻게 어디에 위치해있는지 정리해보자. 이제 슬슬 머리가 아프다.)

 

이게 뭐지?

(운영체제를 안 들은 나에겐 죽을 맛이다. i-node array에 대한 detail도 다음 그림으로 보자.)

오 마이 갓.

(여기부터는 아... 그렇구나... 하게 된다. 그래도 될 것 같다.
뭔가 문제가 생겼을 때 자세히 보면 좋을 것 같다. 뭔가 하나로 정리되지는 않는 것 같사와요.)

UNIX file System과 disk 구조를 구체화해서 보자.

(위의 세가지 그림은 다 똑같은 것을 설명하기 위한 것이다. 하하.)

 

>파일 속성 관련 함수

 -to get attributes : stat(), fstat(), lstat()

 -to modify permission, ownership, etc : umask(), chmod()

 -to create or delete files or links : link(), unlink(), rename()

 -to manipulate directories : mkdir, opendir, readdir, chdir, getcwd

 -to ensure consistency pf the actual file system : sync()

 

>User/Permission

 -User

  +owner / group / others(super suer)

  +real(실제 수행) / effective(excutable file의 owner) user로 구분

 -Permission

  +rwx(read/write/execute)

    1bit씩 각각의 권한 / 3bits씩 각 유저 => total 9 bits

    r : read directory entry

    w : remove and create files in directory

    x : search for given pathname in directory

 

'SSS' 카테고리의 다른 글

SSS-4. 시스템 데이터 파일  (0) 2020.04.13
SSS-3. UNIX 시스템 호출  (0) 2020.04.12