sem_timedwait 会被signal的信号唤醒及处理办法
2015-12-24 14:56
513 查看
一直都在使用sem_timedwait 函数用来处理超时等待应答.但是突然发现 没有收到应答.竟然返回了.查了半天竟然是signal(SIGALRM, ....)的原因.man 了一下 sem_timedwait
RETURN VALUE
All of these functions return 0 on success; on error, the value of the
semaphore is left unchanged, -1 is returned, and errno is set to indi‐
cate the error.
ERRORS
EINTR The call was interrupted by a signal handler; see signal(7).这里说了.确实会被唤醒.没办法只能该程序忽略这个信号
int _wait_sem( int sec, char *pack_str_t)
{
struct timespec ts;
int sts;
sem_t *wSem;
wSem = &jf2414_acksem;
p_ack_str = pack_str_t;
ts.tv_sec = time(0) + sec; //important
ts.tv_nsec = 0;
/* Try to lock Semaphore */
sem_init (wSem, 0, 0);//set sem is 0
while ( 1 )
{
sts = sem_timedwait(wSem, &ts);
if(sts == 0)
{
printf("rec ack\n");
sem_destroy(wSem);
return 0;
}
else
{
if(errno == ETIMEDOUT)
{
printf("sem timout\n");
sem_destroy(wSem);
return -1;
}
// else if(errno == EINTR)
// {
// continue;//忽略其它signal信号
// }
}
}
}
RETURN VALUE
All of these functions return 0 on success; on error, the value of the
semaphore is left unchanged, -1 is returned, and errno is set to indi‐
cate the error.
ERRORS
EINTR The call was interrupted by a signal handler; see signal(7).这里说了.确实会被唤醒.没办法只能该程序忽略这个信号
int _wait_sem( int sec, char *pack_str_t)
{
struct timespec ts;
int sts;
sem_t *wSem;
wSem = &jf2414_acksem;
p_ack_str = pack_str_t;
ts.tv_sec = time(0) + sec; //important
ts.tv_nsec = 0;
/* Try to lock Semaphore */
sem_init (wSem, 0, 0);//set sem is 0
while ( 1 )
{
sts = sem_timedwait(wSem, &ts);
if(sts == 0)
{
printf("rec ack\n");
sem_destroy(wSem);
return 0;
}
else
{
if(errno == ETIMEDOUT)
{
printf("sem timout\n");
sem_destroy(wSem);
return -1;
}
// else if(errno == EINTR)
// {
// continue;//忽略其它signal信号
// }
}
}
}
相关文章推荐
- offsetof和container_of两个内核中的宏
- http://blog.csdn.net/yichenlian/article/details/37055393
- vs2010解决LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
- Codeforces Round #336 (Div. 2) A. Saitama Destroys Hotel 模拟
- Raid5磁盘阵列修复方法介绍
- failed to import ova file
- AIDL和远程Service调用
- rails里面的撤销操作
- UVA-11167 Monkeys in the Emei Mountain(区间模型最大流+输出方案)
- chai3d中的全局坐标和局部坐标作用
- 进程间通讯AIDL的使用
- 博客开通,AnyCai
- 控制AI战车前轮左右转弯的脚本
- HP机器RAID和LVM创建
- DELL磁盘阵列控制卡(RAID卡)MegaCli常用管理命令汇总
- [经典小题一道] 在浏览器中输入:http://www.baidu.com/后到底发生了神马?
- 人工智能初体验(二):开发简单的图灵智能聊天工具
- http://blog.csdn.net/tswisdom/article/details/41823881
- MYSQL 错误 :Out of resources when opening file './datagather/mx_domain#P#p178.MYD' (Errcode: 24) 解决办法
- 利用spark进行层次社团发现(louvain算法测试)