我已经为SIGABRT注册了信号处理程序。但只捕捉到了第一个信号。第二个或随后的信号转到SIG_DFL,程序终止。
下面是来自truss的应用程序进程id的代码片段。
/1: stat64("/zones/netiq/AM/log/nqmlog.lck", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/agent20160223061748.err", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/agent20160223052255.err", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/NqmAgt_4.log", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/NqmAgt_3.log", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/agent20160223052605.err", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/1.log", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/agent20160223061613.err", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/agent20160223052430.err", 0xFEFFE28C) = 0
/1: stat64("/zones/netiq/AM/log/NqmAgt_1.log", 0xFEFFE28C) = 0
/1: getdents64(5, 0xFC204000, 8192) = 0
/1: close(5) = 0
/1: statvfs64("/zones/netiq/AM", 0xFEFFE224) = 0
/7: lwp_park(0xFBB82DB8, 0) Err#62 ETIME
/10: lwp_park(0xFB885DB8, 0) Err#62 ETIME
/10: time() = 1456208362
/10: time() = 1456208362
/10: time() = 1456208362
/7: time() = 1456208362
/7: time() = 1456208362
/7: time() = 1456208362
/1: write(3, " [ 2 0 1 6 - 0 2 - 2 3 ".., 125) = 125
/1: time() = 1456208362
/1: write(3, " [ 2 0 1 6 - 0 2 - 2 3 ".., 665) = 665
/1: time() = 1456208362
/1: time() = 1456208362
/1: time() = 1456208362
/1: time() = 1456208362
/1: time() = 1456208362
/1: time() = 1456208362
/1: write(3, " [ 2 0 1 6 - 0 2 - 2 3 ".., 114) = 114
/1: write(3, " [ 2 0 1 6 - 0 2 - 2 3 ".., 168) = 168
/1: write(3, " [ 2 0 1 6 - 0 2 - 2 3 ".., 146) = 146
/1: lstat64("/zones/netiq/AM/data/Config_1", 0xFEFFE1E0) = 0
/1: rmdir("/zones/netiq/AM/data/Config_1") Err#17 EEXIST
/1: open("/zones/netiq/AM/data/Config_1", O_RDONLY|O_NDELAY|O_LARGEFILE|O_CLOEXEC|O_DIRECTORY) = 5
/1: fcntl(5, F_SETFD, 0x00000001) = 0
/1: fstat64(5, 0xFEFFE1A0) = 0
/1: pathconf("/zones/netiq/AM/data/Config_1", _PC_NAME_MAX) = 255
/1: lwp_kill(1, SIGABRT) = 0
/1: Received signal #6, SIGABRT [caught]
/1: siginfo: SIGABRT pid=27656 uid=100 code=-1
/1: lwp_sigmask(SIG_SETMASK, 0x00029000, 0x00000000, 0x00000000, 0x00000000) = 0xFFBFFEFF [0xFFFFFFFF]
/1: chdir("/zones/netiq/AM/bin") = 0
/1: setcontext(0xFEFFD8D0)
/1: sigaction(SIGABRT, 0xFEFFE080, 0xFEFFE100) = 0
/1: lwp_sigmask(SIG_SETMASK, 0x00029000, 0x00000000, 0x00000000, 0x00000000) = 0xFFBFFEFF [0xFFFFFFFF]
/1: lwp_kill(1, SIGABRT) = 0
/1: Received signal #6, SIGABRT [default]
/1: siginfo: SIGABRT pid=27656 uid=100 code=-1请告诉我该怎么做。
用于信号处理的代码
static void
SetSignals(void)
{
struct sigaction sa;
sa.sa_handler = signalHandler; /* Point to our signal handler func. */
sigemptyset(&sa.sa_mask); /* Clear mask */
/* Block delivery of these signals during receipt of any one of them */
sigaddset(&sa.sa_mask, SIGINT);
sigaddset(&sa.sa_mask, SIGTERM);
sigaddset(&sa.sa_mask, SIGSEGV);
sigaddset(&sa.sa_mask, SIGBUS);
sigaddset(&sa.sa_mask, SIGILL);
sigaddset(&sa.sa_mask, SIGTRAP);
sigaddset(&sa.sa_mask, SIGABRT);
sigaddset(&sa.sa_mask, SIGFPE);
sa.sa_flags = 0; /* No special flags */
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
sigaction(SIGILL, &sa, NULL);
sigaction(SIGTRAP, &sa, NULL);
sigaction(SIGABRT, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
/* Do nothing for SIGALRM. In release builds, it seems to kill us. */
sa.sa_handler = doNothingHandler;
sigemptyset(&sa.sa_mask); /* Clear mask */
sigaction(SIGALRM, &sa, NULL);
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask,SIGHUP);
sigaction(SIGHUP, &sa, NULL);
}信号处理程序:
static void
signalHandler(int signum)
{
char PathName[1024];
UA_LOG_COMPONENT(MAIN, "main::signalHandler" );
UA_LOG_BLOCK( DEBUG3 );
if (g_Settings.m_strBinaryPath.length()) {
strncpy(PathName, g_Settings.m_strBinaryPath, sizeof(PathName));
PathName[sizeof(PathName) - 1] = 0;
}
else
snprintf(PathName, sizeof(PathName), "%s/bin", g_Settings.m_strHomeDir.data());
if (chdir(PathName) == -1)
perror("UnixAgent: Could not change directory to UnixAgent home bin directory.");
if (signum == SIGINT) {
printf("UnixAgent: Got SIGINT\n");
bRunning = false;
}
if (signum == SIGSEGV) {
printf("UnixAgent: Got SIGSEGV\n");
bSigINT = true;
bRunning = false;
ShmUpdateSegv(signum);
}
else if (signum == SIGTERM) {
printf("UnixAgent: Got SIGTERM\n");
bRunning = false;
}
else if (signum == SIGHUP) {
printf("UnixAgent: Got SIGHUP\n");
}
}发布于 2016-02-25 03:51:24
如果您的Solaris使用与内华达州相同的abort (这里是abort.c source),它将调用用户安装的SIGABRT处理程序(如果设置了的话),然后进入无限循环,将SIGABRT的处理设置为SIG_DFL,然后引发信号。
如果您想要执行任何清理工作,只需调用您的处理程序就可以了。如果你不想让abort的其余部分运行,你可以用它做一个longjmp。
https://stackoverflow.com/questions/35600369
复制相似问题