pid=fork()로 자식 생성후, sleep문이 먹질 않습니다.
부모가 잠을 안자요...
저와같이 이틀째 밤새고있어요....
pid =fork()로 pid를 생성했는데,,,
자식에겐 잘 들어가는데 부모의 로직에 잘 안들어가요...
자식에게 몇번 들어가고 부모의 로직에 한꺼번에 3개씩 들어가기도하고...
그래서 시그널을 블록시켜줬더니... 이제 부모의 로직에 들어가긴하는데,
sleep문을 안먹어요...
리눅스에서 작업하고있습니다..
혹시 아래의 소스를 잠시보시고 왜 sleep 안먹는지 아시거나,,, 껀덕지가 있으시면 답변달아주세요 ㅠㅠ
// 부모
if( pid != 0 ) {
printf(" 첫수행이 아닐 때의 부모에 들어왔네요.\n");
activePcb->next->remainingcputime--;
dispatcherTimer++;
sigemptyset (&set); // 빈 시그널 집합 생성 // unblock SIGSTP if necessary (BSD/OS X)
sigaddset (&set, SIGALRM); // 시그널을 추가합니다.
sigaddset (&set, SIGCHLD); // 시그널을 추가합니다.
sigprocmask (SIG_BLOCK, &set, NULL); // 블록화될 시그널을 설정합니다
nSleep(1);
sigprocmask (SIG_UNBLOCK, &set, NULL); // 언블록화될 시그널을 설정합니다
act.sa_handler = signalHandler;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
sigaction(SIGCONT, &act, NULL);
// 수행을 완료한 프로세스를 종료합니다.
if( activePcb->next->remainingcputime == 0 ) {
// 원래 수행하려 했던 프로세스 사살
if(kill(activePcb->next->pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}
//waitpid(activePcb->next->pid, &status, 0);
pause();
// 수행하려 했던 프로세스를 수행하기 위해 만들었던 자식 죽이기
if(kill(pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}
//wait(&status);
pause();
}
else {
// 원래 수행 하려 했던 프로세스 중단
if(kill(activePcb->next->pid, SIGTSTP)) {
fprintf(stderr, "stop of %d failed", (int)activePcb->next->pid);
}
//waitpid(activePcb->next->pid, &status, 0);
pause();
// 수행하려 했던 프로세스를 수행하기 위해 만들었던 자식 죽이기
if(kill(pid, SIGINT)) {
fprintf(stderr, "terminate of %d failed", (int)activePcb->next->pid);
}
//wait(&status);
pause();
}
}
// 자식
else {
printf(" 첫수행이 아닐 때의 자식에 들어왔네요.\n");
printf("제계할 프로세스 id : %7d\n", activePcb->next->pid);
kill(activePcb->next->pid, SIGCONT);
}
}
댓글 달기