`signal()`是Linux上的系统调用函数吗?

时间:2018-05-31 04:57:20

标签: c linux signals

来自signal() http://man7.org/linux/man-pages/man2/signal.2.html

的联系页面
  

姓名顶部

   signal - ANSI C signal handling
     

大纲顶部

   #include <signal.h>

   typedef void (*sighandler_t)(int);

   sighandler_t signal(int signum, sighandler_t handler);
     

Linux的情况如下:

   * The kernel's signal() system call provides System V semantics.

   * By default, in glibc 2 and later, the signal() wrapper function
     does not invoke the kernel system call.  Instead, it calls
     sigaction(2) using flags that supply BSD semantics.  This default
     behavior is provided as long as a suitable feature test macro is
     defined: _BSD_SOURCE on glibc 2.19 and earlier or _DEFAULT_SOURCE
     in glibc 2.19 and later.  (By default, these macros are defined;
     see feature_test_macros(7) for details.)  If such a feature test
     macro is not defined, then signal() provides System V semantics.

在我看来,signal()不是系统调用,而是基于系统调用sigaction()实现的包装函数,除了“内核的signal()系统调用”。

Linux上是否有signal()系统调用函数?

2 个答案:

答案 0 :(得分:4)

syscalls的联机帮助页指示包装器间接是常见的,并且包含一个包含signal(2)的Linux系统调用列表:

http://man7.org/linux/man-pages/man2/syscalls.2.html

答案 1 :(得分:4)

Linux上有一个signal系统调用(参见Jim给出的Linux系统调用列表)。你永远不会直接陷入系统调用,你总是调用一个包装函数(至少你很少直接生成陷阱)。如手册中所述,signal()只是系统调用的包装器,可能不是signal系统调用(在@Jim引用的文档中为truncate提供了示例)。 signal()函数位于libc中,只要保留了语义,该库就可以自由地实现该函数。正如您所提到的,signal()的调用可能会在特定情况下陷入signal系统调用或sigaction系统调用或任何合适的调用。