목차

-booting과 /etc/rc

-login과 /etc/passwd(shadow)

-networking과 여러 가지 file

 -/etc/hosts, /etc/services, /etc/protocols

 -/etc/networks

 

booting과 /etc/rc

- Booting : 컴퓨터가 처음에 power on을 하거나 reset을 했을 때 처음 시작되는 프로그램.

 bootstraper -> Boot Block(disk에 있음) -> OS

 이 과정의 마지막에서 /etc/init(pid=1을 생성하는 process) 이 불려옴 ->다른 process는 전부 init의 fork()

 

-init process : 시스템 초기화를 함. 처음에는 single user mode로 수행.

 shell program fork, stdio descriptor, system console terminal 생성. (하는 일이 많구만)

 

-multi user operation

 이 과정에서 일어나는 자세한 일 : shell을 만든다->/etc/rc에 있는 interpret하여 수행시킴

 /etc/rc : 시스템 초기화에서 수행해야 하는 일이 있음 

  +파일 시스템 체크, cron, syslog 데몬 생성, /etc/mtab file 작업 가능

 terminal device에 관련된 cofiguration file(/etc/tty)을 읽어서 한 entry마다 사용자 접속을 감지할 수 있는 프로그램(/etc/getty) 생성

 

init이 불려올 때의 위 과정들을 정리하자면 다음 그림과 같다.

init process fork()

 

login과 /etc/passwd(shadow) System Data File

-passwd

 passwd 파일에 있는 예시를 가져와서 각 요소가 뭘 의미하는지 살펴보자. 분리자는 :이다.

예시만 보면 답답하니까, 직접 shell 창을 켜서 찾아보자 passwd는 /etc에 있다.

cat passwd를 하면 목록이 쭉 뜬다. root를 일단 살펴보자.

passwd file - root

user name : encrypted password : numerical user id : numerical group id : comment field : initial working directory(home directory) : initial shell(user program, 사용하는 shell.)

의 순서대로 이루어져 있다. (볼 수 있는 세상이 넓어졌다!)

 

-passwd 관련 system call

[간단상식 ] get - return / set - write 

struct passwd *getpwuid(uid_t uid) uid를 통해 passwd를 얻겠다!
struct passwd *getpwname(const char *name) name을 통해 passwd를 얻겠다!

passwd struct는 다음과 같은 요소들이 들어있다 ...

char *pw_name

char *pw_passwd

uid_t  pw_uid

gid_t  pw_gid

char *pw_gecos

char *pw_dir

char *pw_shell

 

-home directory(~)

시작했을 때, 사용자마다 home directory에 login 정보가 들어있는 system data file이 있다.

 +login

  /bin/sh

   ~/.profile : (.login + .cshrc)

  /bin/csh

  ~/.login : set terminal type, environment vars(fork, exec 할 때 e 변수에 관련된 것)

  ~/.cshrc : set command alias, path, umask(access control에 해당. umask에서 masking 되어있으면 해당하는 access permission이 protection함. default mask값 설정)

  +logout

   /bin/csh

   ~/.logout : logout할 때 해야 하는 동작들.

 

networking과 여러 가지 file

-Login Procedure(로그인 과정)

 +terminal login

  +network login

우리는 알고 있다. 이 그림들을 다시 자세히 보게 될 것이라는 것을 ... 그냥 통짜로 정리해보자.

 

 

-/etc/hosts, /etc/services, /etc/protocols

 +/etc/hosts : 각 host에 대한 정보. ip주소, hostname가 기록되어 있는 system daa file

 +/etc/service : IP + port(service, 프로세스 관련)

 +/etc/protocol : transport layer에서 어떤 protocol을 사용하는지 (TCP, UDP)

 

 

위의 정보들을 총정리한 표 역시 존재한다!

 

'SSS' 카테고리의 다른 글

SSS-3. UNIX 시스템 호출  (0) 2020.04.12
SSS-1_2. UNIX 시스템 소개 및 구조  (2) 2020.04.11

지난시간 목차

지난 시간에는 System Call에 대해 file만 나갔다.

process 관련 System call에 대해 알아보자.

 

process : program이 수행되는 것. executable file이 memory에 로딩된 것이 process.

