엔지니어가 되고 싶은 공돌이
05. Fork, Exec and CreateProcess 본문
5. 1. Fork, Exec and CreateProcess
- Fork: Child Process를 만드는 Unix System Call.
1) Child Process는 Parent Process의 공간을 그대로 복사하여 Main Memory에 로드시킵니다.
2) Parent Process는 자식의 PID를 받고, Child Process는 0을 받습니다.
3) PCB를 만들고, PCB를 Ready Queue에 넣습니다.
ex) Web Server에 주로 사용.
- Exec: 새로운 Process를 만드는 것이 아닌 기존 Process를 다른 Process로 바꾸는 Unix System Call.
1) 현재 Process 중단 -> 다른 Program을 읽어와서 기존 주소공간에 로드.
- CreateProcess: Windows에서 Fork를 만드는 방식.
1) Fork와 Exec는 int인 반면 CreateProcess는 bool이며,
Fork는 Parameter가 없지만, CreateProcess는 여러 Parameter가 존재합니다.
2) PCB를 만들고, 주소공간을 로드해 PCB를 Ready Queue에 넣습니다.
5. 2. Process State Transition and PCB
- Process State Transition.
1) Interrupt는 주로 Timer에 의해 발생합니다.
2) I/O는 오래 걸리기 때문에 OS가 Waiting으로 보냅니다.
- 새로운 프로세스가 생성되면 new 상태로 시작합니다.
OS가 Process를 위한 공간을 할당하고 초기화한 뒤 Process를 관리하는 공간에 넣으면,
해당 Process는 Ready 상태가 됩니다.
Scheduler에 의해 Ready 에서 대기하고 있다가, 선택되서, CPU를 사용하기 되는걸 Running이라 부릅니다.
Interruput나 I/O or Event가 발생하면 Ready나 Waiting으로 가서 대기하거나 특정 작업을 수행하게 됩니다.
- PCB(Process Control Block): Process마다 가지고 있는 자기자신의 정보를 모두 저장하는 블록.
1) Process Management: PC, Register, Stack Pointer, PID…
2) Memory Management: Point to text(or data or stack) segment…
3) File Management: Root Directory, Working Directory…
4) Process가 실행 중 일 때 정보들(PC, SP, Register…)은 CPU안에 있고,
Process가 중단 되면 CPU안에 있는 값들을 Memory에 있는 PCB에 저장합니다.
다시 실행되면 다시 PCB -> CPU로 데이터를 이동시킵니다.
'Computer Science > Operating System' 카테고리의 다른 글
04. Process (0) | 2025.05.15 |
---|---|
03. Interrupt and Exception (2) (0) | 2025.05.13 |
02. Interrupt and Exception (1) (0) | 2025.05.12 |
01. Introduction to Operation System (0) | 2025.05.06 |