Scroll to navigation

SIGNAL(7) Linux - příručka programátora SIGNAL(7)

JMÉNO

signal - overview of signals

POPIS

V Linuxu jsou podporovány jak POSIX reliable signály (dále jen "standardní signály"), tak POSIX real-time signály.

Dispozice signálů

Každý signál má dispozici, která určuje, jak se proces zachová při jeho přijetí.

The entries in the "Action" column of the tables below specify the default disposition for each signal, as follows:

Výchozí akcí je ukončení procesu.
Výchozí akcí je ignorování signálu.
Výchozí akcí je ukončení procesu a výpis paměti (core dump) (viz core(5)).
Výchozí akcí je zastavení procesu.
Výchozí akcí je pokračování procesu, pokud je momentálně zastavený.

A process can change the disposition of a signal using sigaction(2) or signal(2). (The latter is less portable when establishing a signal handler; see signal(2) for details.) Using these system calls, a process can elect one of the following behaviors to occur on delivery of the signal: perform the default action; ignore the signal; or catch the signal with a signal handler, a programmer-defined function that is automatically invoked when the signal is delivered. (By default, the signal handler is invoked on the normal process stack. It is possible to arrange that the signal handler uses an alternate stack; see sigaltstack(2) for a discussion of how to do this and when it might be useful.)

Dispozice signálu je atribut procesu: v mnohovláknových aplikacích je dispozice určitého signálu stejná pro všechna vlákna.

A child created via fork(2) inherits a copy of its parent's signal dispositions. During an execve(2), the dispositions of handled signals are reset to the default; the dispositions of ignored signals are left unchanged.

Sending a signal

The following system calls and library functions allow the caller to send a signal:

raise(3)
Sends a signal to the calling thread.
kill(2)
Sends a signal to a specified process, to all members of a specified process group, or to all processes on the system.
killpg(3)
Sends a signal to all of the members of a specified process group.
pthread_kill(3)
Sends a signal to a specified POSIX thread in the same process as the caller.
tgkill(2)
Sends a signal to a specified thread within a specific process. (This is the system call used to implement pthread_kill(3).)
sigqueue(3)
Sends a real-time signal with accompanying data to a specified process.

Waiting for a signal to be caught

The following system calls suspend execution of the calling process or thread until a signal is caught (or an unhandled signal terminates the process):

pause(2)
Suspends execution until any signal is caught.
sigsuspend(2)
Temporarily changes the signal mask (see below) and suspends execution until one of the unmasked signals is caught.

Synchronously accepting a signal

Rather than asynchronously catching a signal via a signal handler, it is possible to synchronously accept the signal, that is, to block execution until the signal is delivered, at which point the kernel returns information about the signal to the caller. There are two general ways to do this:

  • sigwaitinfo(2), sigtimedwait(2), and sigwait(3) suspend execution until one of the signals in a specified set is delivered. Each of these calls returns information about the delivered signal.
  • signalfd(2) returns a file descriptor that can be used to read information about signals that are delivered to the caller. Each read(2) from this file descriptor blocks until one of the signals in the set specified in the signalfd(2) call is delivered to the caller. The buffer returned by read(2) contains a structure describing the signal.

Signal mask and pending signals

A signal may be blocked, which means that it will not be delivered until it is later unblocked. Between the time when it is generated and when it is delivered a signal is said to be pending.

Each thread in a process has an independent signal mask, which indicates the set of signals that the thread is currently blocking. A thread can manipulate its signal mask using pthread_sigmask(3). In a traditional single-threaded application, sigprocmask(2) can be used to manipulate the signal mask.

A child created via fork(2) inherits a copy of its parent's signal mask; the signal mask is preserved across execve(2).

A signal may be generated (and thus pending) for a process as a whole (e.g., when sent using kill(2)) or for a specific thread (e.g., certain signals, such as SIGSEGV and SIGFPE, generated as a consequence of executing a specific machine-language instruction are thread directed, as are signals targeted at a specific thread using pthread_kill(3)). A process-directed signal may be delivered to any one of the threads that does not currently have the signal blocked. If more than one of the threads has the signal unblocked, then the kernel chooses an arbitrary thread to which to deliver the signal.

