Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
SIGACTION(2)		  FreeBSD System Calls Manual		  SIGACTION(2)

     sigaction -- software signal facilities

     Standard C	Library	(libc, -lc)

     #include <signal.h>

     struct  sigaction {
	     void    (*sa_handler)(int);
	     int     sa_flags;		     /*	see signal options below */
	     sigset_t sa_mask;		     /*	signal mask to apply */

     sigaction(int sig,	const struct sigaction * restrict act,
	 struct	sigaction * restrict oact);

     Signal delivery resembles the occurrence of a hardware interrupt: the
     signal is normally	blocked	from further occurrence, the current thread
     by	the system when	a signal occurs.  A signal may also be blocked for a
     thread, in	which case it will not be delivered to that thread until it is
     the thread.  This may be changed, on a per-handler	basis, so that signals
     are taken on a special signal stack.

     Signal routines normally execute with the signal that caused their	invo-
     defines the set of	signals	currently blocked from delivery	to a thread.
     The signal	mask for a thread is initialized from that of its parent (nor-
     mally empty).  It may be changed with a sigprocmask(2) or
     pthread_sigmask(3)	call, or when a	signal is delivered to the thread.

     When a signal condition arises for	a process or thread, the signal	is
     added to a	set of signals pending for the process or thread.  Whether the
     signal is directed	at the process in general or at	a specific thread
     depends on	how it is generated.  For signals directed at a	specific
     thread, if	the signal is not currently blocked by the thread then it is
     delivered to the thread.  For signals directed at the process, if the
     signal is not currently blocked by	all threads then it is delivered to
     one thread	that does not have it blocked (the selection of	which is
     unspecified).  Signals may	be delivered any time a	thread enters the
     to	interrupt the handlers for the previous	signals	before their first
     instructions.  The	set of pending signals is returned by the
     sigpending(2) system call.	 When a	caught signal is delivered, the	cur-
     rent state	of the thread is saved,	a new signal mask is calculated	(as
     handler is	arranged so that if the	signal handling	routine	returns	nor-
     mally the thread will resume execution in the context from	before the
     signal's delivery.	 If the	thread wishes to resume	in a different con-
     text, then	it must	arrange	to restore the previous	context	itself.

     When a signal is delivered	to a thread a new signal mask is installed for
     associated	with the handler to be invoked.

     sig.  If act is non-NULL, it specifies an action (SIG_DFL,	SIG_IGN, or a
     nal.  If oact is non-NULL,	the previous handling information for the sig-
     nal is returned to	the user.

     The above declaration of struct sigaction is not literal.	It is provided
     only to list the accessible members.  See <sys/signal.h> for the actual
     definition.  In particular, the storage occupied by sa_handler and
     sa_sigaction overlaps, and	it is nonsensical for an application to
     attempt to	use both simultaneously.

     Once a signal handler is installed, it normally remains installed until
     signal-specific default action may	be reset by setting sa_handler to
     nal list below for	each signal's default action.  If sa_handler is
     instances of the signal are ignored and discarded.

     bits is as	follows:

	   SA_NOCLDSTOP	   If this bit is set when installing a	catching func-
			   tion	for the	SIGCHLD	signal,	the SIGCHLD signal
			   will	be generated only when a child process exits,
			   not when a child process stops.

			   SIGCHLD signal, the system will not create zombie
			   processes when children of the calling process
			   exit.  If the calling process subsequently issues a
			   calling process's child processes terminate,	and
			   then	returns	a value	of -1 with errno set to
			   ECHILD.  The	same effect of avoiding	zombie cre-
			   ation can also be achieved by setting sa_handler
			   for SIGCHLD to SIG_IGN.

	   SA_ONSTACK	   If this bit is set, the system will deliver the
			   signal to the process on a signal stack, specified
			   by each thread with sigaltstack(2).

	   SA_NODEFER	   If this bit is set, further occurrences of the
			   delivered signal are	not masked during the execu-
			   tion	of the handler.

			   SIG_DFL at the moment the signal is delivered.

	   SA_RESTART	   See paragraph below.

	   SA_SIGINFO	   If this bit is set, the handler function is assumed
			   to be pointed to by the sa_sigaction	member of
			   struct sigaction and	should match the prototype
			   shown above or as below in EXAMPLES.	 This bit
			   should not be set when assigning SIG_DFL or

     Restart of	pending	calls is requested by setting the SA_RESTART bit in
     short read	count).

     After a pthread_create(3) the signal mask is inherited by the new thread
     and the set of pending signals and	the signal stack for the new thread
     are empty.


     that restart pending system calls continue	to do so.


     NAME	     Default Action	     Description
     SIGHUP	     terminate process	     terminal line hangup
     SIGINT	     terminate process	     interrupt program
     SIGQUIT	     create core image	     quit program
     SIGILL	     create core image	     illegal instruction
     SIGTRAP	     create core image	     trace trap
     SIGEMT	     create core image	     emulate instruction executed
     SIGFPE	     create core image	     floating-point exception
     SIGKILL	     terminate process	     kill program
     SIGBUS	     create core image	     bus error
     SIGSEGV	     create core image	     segmentation violation
     SIGSYS	     create core image	     non-existent system call invoked
     SIGPIPE	     terminate process	     write on a	pipe with no reader
     SIGALRM	     terminate process	     real-time timer expired
     SIGTERM	     terminate process	     software termination signal
     SIGURG	     discard signal	     urgent condition present on
     SIGSTOP	     stop process	     stop (cannot be caught or
     SIGTSTP	     stop process	     stop signal generated from
     SIGCONT	     discard signal	     continue after stop
     SIGCHLD	     discard signal	     child status has changed
     SIGTTIN	     stop process	     background	read attempted from
					     control terminal
     SIGTTOU	     stop process	     background	write attempted	to
					     control terminal
     SIGIO	     discard signal	     I/O is possible on	a descriptor
					     (see fcntl(2))
     SIGXCPU	     terminate process	     cpu time limit exceeded (see
     SIGXFSZ	     terminate process	     file size limit exceeded (see
     SIGVTALRM	     terminate process	     virtual time alarm	(see
     SIGPROF	     terminate process	     profiling timer alarm (see
     SIGWINCH	     discard signal	     window size change
     SIGINFO	     discard signal	     status request from keyboard
     SIGUSR1	     terminate process	     user defined signal 1
     SIGUSR2	     terminate process	     user defined signal 2

     SIGSTOP.  Any attempt to do so will be silently ignored.

     The following functions are either	reentrant or not interruptible by sig-
     without restriction, from signal-catching functions or from a child
     process after calling fork(2) in a	multi-threaded process:

     Base Interfaces:

     _Exit(), _exit(), accept(), access(), alarm(), bind(), cfgetispeed(),
     fchownat(), fcntl(), fork(), fstat(), fstatat(), fsync(), ftruncate(),
     mkfifo(), mkfifoat(), mknod(), mknodat(), open(), openat(), pause(),
     sockatmark(), socket(), socketpair(), stat(), symlink(), symlinkat(),

     X/Open Systems Interfaces:

     sigpause(), sigset(), utimes().

     Realtime Interfaces:

     aio_error(), clock_gettime(), timer_getoverrun(), aio_return(),
     fdatasync(), sigqueue(), timer_gettime(), aio_suspend(), sem_post(),

     Base Interfaces not specified as async-signal safe	by POSIX:

     fpathconf(), pathconf(), sysconf().

     Base Interfaces not specified as async-signal safe	by POSIX, but planned
     to	be:

     ffs(), htonl(), htons(), memccpy(), memchr(), memcmp(), memcpy(),
     memmove(),	memset(), ntohl(), ntohs(), stpcpy(), stpncpy(), strcat(),
     strchr(), strcmp(), strcpy(), strcspn(), strlen(),	strncat(), strncmp(),
     strncpy(),	strnlen(), strpbrk(), strrchr(), strspn(), strstr(),
     strtok_r(), wcpcpy(), wcpncpy(), wcscat(),	wcschr(), wcscmp(), wcscpy(),
     wcscspn(),	wcslen(), wcsncat(), wcsncmp(),	wcsncpy(), wcsnlen(),
     wcspbrk(),	wcsrchr(), wcsspn(), wcsstr(), wcstok(), wmemchr(), wmemcmp(),
     wmemcpy(),	wmemmove(), wmemset().

     Extension Interfaces:

     accept4(),	bindat(), closefrom(), connectat(), eaccess(), ffsl(),
     ffsll(), flock(), fls(), flsl(), flsll(), futimesat(), pipe2(),
     strlcat().	 strlcpy(), strsep().

     In	addition, reading or writing errno is async-signal safe.

     respect to	signals.  That is to say, the behaviour	of such	functions is
     undefined when they are called from a signal handler that interrupted an
     unsafe function.  In general though, signal handlers should do little
     more than set a flag; most	other actions are not safe.

     restore it	before returning from the signal handler.  This	protects
     against the side effect of	errno being set	by functions called from
     inside the	signal handler.


     There are three possible prototypes the handler may match:

	   ANSI	C:
		  void handler(int);

	   Traditional BSD style:


     The handler function should match the SA_SIGINFO prototype	if the
     sa_sigaction member of struct sigaction.  Note that you should not	assign
     SIG_DFL or	SIG_IGN	this way.

     sa_handler	member of struct sigaction.  In	practice, FreeBSD always sends
     subset, both will work.  The sa_handler member declaration	in FreeBSD


     info argument to a	SA_SIGINFO handler contain a numeric code explaining
     values for	SIGFPE.



     installed if one of the following occurs:



     kill(1), kill(2), ptrace(2), setitimer(2),	setrlimit(2), sigaltstack(2),
     setjmp(3),	siginfo(3), siginterrupt(3), sigsetops(3), ucontext(3),	tty(4)

     and SA_RESETHAND flags are	intended for backwards compatibility with
     other operating systems.  The SA_NOCLDSTOP, and SA_NOCLDWAIT flags	are
     featuring options commonly	found in other operating systems.  The flags
     along with	the option to avoid zombie creation by ignoring	SIGCHLD.

FreeBSD	Ports 11.2		 June 28, 2018		    FreeBSD Ports 11.2


Want to link to this manual page? Use this URL:

home | help