简体   繁体   English

确定哪个信号中断了我的系统调用(Linux)

[英]Determining which signal interrupted my system call (Linux)

在我的系统调用由于被信号中断而返回后,是否有办法准确确定导致中断的信号类型(即子进程终止)?

You need to set an handler. 您需要设置一个处理程序。 Have a look here . 在这里看看。

There's a number of facilities in Linux to deal with signals: Linux中有许多工具可以处理信号:

  • waitpid(2) could be used to wait inline for SIGCHLD waitpid(2)可用于内联等待SIGCHLD
  • sigaction(2) could be used to setup handler functions to react to specific signals, the SA_RESTART flag here affects whether certain system calls are interrupted or restarted sigaction(2)可用于设置处理程序函数以对特定信号做出反应,此处的SA_RESTART标志会影响某些系统调用是中断还是重新启动
  • sigprocmask(2) could be used to block a number of signals sigprocmask(2)可用于阻止许多信号
  • sigwait(3) could be used to wait for number of signals inline sigwait(3)可用于等待内联信号数量
  • Latest kernels support signalfd(2) , which is convenient when one needs to combine signal handling and non-blocking IO. 最新的内核支持signalfd(2) ,当需要将信号处理和无阻塞IO结合使用时,这很方便。

Then there's the whole next level of complexity when we start talking about threads, though if you deal with signals explicitly you usually don't really care which signal interrupted the system call. 然后,当我们开始讨论线程时,就会出现整个复杂性的下一个层次,尽管如果您明确地处理信号,通常您并不在乎哪个信号会中断系统调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM