在测试一个程序时,通过写的信号退出函数,我们处理了SIGTERM信号, 收到SIGTERM信号后,进程调用信号处理函数,但是当调用处理函数后,进程没有退出,通过GDB跟踪发现一个问题,进程执行堆栈如下:
#0 0x000000351a6f806e in __lll_lock_wait_private () from /lib64/libc.so.6
#1 0x000000351a69de5d in _L_lock_2163 () from /lib64/libc.so.6
#2 0x000000351a69dc17 in __tz_convert () from /lib64/libc.so.6
#3 0x0000000000409362 in GetCurrentZmtDTime (aiZoneTm=0x7fff1224a3f4) at /root/zqy/0528/src/base/ait_base_log.c:892
#4 0x0000000000409b77 in XHandleOutput (fmt=0x44890e "close socket sock[%d]", ap=0x7fff1224a460) at /root/zqy/0528/src/base/ait_base_log.c:1434
#5 0x0000000000409dc5 in LogOutput (iLevel=600, iLogCode=0, fmt=0x44890e "close socket sock[%d]") at /root/zqy/0528/src/base/ait_base_log.c:1470
#6 0x000000000040cb49 in tCloseSocket (piSockFd=0x65b1b0) at /root/zqy/0528/src/base/ait_base_socket.c:1575
#7 0x000000000041cc12 in tAfsExitHandler (iSigno=15) at /root/zqy/0528/src/busi/ait_busi_afs.c:46
#8 0x0000000000403f96 in ExitAfs (iSignal=15) at sys_afs.c:174
#9
#10 0x000000351a6daf25 in _xstat () from /lib64/libc.so.6
#11 0x000000351a69e650 in __tzfile_read () from /lib64/libc.so.6
#12 0x000000351a69dad4 in tzset_internal () from /lib64/libc.so.6
#13 0x000000351a69dc39 in __tz_convert () from /lib64/libc.so.6
#14 0x00000000004102c3 in tGetSysTime (iTimeType=1) at /root/zqy/0528/src/base/ait_base_util.c:312
#15 0x0000000000423b8e in tAskBase (cObject=1 '\001', cType=65 'A') at /root/zqy/0528/src/busi/ait_busi_afs_file.c:272
#16 0x000000000042ed36 in AskBaseTable (cProType=65 'A') at /root/zqy/0528/src/busi/ait_busi_afs_sync.c:3610
#17 0x000000000041dd20 in tSyncPeerDoc (sFile=0x7fff1224add0 "150529", AskBaseTable=0x42ec74 ) at /root/zqy/0528/src/busi/ait_busi_afs.c:428
#18 0x0000000000404647 in main (argc=1, argv=0x7fff1224af28) at sys_afs.c:339
信号处理函数后,调用日志输出,日志里面打印日期,因此调用GetCurrentZmtDTime 函数获取日期时间
void GetCurrentZmtDTime(INT32 aiZoneTm[6])
{
time_t tt ;
struct tm tv ;
time(&tt);
localtime_r(&tt,&tv);
aiZoneTm[0] = tv.tm_year +1900;
aiZoneTm[1] = tv.tm_mon + 1 ;
aiZoneTm[2] = tv.tm_mday ;
aiZoneTm[3] = tv.tm_hour ;
aiZoneTm[4] = tv.tm_min ;
aiZoneTm[5] = tv.tm_sec ;
}
这个函数又只调用了取时间的函数,从堆栈来看,应该是死锁了,__lll_lock_wait_private等待释放锁,而在堆栈#13里面的函数可能也加了锁,信号退出函数里面有又读了时间,并且时间应该是个临界资源, 不管读写,都要进行上锁处理,因此导致进程无法退出。
阅读(4404) | 评论(0) | 转发(0) |