c로 작성한 fork()문 질문요 ㅠㅠ
꽃여름
질문 제목 : fork()문이요..ㅠ
fork로 부모-자식-손자 만드는거거든요 근데
코딩 실행시키면
PARENT: Child pid = 21938
CHILD: Child process is running.
CHILD: GRANDCHILD pid = 21939
CHILD: Child process is running. ---- GRANDCHILD: Grandchild process is running 으로 해야되는데 ㅠㅠ
이렇게 뜨네요...ㅠㅠ
바꿀려고 별짓 다했지만 못하게어요...도와주세요
질문 내용 :
#include sys/types.h
#include unistd.h
#include sys/wait.h
int main(void)
{
int pid, status;
if((pid = fork()) 0)
printf(Fork error \n);
else if (pid 0) {
/* parent process */
printf(PARENT: Child pid = %d \n, pid);
if (waitpid(pid, &status, 0) 0)
printf(waitpid error \n);
printf(PARENT: Child process exited (parent is still running) \n);
do { } while (1);
} else if(pid == 0) {
/* child process */
if ((pid = fork() ) 0)
printf(Fork error\n);
else if (pid 0) {
printf(CHILD: GRANDCHILD pid = %d\n, pid);
}
printf(CHILD: Child process is running. \n);
do { } while (1);
}
}
-
미련곰팅이
else if (pid 0) {
printf(\CHILD: GRANDCHILD pid = %d\\n\