加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何使函数异步信号安全?

发布时间:2020-12-16 03:35:36 所属栏目:百科 来源:网络整理
导读:我有以下sigaction处理函数 void signal_term_handler(int sig){ printf("EXIT :TERM signal Received!n"); int rc = flock(pid_file,LOCK_UN | LOCK_NB); if(rc) { char *piderr = "PID file unlock failed!"; fprintf(stderr,"%sn",piderr); printf(pide
我有以下sigaction处理函数
void signal_term_handler(int sig)
{
    printf("EXIT :TERM signal Received!n");
    int rc = flock(pid_file,LOCK_UN | LOCK_NB);
    if(rc) {
        char *piderr = "PID file unlock failed!";
        fprintf(stderr,"%sn",piderr);
        printf(piderr);
    }
    abort();
}

有人告诉我,flock和printf不是异步信号安全的.而且我找不到另一个异步信号安全函数flockin这个list.

并根据以上链接:

when a signal interrupts an unsafe function and the signal-catching
function calls an unsafe function,the behavior is undefined

有没有办法使flock异步信号安全?或者,当我收到TERM信号时,是否有另一种解决方案来执行flock?

解决方法

您可以使用 fcntl()作为flock()的替代方法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读