A thread can obtain the set of signals that it currently has pending using sigpending(2). This set will consist of the union of the set of pending process-directed signals and the set of signals pending for the calling thread.

A child created via fork(2) initially has an empty pending signal set; the pending signal set is preserved across an execve(2).

Standardní Signály

Linux supports the standard signals listed below. Several signal numbers are architecture-dependent, as indicated in the "Value" column. (Where three values are given, the first one is usually valid for alpha and sparc, the middle one for x86, arm, and most other architectures, and the last one for mips. (Values for parisc are not shown; see the Linux kernel source for signal numbering on that architecture.) A dash (-) denotes that a signal is absent on the corresponding architecture.

First the signals described in the original POSIX.1-1990 standard.

Signál Hodnota Akce Poznámka
SIGHUP  1 Term "Hangup" - při zavěšení na řídícím terminálu
nebo ukončení řídícího procesu
SIGINT  2 Term "Interrupt" - přerušení z klávesnice
SIGQUIT  3 Core "Quit" - ukončení z klávesnice
SIGILL  4 Core "Illegal Instruction" - neplatná instrukce
SIGABRT  6 Core "Abort" - ukončení funkcí abort(3)
SIGFPE  8 Core "Floating point exception" - přetečení v pohyblivé řádové čárce
SIGKILL  9 Term "Kill" - signál pro nepodmíněné ukončení procesu
SIGSEGV 11 Core Odkaz na nepřípustnou adresu v paměti
SIGPIPE 13 Term "Broken pipe" - pokus o zápis do roury,
readers; see pipe(7)
SIGALRM 14 Term Signál od časovače, nastaveného funkcí alarm(1)
SIGTERM 15 Term "Termination" - signál ukončení
SIGUSR1 30,10,16 Term Signál 1 definovaný uživatelem
SIGUSR2 31,12,17 Term Signál 2 definovaný uživatelem
SIGCHLD 20,17,18 Ign Zastavení nebo ukončení dětského procesu
SIGCONT 19,18,25 Cont Pokračování po zastavení
SIGSTOP 17,19,23 Stop Zastavení procesu
SIGTSTP 18,20,24 Stop Stop typed at terminal
SIGTTIN 21,21,26 Stop Terminal input for background process
SIGTTOU 22,22,27 Stop Terminal output for background process

Signály SIGKILL a SIGSTOP nemohou být zachyceny, blokovány ani ignorovány.

Next the signals not in the POSIX.1-1990 standard but described in SUSv2 and POSIX.1-2001.

Signál Hodnota Akce Poznámka
SIGBUS 10,7,10 Core "Bus error" - pokus o přístup mimo mapovanou paměť
SIGPOLL Term Pollable event (Sys V).
Synonymum SIGIO
SIGPROF 27,27,29 Term Časovač používaný při profilování
SIGSYS 12,31,12 Core Bad system call (SVr4);
see also seccomp(2)
SIGTRAP 5 Core Přerušení při ladění (trasování,breakpoint)
SIGURG 16,23,21 Ign Soket přijal data s příznakem Urgent (4.2 BSD)
SIGVTALRM 26,26,28 Term Virtuální časovač (4.2 BSD)
SIGXCPU 24,24,30 Core Překročen limit času CPU (4.2 BSD);
viz setrlimit(2)
SIGXFSZ 25,25,31 Core Překročen limit velikosti souboru (4.2 BSD);
viz setrlimit(2)

Až po Linux 2.2 včetně bylo výchozí chování pro SIGSYS, SIGXCPU, SIGXFSZ, a (na architekturách jiných než SPARC a MIPS) SIGBUS ukončit proces (bez core dump). (Na některých jiných UNIXových systémech bylo výchozí akcí pro SIGXCPU a SIGXFSZ ukončení procesu bez core dump.) Linux 2.4 splňuje požadavky POSIX.1-2001 pro tyto signály, ukončuje procesy s core dump.

Next various other signals.

Signál Hodnota Akce Poznámka
SIGIOT 6 Core IOT - synonymum signálu SIGABRT
SIGEMT 7,-,7 Term Emulator trap
SIGSTKFLT -,16,- Term Chyba zásobníku koprocesoru (nepoužívá se)
SIGIO 23,29,22 Term Lze pokračovat ve vstupu/výstupu (4.2 BSD)
SIGCLD -,-,18 Ign Synonymum SIGCHLD
SIGPWR 29,30,19 Term Výpadek napájení (Systém V)
SIGINFO 29,-,- Synonymum SIGPWR
SIGLOST -,-,- Term Zámek souboru byl ztracen (nepoužívá se)
SIGWINCH 28,28,20 Ign Změna velikosti okna (4.3 BSD, Sun)
SIGUNUSED -,31,- Core Synonymous with SIGSYS

(Signal 29 is SIGINFO / SIGPWR on an alpha but SIGLOST on a sparc.)

SIGEMT není specifikován v POSIX.1-2001, ale stejně je přítomen na většině ostatních UNIXových systémů, kde je výchozí akcí obvykle ukončení procesu s core dump.

SIGPWR (není specifikován v POSIX.1-2001) na většině ostatních UNIXových systémů, kde se objevuje, je obvykle ignorován.

SIGIO (není specifikován v POSIX.1-2001) na některých dalších UNIXech je jako výchozí ignorován.

Where defined, SIGUNUSED is synonymous with SIGSYS on most architectures. Since glibc 2.26, SIGUNUSED is no longer defined on any architecture.

Real-time signály

Starting with version 2.2, Linux supports real-time signals as originally defined in the POSIX.1b real-time extensions (and now included in POSIX.1-2001). The range of supported real-time signals is defined by the macros SIGRTMIN and SIGRTMAX. POSIX.1-2001 requires that an implementation support at least _POSIX_RTSIG_MAX (8) real-time signals.

Linux podporuje 33 různých real-time signálů očíslovaných 32 až 64. Nicméně implementace POSIX threads v glibc používá interně dva (pro NPTL) nebo tři (pro LinuxThreads) real-time signály (viz pthreads(7)), a podle toho upravuje hodnotu SIGRTMIN (na 34 nebo 35). protože rozsah dostupných real-time signálů se liší v závislosti na implementaci vláken v glibc (může se měnit za běhu v závislosti na jádře a glibc) a navíc rozsah real-time signálů se mezi UNIXovými systémy liší, programy by nikdy neměly odkazovat na real-time signály pevně danými čísly, místo toho by měly používat notaci SIGRTMIN+n, a za běhu kontrolovat, zda SIGRTMIN+n nepřesahuje SIGRTMAX.

Na rozdíl od standardních signálů nemají real-time signály stanovený význam: Celá sada real-time signálů může být použita pro účely definované aplikací.

Výchozí akcí pro nezpracovaný real-time signál je ukončení procesu, který jej přijal.

Real-time signály se liší následujícně:

1.
Vícero instancí real-time signálů může být zařazeno do fronty. Naopak pokud je doručeno vícero instancí standardního signálu, zatímco je signál blokován, je do fronty zařazen jen jeden.
2.
Pokud je signál poslán pomocí sigqueue(3), může s ním být poslána doprovodná hodnota (integer nebo pointer). Pokud přijímací proces vytvoří pro tento signál handler pomocí vlajky SA_SIGINFO pro sigaction(2), tak může tato data získat v poli si_value struktury siginfo_t předané jako druhý argument handleru. Navíc mohou být pole si_pid a si_uid této struktury použita k získání PID a real user ID procesu, který signál poslal.
3.
Real-time signály jsou doručeny v zaručeném pořadí. Vícero real-time signálů stejného typu je doručeno v pořadí, v jakém byly vyslány. Pokud jsou procesu poslány různé real-time signály, jsou doručeny v pořadí podle čísla, začínajíc nejnižším (tj. signály s nízkým číslem mají vyšší prioritu). Naopak, pokud na proces čeká vícero standardních signálů, není pořadí jejich doručení definováno.

Pokud má proces nevyřízené zároveň real-time a standardní signály, POSIX neurčuje, které mají být doručeny jako první. Linux, stejně jako mnoho jiných implementací, v takovém případě upřednostňí standardní signály.

Podle POSIX by měla implementace pro frontu procesu povolit alespoň _POSIX_SIGQUEUE_MAX (32) real-time signálů. Linux ale pracuje jinak. V jádrech do 2.6.7 včetně stanovuje Linux celosystémový limit na počet real-time signálů ve frontách všech procesů. tento limit je možné zjistit a (s patřičnými právy) změnit přes soubor /proc/sys/kernel/rtsig-max. Další soubor, /proc/sys/kernel/rtsig-nr, může být použit ke zjištění, kolik real-time signálů je momentálně ve frontách. V Linuxu 2.6.8 byla tato /proc rozhraní nahrazena limitem zdrojů RLIMIT_SIGPENDING, který určuje uživatelský limit na počet signálů ve frontách; více viz setrlimit(2).

The addition of real-time signals required the widening of the signal set structure (sigset_t) from 32 to 64 bits. Consequently, various system calls were superseded by new system calls that supported the larger signal sets. The old and new system calls are as follows:

Jádro 2.0 a dřívější Linux 2.2 and later
sigaction(2) rt_sigaction(2)
sigpending(2) rt_sigpending(2)
sigprocmask(2) rt_sigprocmask(2)
sigreturn(2) rt_sigreturn(2)
sigsuspend(2) rt_sigsuspend(2)
sigtimedwait(2) rt_sigtimedwait(2)

Přerušení systémových volání a funkcí knihoven prostřednictvím "signal handlers"

Pokud je signal handler vyvolán v okamžiku, kdy je systémové volání nebo funkce knihovny blokována, pak:

  • je volání automaticky restartováno po návratu signal handleru, nebo
  • volání selže s chybou EINTR.

Která z těchto možností nastane, záleží na rozhraní a na tom, zda byl signal handler definován s pomocí vlajky SA_RESTART (viz sigaction(2)). Podrobnosti se mezi UNIXovými systémy liší; dále jsou uvedeny pro Linux.

If a blocked call to one of the following interfaces is interrupted by a signal handler, then the call is automatically restarted after the signal handler returns if the SA_RESTART flag was used; otherwise the call fails with the error EINTR:

The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:

Funkce sleep(3) se také při přerušení signal handlerem nerestartuje, nýbrž vrátí úspěch: počet sekund, které zbývají ke spaní.

Přerušení systémovách volání a funkcí knihoven signály Stop

V Linuxu mohou některá blokující rozhraní selhat s chybou EINTR i bez signal handlerů, pokud je proces zastaven jedním ze stop signálů a poté obnoven pomocí SIGCONT. Toto chování neodporuje POSIX.1 a neobjevuje se v jiných systémech.

Linuxová rozhraní, v nichž se toto chování projevuje, jsou:

SPLŇUJE STANDARDY

POSIX.1, s uvedenými výjimkami.

POZNÁMKY

For a discussion of async-signal-safe functions, see signal-safety(7).

DALŠÍ INFORMACE

kill(1), getrlimit(2), kill(2), restart_syscall(2), rt_sigqueueinfo(2), setitimer(2), setrlimit(2), sgetmask(2), sigaction(2), sigaltstack(2), signal(2), signalfd(2), sigpending(2), sigprocmask(2), sigreturn(2), sigsuspend(2), sigwaitinfo(2), abort(3), bsd_signal(3), killpg(3), longjmp(3), pthread_sigqueue(3), raise(3), sigqueue(3), sigset(3), sigsetops(3), sigvec(3), sigwait(3), strsignal(3), sysv_signal(3), core(5), proc(5), nptl(7), pthreads(7), sigevent(7)

TIRÁŽ

Tato stránka je součástí projektu Linux man-pages v4.16. Popis projektu a informace o hlášení chyb najdete na https://www.kernel.org/doc/man-pages/.

PŘEKLAD

Překlad této příručky do španělštiny vytvořili Marek Kubita <Kubitovi@mbox.lantanet.cz> a Pavel Heimlich <tropikhajma@gmail.com>

Tento překlad je bezplatná dokumentace; Přečtěte si GNU General Public License Version 3 nebo novější ohledně podmínek autorských práv. Neexistuje ŽÁDNÁ ODPOVĚDNOST.

Pokud narazíte na nějaké chyby v překladu této příručky, pošlete e-mail na adresu translation-team-cs@lists.sourceforge.net.

15. září 2017 Linux