如何使一个函数异步信号安全的吗? [英] How to make a function async-signal-safe?
本文介绍了如何使一个函数异步信号安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下的的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, "%s\n", piderr);
printf(piderr);
}
abort();
}
有人告诉我,羊群
和的printf
不是异步信号安全的。我找不到在本作羊群
备用异步信号安全功能的列表。
Someone told me that flock
and printf
aren't async-signal-safe. And I could not find an alternate async-signal-safe function for flock
in this list.
和根据上述链接:
函数调用不安全的功能,这种行为是未定义
when a signal interrupts an unsafe function and the signal-catching function calls an unsafe function, the behavior is undefined
有没有一种方法,使羊群
异步信号安全的吗?或者有另一种解决方案来执行羊群
当我收到 TERM
信号?
Are there a way to make flock
async-signal-safe? Or is there another solution to execute flock
when I receive TERM
signal?
推荐答案
您可以使用的的fcntl()作为替代涌向()。
You can use fcntl() as an alternative to flock().
这篇关于如何使一个函数异步信号安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文