我有以下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();
- }
有人告诉我,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?