ํ๋ก์ธ์ค ์์ฑ
๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์์ ํ๋ก์ธ์ค๋ฅผ ์์ฑ
→ ๋ณต์ ์์ฑ
์ ์ฒด ํ๋ก์ธ์ค๋ ํธ๋ฆฌ ๊ณ์ธต๊ตฌ์กฐ ํ์ฑ
ํ๋ก์ธ์ค๋ ์คํ์ ์ํด ์์์ ํ์๋ก ํจ
์ด์์ฒด์ ๋ก๋ถํฐ ๋ฐ๋๋ค.
์์์ ๊ณต์
๋ถ๋ชจ์ ์์์ด ์์์ ๊ณต์ ํ ์ ์์ง๋ง ๋
๋ฆฝ์ ์ธ ์์์ ๊ฐ๋ ๊ฒ์ด ์์น
Copy-on-write(COW)
write๊ฐ ๋ฐ์ํ์ ๋(๋ด์ฉ์ ๋ณํ๊ฐ ์์ ๋) ๋ถ๋ชจ์ code, data, stack ๋ฑ์ copy ํ๋ค.
์ํ (Execution)
๋ถ๋ชจ์ ์์ ์ ๊ณต์กดํ๋ฉฐ ์ํ๋๋ ๋ชจ๋ธ
์์์ด ์ข
๋ฃ(terminate)๋ ๋๊น์ง ๋ถ๋ชจ๊ฐ ๊ธฐ๋ค๋ฆฌ๋(wait - blocked) ๋ชจ๋ธ
์ฃผ์ ๊ณต๊ฐ(Address space)
์์์ ๋ถ๋ชจ์ ๊ณต๊ฐ์ ๋ณต์ฌํจ (binary and OS data)
์์์ ๊ทธ ๊ณต๊ฐ์ ์๋ก์ด ํ๋ก๊ทธ๋จ์ ์ฌ๋ฆผ
fork() ์์คํ
์ฝ์ด ์๋ก์ด ํ๋ก์ธ์ค๋ฅผ ์์ฑ
fork() ๋ค์์ ์ด์ด์ง๋ exec() ์์คํ
์ฝ์ ํตํด ์๋ก์ด ํ๋ก๊ทธ๋จ์ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆผ
fork() ์์คํ
์ฝ - create a child (copy)
์๋ก์ด ํ๋ก๊ทธ๋จ์ ๋ฉ๋ชจ๋ฆฌ์ ์ฌ๋ฆผ → ์ ์ถ๋ฐ
int main(){
int pid;
pid = fork();
if (pid==0) /* this is child */
printf("\n Hello, I am child! Now I'll run date\n");
execlp("/bin/date", "/bin/date", (char *) 0);
else if (pid > 0) /* this is parent */
printf("\n Hello, I am parent!\n");
}
๊ผญ ์์์ ๋ง๋ค์ด์(fork()๋ฅผ ํด์) exec()์ ํด์ผํ๋ ๊ฒ์ ์๋
int main(){
printf("1");
execlp("echo", "echo", "3", (char *) 0);
printf("2"); /* ์์ํ ์ถ๋ ฅ X */
}
exit() ์์คํ
์ฝ - frees all the resources, notify parent
์๋ฐ์ → ํ๋ก์ธ์ค๊ฐ ๋ง์ง๋ง ๋ช
๋ น์ ์ํํ ํ ์ด์์ฒด์ ์๊ฒ ์ด๋ฅผ ์๋ ค์ค (exit )
์์์ด ๋ถ๋ชจ์๊ฒ output data๋ฅผ ๋ณด๋
๋น์๋ฐ์ → ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์์์ ์ํ์ ์ข
๋ฃ์ํด (abort )
์์์ด ํ ๋น ์์์ ํ๊ณ์น๋ฅผ ๋์ด์ฌ
์์์๊ฒ ํ ๋น๋ ํ์คํฌ๊ฐ ๋ ์ด์ ํ์ํ์ง ์์
๋ถ๋ชจ๊ฐ ์ข
๋ฃ(exit)ํ๋ ๊ฒฝ์ฐ
๋จ๊ณ์ ์ธ ์ข
๋ฃ → ๋ถ๋ชจ ํ๋ก์ธ์ค๊ฐ ์ข
๋ฃํ๊ธฐ ์ ์ ์์๋ค์ด ๋จผ์ ์ข
๋ฃ๋จ
ํค๋ณด๋๋ก kill, break๋ฅผ ์น ๊ฒฝ์ฐ
wait() ์์คํ
์ฝ - sleep until child is done
ํ๋ก์ธ์ค A๊ฐ wait() ์์คํ
์ฝ์ ํธ์ถํ๋ฉด
์ปค๋์ child๊ฐ ์ข
๋ฃ๋ ๋๊น์ง ํ๋ก์ธ์ค A๋ฅผ sleep์ํด (block ์ํ)
์์ ํ๋ก์ธ์ค๊ฐ ์ข
๋ฃ ์ ์ปค๋์ ํ๋ก์ธ์ค A๋ฅผ ๊นจ์ (ready ์ํ)
ํ๋ก์ธ์ค ๊ฐ ํ๋ ฅ
ํ๋ก์ธ์ค ๊ฐ ํ๋ ฅ ๋ฉ์ปค๋์ฆ - IPC: Interprocess Communication
๋ฉ์์ง๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ
message passing: ์ปค๋์ ํตํด ๋ฉ์์ง ์ ๋ฌ
ํ๋ก์ธ์ค ์ฌ์ด์ ๊ณต์ ๋ณ์๋ฅผ ์ผ์ฒด ์ฌ์ฉํ์ง ์๊ณ ํต์ ํ๋ ์์คํ
์ฃผ์ ๊ณต๊ฐ์ ๊ณต์ ํ๋ ๋ฐฉ๋ฒ
shared memory: ์๋ก ๋ค๋ฅธ ํ๋ก์ธ์ค ๊ฐ์๋ ์ผ๋ถ ์ฃผ์ ๊ณต๊ฐ์ ๊ณต์
CPU-burst Time์ ๋ถํฌ