트리구조 변경에관해서
태양
다음과 같은트리구조로 바꾸려고요.
a -- b -- c (즉, 부모-자식-손자)어떻게하면 되는지 코드변경과 이해가 쉽게 주석을 달아주셧으면 정말 감사하겟습니다!!질문 내용 : #include sys/types.h
#include unistd.h
#include sys/wait.h
#include string.h
int main(void)
{
int pid, status;
if((pid = fork()) 0)
printf(fork error\n);
else if (pid 0) {
/* parent process */
printf(\nparent: child pid = %d\n, pid);
if(waitpid(pid, &status, 0) 0)
printf(waitpid error\n);
printf(\nparent: child process exited.\n);
printf(parent: parent process is still running.\n);
do {} while (1);
} else if(pid == 0) {
/* child process */
printf(child: child process is running.\n);
do {} while (1);
}
}
-
해찬나래
child가 만들어지면 거기에서 다시 똑같은 형태로 fork를 하면 되지요.
else if(pid == 0) {
// 여기에 parent, child가 나뉘는 부분을 반복하면 됩니다.
}
물론 변수 선언 정도는 만져주면 되겠죠. -
놓아줄게요
가입인사를 하지 않으면 사이트 활동을 할 수 없다는 규칙이라도 있었던가요.
-
다흰
가입인사는 하고 글 올리시는 건지요
-
하린
소스 ㄷㄷ