signal(2) System Calls Manual signal(2) JMENO signal - prace se signaly v ANSI C KNIHOVNA Standardni knihovna C (libc, -lc) POUZITI #include typedef void (*sighandler_t)(int); sighandler_t signal(int signum, sighandler_t handler); POPIS WARNING: the behavior of signal() varies across UNIX versions, and has also varied historically across different versions of Linux. Avoid its use: use sigaction(2) instead. See Portability below. Systemove volani signal() instaluje novou obsluznou funkci pro signal s cislem signum. Obsluha signalu je nastavena na handler, coz muze byt uzivatelsky definovana funkce nebo SIG_IGN pripadne SIG_DFL. Pokud je signal signum prijat procesem, stane se jedna z nasledujicich veci: * Je-li nastaveno SIG_IGN signal je ignorovan. * If the disposition is set to SIG_DFL, then the default action associated with the signal (see signal(7)) occurs. * Pokud je dispozice nastavena na funkci, pak je nejdriv bud znovu nastavena dispozice na SIG_DFL nebo je signal blokovan (viz Prenositelnost nize) a obsluzna funkce je volana s parametrem signum. Pokud volani funkce zablokovalo signal, je signal odblokovan pri navratu z obsluzne funkce. Signaly SIGKILL a SIGSTOP nemohou byt odchyceny nebo blokovany. NAVRATOVE HODNOTY signal() returns the previous value of the signal handler. On failure, it returns SIG_ERR, and errno is set to indicate the error. CHYBOVE STAVY EINVAL signum je neplatny. VERZE The use of sighandler_t is a GNU extension, exposed if _GNU_SOURCE is defined; glibc also defines (the BSD-derived) sig_t if _BSD_SOURCE (glibc 2.19 and earlier) or _DEFAULT_SOURCE (glibc 2.19 and later) is defined. Without use of such a type, the declaration of signal() is the somewhat harder to read: void ( *signal(int signum, void (*handler)(int)) ) (int); Prenositelnost Jedine prenositelne pouziti funkce signal() je nastavit obsluhu signalu na SIG_DFL nebo SIG_IGN. Semantika pouziti signal() na nastaveni obsluhy signalu se lisi na ruznych systemech (a POSIX.1 tot explicitne podporuje). Proto jej nepouzivejte za timto ucelem. POSIX.1 vyresil tento nesoulad v prenositelnosti zavedenim sigaction(2), ktery poskytuje explicitni kontrolu semantiky v pripade vyvolani obsluhy signalu. Pouzivejte jej proto misto signal()u. STANDARDY C11, POSIX.1-2008. HISTORIE C89, POSIX.1-2001. In the original UNIX systems, when a handler that was established using signal() was invoked by the delivery of a signal, the disposition of the signal would be reset to SIG_DFL, and the system did not block delivery of further instances of the signal. This is equivalent to calling sigaction(2) with the following flags: sa.sa_flags = SA_RESETHAND | SA_NODEFER; System V also provides these semantics for signal(). This was bad because the signal might be delivered again before the handler had a chance to reestablish itself. Furthermore, rapid deliveries of the same signal could result in recursive invocations of the handler. BSD improved on this situation, but unfortunately also changed the semantics of the existing signal() interface while doing so. On BSD, when a signal handler is invoked, the signal disposition is not reset, and further instances of the signal are blocked from being delivered while the handler is executing. Furthermore, certain blocking system calls are automatically restarted if interrupted by a signal handler (see signal(7)). The BSD semantics are equivalent to calling sigaction(2) with the following flags: sa.sa_flags = SA_RESTART; Situace na Linuxu je nasledujici: o Systemove volani jadra signal() poskytuje System V semantiku. o 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. POZNAMKY Efekt funkce signal() v procesech s vlakny nejsou specifikovany. Dle specifikace POSIX je chovani systemu nespecifikovano, pokud ignoruje SIGFPE, SIGILL nebo SIGSEGV signal pokud nebyl vyvolan pomoci kill(2) nebo raise(3). Celociselne deleni nulou ma nedefinovany vysledek. Na nekterych architekturach se generuje SIGFRE signal. (Take deleni nejvetsiho zaporneho celeho cisla -1 generuje SIGFRE). Ignorovani tohoto signalu muze vest k nekonecne smycce. See sigaction(2) for details on what happens when the disposition SIGCHLD is set to SIG_IGN. Viz signal-safety(7) pro seznam asynchronnich bezpecnych funkci, ktere mohou byt bezpecne volany uvnitr funkce pro obsluhu signalu. DALSI INFORMACE kill(1), alarm(2), kill(2), pause(2), sigaction(2), signalfd(2), sigpending(2), sigprocmask(2), sigsuspend(2), bsd_signal(3), killpg(3), raise(3), siginterrupt(3), sigqueue(3), sigsetops(3), sigvec(3), sysv_signal(3), signal(7) PREKLAD Preklad teto prirucky do spanelstiny vytvorili Marek Kubita a Pavel Heimlich Tento preklad je bezplatna dokumentace; Prectete si GNU General Public License Version 3 nebo novejsi ohledne podminek autorskych prav. Neexistuje ZADNA ODPOVEDNOST. Pokud narazite na nejake chyby v prekladu teto prirucky, poslete e-mail na adresu . Linux man-pages 6.06 31. rijna 2023 signal(2)