나는 C 언어를 사용하여 Unix-Shell에서 작업하고 있습니다. waitpid를 사용하여 프로세스가 종료 될 때까지 기다렸다가 내 아들 프로세스 (fork()
으로 생성)가 SIGSEGV
과 같은 신호를 받았는지 알고 싶습니다.Unix - Waitpid 'status'
현재 코드 :
static const t_error error[ERROR_NBR]= {
{SIGHUP, "Hangup"},
{SIGQUIT, "Quit (core dumped)"},
{SIGABRT, "Abort (core dumped)"},
{SIGBUS, "Bus error (core dumped)"},
{SIGFPE, "Floating exception (core dumped)"},
{SIGKILL, "Killed"},
{SIGUSR1, "User signal 1"},
{SIGSEGV, "Segmentation fault (core dumped)"},
{SIGUSR2, "User signal 2"},
{SIGPIPE, "Broken pipe"},
{SIGTERM, "Terminated"},
};
void print_signal_message(int status)
{
int i;
if (WIFSIGNALED(status))
status = WTERMSIG(status);
else
return ;
i = -1;
while (++i < ERROR_NBR)
{
if (status == error[i].error_status)
{
fprintf(stderr, "%s\n", error[i].error);
return ;
}
}
return ;
}
int xwaitpid(int pid, int *status, int opt)
{
int ret;
ret = waitpid(pid, status, opt);
if (ret == -1)
fprintf(stderr, "Can't perfom waitpid (pid = %d)\n", pid);
if (WIFEXITED(*status))
*status = WEXITSTATUS(*status);
else
**print_sigerr(*status);**
return (ret == -1 ? (1) : ret);
}
xwaitpid
는 부모 프로세스에서 호출된다.
false || true
과 같은 명령을 실행해도 WIFSIGNALED는 항상 TRUE를 반환합니다.
누군가 나를 도와 줄 수있는 좋은 생각이 있습니까?
-> 내 답변을 찾았습니다.
제기 된 명백한 신호는 무엇입니까? 아이를 시작하는 코드가 괜찮습니까? (BTW, 코드에 전역 변수'i'가있는 것처럼 보입니다. 그런 경우라면, 음 ...,하지 마세요.) – Mat
'waitpid'를 올바르게 호출 했습니까? 당신이 보여준 코드에서 그 코드에 대한 호출을 볼 수는 없지만, 당신이 전달하는 상태가 '틀린'경우에는 놀라지 않을 것입니다. – Flexo
@Mat :'int i'을 넣는 것을 잊어 버렸습니다. 자식들은 단지'execve()'를 호출한다. – GeoffreyB