process control을 위한 system call을 예제 중심으로 알아봅시다.

 

목차

-fork/vfork 및 file sharing

-exit, wait, exec 계열

-user id(real/effective)

 

fork/vfork 및 file sharing

*vfork는 child process를 만들지 않고(fork -> exec 하는 경우에) parent가 연 file을 공유하는 방식? 이다.

 

int pid;
printf(“ my pid = %d\n”, getpid());
pid = fork();
if (pid > 0)    { /* parent */
	printf(“parent with pid = %d\n”, getpid());
    }
else if (pid == 0) { /* child  */
	printf(“child with pid = %d\n”, getpid());
	}
else if (pid == -1) {
	printf(“error \n”);
    }

 

더보기

결과 실행

my pid = 110

child with pid = 111

parent with pid = 110

(코드는 운체 때도 본 코드이므로 자세한 설명은 생략한다.)

이 때 parent와 child가 공유하는 내용은 다음과 같다.

text(code) - share

data - no share

stack - no share

메모리 배열에 관해 ...

각각의 부분은 다음과 같은 part로 이루어져 있다.

 

그림을 하나 더 보자(조금 더 자세히 나와있다).

fork를 썼을 때 parent와 child의 파일 공유

지금까지 배운 걸로 퀴즈를 풀어봅시다 !

 

Q. 다음 코드를 읽고 생성되는 process의 갯수는 몇개일지 맟춰봅시다.

int pid, i, N;
....
for(i=1;i<=N;i++)
	fork();
더보기
정답은 2^N개!

 

 

exit, wait, exec 계열

-exec 계열

 exec+{l,v}+{p, <sp>, e} ()

 +argument 형식 관련 : l (list), v(vector)

 +p(path), e(environment), sp(직접지정)

 

! 환경 변수

다음과 같은 요소로 이루어져 있다.

 

exec() 실행 예제를 보자.

exec 각 요소에는 뭐가 들어갈까

exec가 실행되면... 다 갈아 엎는다. 자기 process에서 날리고 불러온 program을 실행시키는 것이다.

어디를 날리는지는 OS마다 다르다. 대충 위에 있는 사진은 다 날라간다고 보면 된다.

fork는 새로 process를 복제하는 거라 다르다.

 

fork()와 exec()를 합체해보자.

응용 1.

{
     if ((pid=fork()) == 0) { /* child */
          execlp(“myprogram”,”myprogram”,”only 1 arg”,(char *)0 );
          printf(“myprogram cannot be executed. Check it. \n”);
     }
     else if (pid > 0)  /*parent */
}

fork로 만들어진 자식 process를 exec() 시켜서 독립시켜버릴 수 있다.

응용 2.

if (fork() == 0) { /*child*/
      fd = open();
      close(0);
      dup(fd)
      close(fd);
      execlp(“cmd”,”cmd”,(char *)0 );
}

*dup은 가장 앞부터 찾아서 비어있는 곳에 복사한다.

해당 코드는 결과적으로 0번이 open한 file을 가리키게 된다. = cmd < F와 같다!(redirection)

 

 

User id

(Real user/effective user)

-real user : 실제 프로그램을 실행하고 있는 사람.

-effective user : 파일 주인.

 

마찬가지로 예시를 보자.

"maury" user id 8319

"mjb" user id 5088

uid = getuid();
euid = geteuid();
fdmjb = open(“mjb”,O_RDONLY);
fdmaury = open(“maury”,O_RDONLY);
printf(“uid = %d, euid = %d, fdmjb=%d, fdmaury=%d\n”, uid, euid, fdmjb, fdmaury); 

*user mjb가 "maury"를 실행시켰을 때

uid = 5058, euid =8319, fdmjb=-1, fdmaury= 3

*user maury가 "maury"를 실행시켰을 때

uid = 8319, euid =8319, fdmjb=-1, fdmaury= 3

 

user ID별 항목은 다음과 같다.

 

saved set-user-ID에 대한 자세한 과정은 다음 그림을 참고하자.

'SSS' 카테고리의 다른 글

SSS-4. 시스템 데이터 파일  (0) 2020.04.13
SSS-1_2. UNIX 시스템 소개 및 구조  (2) 2020.04.11

목차

-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

+ Recent posts