简体   繁体   English

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

[英]Is `signal()` a system call function on Linux?

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

NAME top NAME顶部

  signal - ANSI C signal handling 

SYNOPSIS top 大纲顶部

  #include <signal.h> typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); 

The situation on Linux is as follows: 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. 

The quote seems to me that signal() is not a system call but a wrapper function implemented based on system call sigaction() , except "The kernel's signal() system call". 引用在我看来, signal()不是系统调用,而是基于系统调用sigaction()实现的包装函数,除了“内核的signal()系统调用”。

So is signal() a system call function or not on Linux? 那么signal()是否是Linux上的系统调用函数?

The manpage for syscalls indicates the wrapper indirection is common, and has a list of Linux syscalls that includes signal(2) : syscalls的联机帮助页指示包装器间接是常见的,并且包含一个包含signal(2)的Linux系统调用列表:

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

There is a signal system call on Linux (see list of Linux system calls given by Jim). 在Linux上有一个signal系统调用(参见Jim给出的Linux系统调用列表)。 You never trap to a system call directly, you always call a wrapping function (at least you rarely generate the trap directly). 你永远不会直接陷入系统调用,你总是调用一个包装函数(至少你很少直接生成陷阱)。 As stated in the manual, signal() is just a wrapper to a system call that may not be the signal one (example is given for truncate in the document cited by @Jim). 正如在说明书中指出signal()是只是一个包装到一个系统调用可能不是signal酮(实施例给出了truncate由@Jim引用的文献中)。 The signal() function is in the libc and that library is free to implement that function the way it want provided that the semantic is preserved. signal()函数位于libc中,并且该库可以自由地实现该函数,前提是保留语义。 So as you mentioned a call to signal() may under given circumstances trap to signal system call or sigaction system call or whatever suitable. 因此,正如您所提到的,对signal()的调用可能在给定的情况下陷阱signal系统调用或sigaction系统调用或任何合适的。

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

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