fork() : 시스템 콜이 새로운 프로세스를 생성(주소 공간 복사)exec() : 시스템 콜을 통해 새로운 프로그램을 메모리에 올림프로세스가 마지막 명령을 수행한 후 운영체제에게 이를 알려줌(exit)
부모 프로세스가 자식의 수행을 종료시킴(abort)
자식이 할당 자원의 한계치를 넘어선 경우
자식에게 할당된 태스크가 더 이상 필요하지 않은 경우
부모가 종료(exit)하는 경우
parent
int main()
{ int pid;
pid = fork();
if (pid == 0) /" this is child"
printf("\n Hello, I am child!\n")
else if (pid > 0) /" this is parent "
printf("\n Hello, I am parent!\n");
}
child
int main()
{ int pid;
pid = fork();
if (pid == 0) /" this is child"
printf("\n Hello, I am child!\n")
else if (pid > 0) /" this is parent "
printf("\n Hello, I am parent!\n");
}
int main()
{ int pid;
pid = fork();
if (pid == 0) /" this is child"
{ printf("\n Hello, I am child!\n 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");
}
자식 프로세스가 종료될 때까지 기다리는 함수
독립적 프로세스 : 프로세스는 각자의 주소 공간을 가지고 수행되므로 원칙적으로 하나의 프로세스는 다른 프로세스의 수행에 영향을 미치지 못함
협력 프로세스 : 프로세스 협력 메커니즘을 통해 하나의 프로세스가 다른 프로세스의 수행에 영향을 미칠 수 있음
프로세스 간 협력 메커니즘(IPC: Interprocess Communication)
Direct Communication : 통신하려는 프로세스의 이름을 명시적으로 표시Indirect Communication : mailbox (또는 port)를 통해 메시지를 간접 전달