I m working on an Unix-Shell, using C langage.
I use waitpid to wait my processes to terminate and i want to know if my son process (created with fork()
) received a signal like SIGSEGV
.
现行法典:
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
", 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)
", pid);
if (WIFEXITED(*status))
*status = WEXITSTATUS(*status);
else
**print_sigerr(*status);**
return (ret == -1 ? (1) : ret);
}
<代码>xwaitpid在括号中注明。
看来,即使我执行像<条码>false >、真实>/代码”这样的指挥,也总是返回西非。
有些人有一个可以帮助我的良好想法?
->见我的回答,感谢。