뚜sh뚜sh

Process Management2 본문

운영체제

Process Management2

뚜sh뚜sh 2023. 6. 13. 14:26

fork() 시스템 콜

- A process is created by the fork() system call.

  • creates a new address space that is a duplicate of the caller.

 

 

 

exec() 시스템 콜

- A process can execute a different program by the exec() system call.

  • replaces the memory image of the caller with a new program.

 

 

 

wait() 시스템 콜

- 프로세스 A가 wait() 시스템 콜을 호출하면

  • 커널은 child가 종료될 때까지 프로세스 A를 sleep시킨다(block 상태)
  • Child process가 종료되면 커널은 프로세스 A를 깨운다(ready 상태)

 

 

 

exit() 시스템 콜

- 프로세스의 종료

1. 자발적 종료

  • 마지막 statement 수행 후 exit() 시스템 콜을 통해
  • 프로그램에 명시적으로 적어주지 않아도 main 함수가 리턴되는 위치에 컴파일러가 넣어줌

2. 비자발적 종료

  • 부모 프로세스가 자식 프로세스를 강제 종료시킴 : 자식 프로세스가 한계치를 넘어서는 자원 요청, 자식에게 할당된 태스크가 더 이상 필요하지 않음
  • 키보드로 kill, break 등을 친 경우
  • 부모가 종료하는 경우 : 부모 프로세스가 종료하기 전에 자식들이 먼저 종료됨

 

 

 

프로세스와 관련한 시스템 콜

- fork() : create a child(copy)

- exec() : overlay new image

- wait() : sleep until child is done

- exit() : frees all the resources, notify parent

 

 

 

프로세스 간 협력

- 독립적 프로세스(Independent process) : 프로세스는 각자의 주소 공간을 가지고 수행되므로 원칙적으로 하나의 프로세스는 다른 프로세스의 수행에 영향을 미치지 못함

- 협력 프로세스(Cooperating process) : 프로세스 협력 메커니즘을 통해 하나의 프로세스가 다른 프로세스의 수행에 영향을 미칠 수 있음

- 프로세스 간 협력 메커니즘(IPC : Interprocess Communication)

  • 메시지를 전달하는 방법 : message passing(커널을 통해 메시지 전달)
  • 주소 공간을 공유하는 방법 : shared memory(서로 다른 프로세스 간에도 일부 주소 공간을 공유하게 하는 shared memory 메커니즘이 있음, thread : thread는 사실상 하나의 프로세스이므로 프로세스 간 협력으로 보기는 어렵지만 process를 구성하는 thread들 간에는 주소 공간을 공유하므로 협력이 가능

 

 

 

Message Passing

- Message system : 프로세스 사이에 공유 변수(shared variable)를 일체 사용하지 않고 통신하는 시스템

- Direct Communication : 통신하려는 프로세스의 이름을 명시적으로 표시

- Indirect Communication : mailbox(또는 port)를 통해 메시지를 간접 전달

 

 

 

Interprocess Communication

 

'운영체제' 카테고리의 다른 글

CPU Scheduling2  (0) 2023.06.14
CPU Scheduling1  (0) 2023.06.13
Process Management1  (0) 2023.06.13
Process2  (0) 2023.06.12
Process1  (0) 2023.06.12
Comments