2

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

NAME top

   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:

   * 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".

So is signal() a system call function or not on Linux?

Tim
  • 1
  • 141
  • 372
  • 590

2 Answers2

4

The manpage for syscalls indicates the wrapper indirection is common, and has a list of Linux syscalls that includes signal(2):

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

4

There is a signal system call on Linux (see list of Linux system calls given by Jim). 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). 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. So as you mentioned a call to signal() may under given circumstances trap to signal system call or sigaction system call or whatever suitable.

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
  • Thanks. How do you explicitly specify that you want to use a system call or a wrapper function in your program? – Tim May 31 '18 at 05:13
  • Becareful, calling a system call is not a standard function call... Read @Tim https://stackoverflow.com/questions/13219501/accessing-a-system-call-directly-from-user-program – Jean-Baptiste Yunès May 31 '18 at 05:17
  • So is `signal()` appearing in a user program always a wrapper function instead of a system call function? – Tim May 31 '18 at 05:18
  • 1
    All so-called system calls in C are **always** wrapper functions. The distinction is rarely useful, and is therefore rarely made. This is like [The Treachery of Images](https://en.wikipedia.org/wiki/The_Treachery_of_Images), where an image of a tobacco pipe is labelled "this is not a pipe" because it's technically a painting and not a smoking implement. – that other guy May 31 '18 at 05:25