Man page - signal(7)
Packages contains this manual
- shm_overview(7)
- nss(5)
- proc_mtrr(5)
- intro(7)
- tcp(7)
- iso_8859-9(7)
- armscii-8(7)
- proc_kpagecount(5)
- initrd(4)
- mouse(4)
- proc_stat(5)
- x25(7)
- proc_interrupts(5)
- fifo(7)
- repertoiremap(5)
- icmp(7)
- futex(7)
- feature_test_macros(7)
- lp(4)
- bpf-helpers(7)
- epoll(7)
- proc_sys_dev(5)
- namespaces(7)
- proc_sysrq-trigger(5)
- proc_bus(5)
- cp1251(7)
- proc_pid_maps(5)
- proc_sys_vm(5)
- proc_pid_projid_map(5)
- st(4)
- proc_pid(5)
- issue(5)
- pid_namespaces(7)
- unicode(7)
- inode(7)
- hosts.equiv(5)
- iso-8859-13(7)
- proc_fb(5)
- proc_modules(5)
- proc_pid_autogroup(5)
- keyrings(7)
- sysvipc(7)
- proc_kmsg(5)
- cgroups(7)
- latin6(7)
- proc_pid_uid_map(5)
- unix(7)
- proc_pid_io(5)
- pts(4)
- packet(7)
- ld-linux.so(8)
- tzselect(8)
- iconv(1)
- proc_pid_syscall(5)
- proc_pid_net(5)
- proc_pid_pagemap(5)
- tty(4)
- proc_profile(5)
- standards(7)
- proc_pid_mounts(5)
- filesystems(5)
- iso-8859-15(7)
- locale(5)
- iso_8859_3(7)
- xattr(7)
- iso-8859-2(7)
- proc_uptime(5)
- persistent-keyring(7)
- credentials(7)
- proc_pid_timers(5)
- utmpx(5)
- vcsa(4)
- proc_pid_exe(5)
- proc_net(5)
- proc_timer_stats(5)
- ip(7)
- proc_pid_fd(5)
- ptmx(4)
- user_namespaces(7)
- resolv.conf(5)
- url(7)
- iso_8859_5(7)
- iso_8859-8(7)
- urn(7)
- process-keyring(7)
- proc_pid_auxv(5)
- proc_ksyms(5)
- proc_ide(5)
- veth(4)
- ldd(1)
- proc_swaps(5)
- landlock(7)
- proc_vmstat(5)
- system_data_types(7)
- cp1252(7)
- lirc(4)
- proc_kpageflags(5)
- random(7)
- precedence(7)
- cpuset(7)
- proc_pid_ns(5)
- acct(5)
- latin4(7)
- proc_pid_cgroup(5)
- proc_cpuinfo(5)
- iso_8859-2(7)
- proc_keys(5)
- charsets(7)
- pldd(1)
- proc_pid_stat(5)
- rtnetlink(7)
- netlink(7)
- ram(4)
- mem(4)
- iso-8859-6(7)
- proc_key-users(5)
- iso_8859_15(7)
- fanotify(7)
- proc_sys_net(5)
- sysfs(5)
- math_error(7)
- latin1(7)
- proc_pid_root(5)
- nptl(7)
- proc_cgroups(5)
- proc_iomem(5)
- proc_pid_statm(5)
- sem_overview(7)
- hier(7)
- full(4)
- proc_pid_status(5)
- proc_pid_cwd(5)
- proc_pid_cpuset(5)
- proc_scsi(5)
- uri(7)
- proc_diskstats(5)
- iso_8859_6(7)
- latin2(7)
- latin5(7)
- man-pages(7)
- ld.so(8)
- uts_namespaces(7)
- proc_pid_mountstats(5)
- intro(3)
- proc_pid_seccomp(5)
- proc_pid_wchan(5)
- attributes(7)
- symlink(7)
- mount_namespaces(7)
- charmap(5)
- tis-620(7)
- iso-8859-10(7)
- getent(1)
- proc_buddyinfo(5)
- ttytype(5)
- rtc(4)
- proc_malloc(5)
- suffixes(7)
- sln(8)
- signal(7)
- proc_sys_abi(5)
- signal-safety(7)
- time_namespaces(7)
- proc_pid_comm(5)
- raw(7)
- gai.conf(5)
- proc_crypto(5)
- locale(1)
- iso-8859-3(7)
- motd(5)
- proc_meminfo(5)
- iso-8859-8(7)
- protocols(5)
- proc_pid_map_files(5)
- pthreads(7)
- null(4)
- proc(5)
- zdump(8)
- socket(7)
- proc_sys_kernel(5)
- ddp(7)
- memusagestat(1)
- hd(4)
- iso-8859-14(7)
- shells(5)
- pipe(7)
- glob(7)
- proc_self(5)
- network_namespaces(7)
- utmp(5)
- proc_kcore(5)
- nsswitch.conf(5)
- sd(4)
- iso-8859-5(7)
- iso_8859_16(7)
- man(7)
- iso_8859-6(7)
- dir_colors(5)
- mq_overview(7)
- vsock(7)
- ascii(7)
- thread-keyring(7)
- fs(5)
- proc_pid_attr(5)
- proc_sys_debug(5)
- proc_sys(5)
- proc_pid_cmdline(5)
- pty(7)
- services(5)
- cgroup_namespaces(7)
- securetty(5)
- netdevice(7)
- iso_8859_13(7)
- host.conf(5)
- proc_pid_setgroups(5)
- proc_slabinfo(5)
- sock_diag(7)
- iso_8859-14(7)
- iso-8859-11(7)
- iso_8859_11(7)
- operator(7)
- regex(7)
- wavelan(4)
- proc_sys_fs(5)
- nologin(5)
- proc_pci(5)
- koi8-r(7)
- erofs(5)
- intro(2)
- utf8(7)
- proc_kallsyms(5)
- proc_sysvipc(5)
- queue(7)
- proc_sys_sunrpc(5)
- intro(5)
- latin8(7)
- mtrace(1)
- ipc_namespaces(7)
- dsp56k(4)
- iso_8859_4(7)
- proc_pid_smaps(5)
- proc_cmdline(5)
- rpc(5)
- proc_tty(5)
- proc_version(5)
- smartpqi(4)
- proc_pid_timerslack_ns(5)
- aio(7)
- session-keyring(7)
- resolver(5)
- slabinfo(5)
- wtmp(5)
- iso_8859_9(7)
- proc_locks(5)
- mailaddr(7)
- proc_pid_oom_score(5)
- kmem(4)
- iconvconfig(8)
- iso_8859-7(7)
- glibc(7)
- hostname(7)
- proc_thread-self(5)
- ipv6(7)
- iso_8859_7(7)
- proc_kpagecgroup(5)
- core(5)
- time(7)
- units(7)
- proc_dma(5)
- loop(4)
- address_families(7)
- zero(4)
- intro(4)
- procfs(5)
- iso_8859-4(7)
- vdso(7)
- tmpfs(5)
- iso-8859-16(7)
- iso_8859_10(7)
- user-session-keyring(7)
- libc(7)
- proc_fs(5)
- koi8-u(7)
- latin3(7)
- proc_tid_children(5)
- proc_pid_limits(5)
- proc_pid_coredump_filter(5)
- iso_8859-15(7)
- arp(7)
- urandom(4)
- iso_8859-10(7)
- hpsa(4)
- proc_pid_environ(5)
- boot(7)
- ftm(7)
- ld-linux(8)
- proc_driver(5)
- loop-control(4)
- iso_8859-16(7)
- proc_filesystems(5)
- tzfile(5)
- sprof(1)
- proc_pid_task(5)
- proc_pid_oom_score_adj(5)
- proc_mounts(5)
- iso-8859-4(7)
- iso_8859-1(7)
- utf-8(7)
- iso_8859-13(7)
- intro(6)
- proc_timer_list(5)
- rtld-audit(7)
- iso_8859-3(7)
- group(5)
- sched(7)
- proc_pid_clear_refs(5)
- hosts(5)
- iso_8859-11(7)
- numa(7)
- iso_8859_2(7)
- locale(7)
- iso-8859-1(7)
- fuse(4)
- proc_tid(5)
- proc_execdomains(5)
- proc_pid_mountinfo(5)
- intro(8)
- iso_8859_8(7)
- proc_loadavg(5)
- proc_pid_oom_adj(5)
- re_format(7)
- iso_8859_14(7)
- zic(8)
- bootparam(7)
- inotify(7)
- posixoptions(7)
- proc_partitions(5)
- iso-8859-9(7)
- proc_pid_mem(5)
- networks(5)
- proc_sys_user(5)
- udp(7)
- proc_zoneinfo(5)
- latin10(7)
- proc_pid_fdinfo(5)
- proc_pid_stack(5)
- memusage(1)
- spufs(7)
- pkeys(7)
- path_resolution(7)
- proc_ioports(5)
- intro(1)
- ldconfig(8)
- msr(4)
- svipc(7)
- port(4)
- proc_pid_personality(5)
- cciss(4)
- latin9(7)
- capabilities(7)
- localedef(1)
- vcs(4)
- iso_8859-5(7)
- elf(5)
- proc_sys_proc(5)
- console_codes(4)
- random(4)
- iso-8859-7(7)
- termcap(5)
- cpuid(4)
- environ(7)
- string_copying(7)
- proc_pid_gid_map(5)
- queue(3)
- termio(7)
- user-keyring(7)
- complex(7)
- latin7(7)
- proc_config.gz(5)
- udplite(7)
- kernel_lockdown(7)
- proc_devices(5)
- proc_apm(5)
- iso_8859_1(7)
- proc_pid_numa_maps(5)
apt-get install manpages
Available languages:
en fr it pl cs ja ru zh_TW zh_CN deManual
SIGNAL
名 前説 明
シ グ ナ ル 処 理 方 法
シ グ ナ ル の 送 信
シ グ ナ ル が 捕 捉 さ れ る の を 待 つ
シ グ ナ ル の 同 期 受 信
シ グ ナ ル マ ス ク と 処 理 待 ち シ グ ナ ル
Execution of signal handlers
標 準 シ グ ナ ル
Queueing and delivery semantics for standard signals
Signal numbering for standard signals
リ ア ル タ イ ム シ グ ナ ル
シ グ ナ ル ハ ン ド ラ ー に よ る シ ス テ ム コ ー ル や ラ イ ブ ラ リ 関 数 へ の 割 り 込 み
一 時 停 止 シ グ ナ ル に よ る シ ス テ ム コ ー ル や ラ イ ブ ラ リ 関 数 へ の 割 り 込 み
準 拠
注 意
バ グ
関 連 項 目
こ の 文 書 に つ い て
名 前
signal - シ グ ナ ル の 概 要
説 明
Linux は POSIX 信 頼 シ グ ナ ル (reliable signal; 以 後 "標 準 シ グ ナ ル "と 表 記 ) と POSIX リ ア ル タ イ ム シ グ ナ ル の 両 方 に 対 応 し て い る 。
シ グ ナ ル 処 理 方 法
シ グ ナ ル は そ れ ぞ れ 現 在 の 「 処 理 方 法 (disposition)」 を 保 持 し て お り 、 こ の 処 理 方 法 に よ り シ グ ナ ル が 配 送 さ れ た 際 に プ ロ セ ス が ど の よ う な 振 舞 い を す る か が 決 ま る 。
後 述 の 表 の "動 作 " の 欄 の エ ン ト リ ー は 各 シ グ ナ ル の デ フ ォ ル ト の 処 理 方 法 を 示 し て お り 、 以 下 の よ う な 意 味 を 持 つ 。
|
Term |
デ フ ォ ル ト の 動 作 は プ ロ セ ス 終 了 。 |
|||
|
Ign |
デ フ ォ ル ト の 動 作 は こ の シ グ ナ ル の 無 視 。 |
|||
|
Core |
デ フ ォ ル ト の 動 作 は プ ロ セ ス 終 了 と コ ア ダ ン プ 出 力 ( core (5) 参 照 )。 |
|||
|
Stop |
デ フ ォ ル ト の 動 作 は プ ロ セ ス の 一 時 停 止 。 |
|||
|
Cont |
デ フ ォ ル ト の 動 作 は 、 プ ロ セ ス が 停 止 中 の 場 合 に そ の 実 行 の 再 開 。 |
プ ロ セ ス は 、 sigaction (2) や signal (2) を 使 っ て 、 シ グ ナ ル の 処 理 方 法 を 変 更 す る こ と が で き る ( signal (2) の 方 が シ グ ナ ル ハ ン ド ラ ー を 設 定 す る 際 の 移 植 性 が 低 い ; 詳 細 は signal (2) を 参 照 )。 シ グ ナ ル の 配 送 時 に 起 こ る 動 作 と し て プ ロ セ ス が 選 択 で き る の は 、 次 の い ず れ か 一 つ で あ る 。 デ フ ォ ル ト の 動 作 を 実 行 す る 、 シ グ ナ ル を 無 視 す る 、 シ グ ナ ル ハ ン ド ラ ー (signal handler) で シ グ ナ ル を 捕 捉 す る 。 シ グ ナ ル ハ ン ド ラ ー と は 、 シ グ ナ ル 配 送 時 に 自 動 的 に 起 動 さ れ る プ ロ グ ラ マ 定 義 の 関 数 で あ る 。
デ フ ォ ル ト で は 、 シ グ ナ ル ハ ン ド ラ ー は 通 常 の プ ロ セ ス の ス タ ッ ク 上 で 起 動 さ れ る 。 シ グ ナ ル ハ ン ド ラ ー が 代 替 ス タ ッ ク (alternate stack) を 使 用 す る よ う に 設 定 す る こ と も で き る 。 代 替 ス タ ッ ク を 使 用 す る よ う に 設 定 す る 方 法 と 、 ど の よ う な 際 に 代 替 ス タ ッ ク が 役 に 立 つ か に つ い て の 議 論 に つ い て は sigaltstack (2) を 参 照 の こ と 。
シ グ ナ ル の 処 理 方 法 は プ ロ セ ス 単 位 の 属 性 で あ る 。 マ ル チ ス レ ッ ド の ア プ リ ケ ー シ ョ ン で は 、 あ る シ グ ナ ル の 処 理 方 法 は 全 て の ス レ ッ ド で 同 じ で あ る 。
fork (2) 経 由 で 作 成 さ れ た 子 プ ロ セ ス は 、 親 プ ロ セ ス の シ グ ナ ル の 処 理 方 法 の コ ピ ー を 継 承 す る 。 execve (2) の 前 後 で 、 ハ ン ド ラ ー が 設 定 さ れ て い る シ グ ナ ル の 処 理 方 法 は デ フ ォ ル ト に リ セ ッ ト さ れ 、 無 視 が 設 定 さ れ て い る シ グ ナ ル の 処 理 方 法 は 変 更 さ れ ず そ の ま ま と な る 。
シ グ ナ ル の 送 信
以
下 の シ ス テ ム
コ ー ル と ラ イ
ブ ラ リ 関 数 を
使 っ て 、 呼 び
出 し 者 は シ グ
ナ ル を 送 信 す
る こ と が で き
る 。
raise
(3)
呼 び 出 し た ス レ ッ ド に シ グ ナ ル を 送 る 。
kill (2)
指 定 さ れ た プ ロ セ ス や 、 指 定 さ れ た プ ロ セ ス グ ル ー プ の 全 メ ン バ ー 、 シ ス テ ム の 全 プ ロ セ ス に シ グ ナ ル を 送 る 。
pidfd_send_signal (2)
Sends a signal to a process identified by a PID file descriptor.
killpg (3)
指 定 さ れ た プ ロ セ ス グ ル ー プ の 全 メ ン バ ー に シ グ ナ ル を 送 る 。
pthread_kill (3)
呼 び 出 し 者 と 同 じ プ ロ セ ス 内 の 指 定 さ れ た POSIX ス レ ッ ド に シ グ ナ ル を 送 る 。
tgkill (2)
指 定 さ れ た プ ロ セ ス 内 の 指 定 さ れ た ス レ ッ ド に シ グ ナ ル を 送 る (こ の シ ス テ ム コ ー ル を 使 っ て pthread_kill (3) は 実 装 さ れ て い る )。
sigqueue (3)
指 定 さ れ た プ ロ セ ス に 付 属 デ ー タ と と も に リ ア ル タ イ ム シ グ ナ ル を 送 る 。
シ グ ナ ル が 捕 捉 さ れ る の を 待 つ
以
下 の シ ス テ ム
コ ー ル を 使 っ
て 、 シ グ ナ ル
が 捕 捉 さ れ る
ま で 呼 び 出 し
た ス レ ッ ド の
実 行 を 中 断 (suspend)
す る こ と が で
き る (ハ ン ド ラ
ー が 設 定 さ れ
て い な い シ グ
ナ ル に よ り そ
の プ ロ セ ス が
終 了 し た 場 合
に も 実 行 の 停
止 は 終 了 す る
)。
pause
(2)
何 か シ グ ナ ル が 捕 捉 さ れ る ま で 実 行 を 停 止 す る 。
sigsuspend (2)
一 時 的 に シ グ ナ ル マ ス ク (下 記 参 照 ) を 変 更 し 、 マ ス ク さ れ て い な い シ グ ナ ル の い ず れ か が 捕 捉 さ れ る ま で 実 行 を 中 断 す る 。
シ グ ナ ル の 同 期 受 信
シ グ ナ ル ハ ン ド ラ ー 経 由 で シ グ ナ ル を 非 同 期 (asynchronously) で 捕 捉 す る 以 外 に も 、 シ グ ナ ル を 同 期 (synchronously) し て 受 け 付 け る こ と も で き る 。 同 期 し て 受 け 付 け る と は 、 シ グ ナ ル が 配 送 さ れ る ま で 実 行 を 停 止 (block) す る と い う こ と で あ る 。 シ グ ナ ル を 受 け 付 け た 際 に 、 カ ー ネ ル は そ の シ グ ナ ル に 関 す る 情 報 を 呼 び 出 し 者 に 返 す 。 こ れ を 行 う 一 般 的 な 方 法 が 二 つ あ る 。
|
* |
sigwaitinfo (2), sigtimedwait (2), sigwait (3) は 、 指 定 さ れ た シ グ ナ ル 集 合 の シ グ ナ ル の 一 つ が 配 送 さ れ る ま で 実 行 を 中 断 す る 。 ど の シ ス テ ム コ ー ル や 関 数 で も 、 配 送 さ れ た シ グ ナ ル に 関 す る 情 報 が 返 さ れ る 。 |
||
|
* |
signalfd (2) が 返 す フ ァ イ ル デ ィ ス ク リ プ タ ー を 使 う と 、 呼 び 出 し 元 に 配 送 さ れ た シ グ ナ ル に 関 す る 情 報 を 読 み 出 す こ と が で き る 。 こ の フ ァ イ ル デ ィ ス ク リ プ タ ー か ら の read (2) は 、 signalfd (2) の 呼 び 出 し 時 に 指 定 さ れ た シ グ ナ ル 集 合 の シ グ ナ ル の 一 つ が 呼 び 出 し 元 に 配 送 さ れ る ま で 停 止 (block) す る 。 read (2) が 返 す バ ッ フ ァ ー に は シ グ ナ ル に 関 す る 情 報 を 格 納 し た 構 造 体 が 入 っ て い る 。 |
シ グ ナ ル マ ス ク と 処 理 待 ち シ グ ナ ル
シ グ ナ ル は ブ ロ ッ ク (block) さ れ る こ と が あ る 。 ブ ロ ッ ク さ れ る と 、 そ の シ グ ナ ル は そ の 後 ブ ロ ッ ク を 解 除 さ れ る ま で 配 送 さ れ な く な る 。 シ グ ナ ル が 生 成 さ れ て か ら 配 送 さ れ る ま で の 間 、 そ の シ グ ナ ル は 処 理 待 ち (pending) で あ る と 呼 ば れ る 。
プ ロ セ ス 内 の 各 ス レ ッ ド は 、 そ れ ぞ れ 独 立 な シ グ ナ ル マ ス ク (signal mask) を 持 つ 。 シ グ ナ ル マ ス ク は そ の ス レ ッ ド が 現 在 ブ ロ ッ ク し て い る シ グ ナ ル 集 合 を 示 す も の で あ る 。 ス レ ッ ド は 、 pthread_sigmask (3) を 使 っ て 自 分 の シ グ ナ ル マ ス ク を 操 作 で き る 。 伝 統 的 な シ ン グ ル ス レ ッ ド の ア プ リ ケ ー シ ョ ン で は 、 sigprocmask (2) を 使 っ て 、 シ グ ナ ル マ ス ク を 操 作 で き る 。
fork (2) 経 由 で 作 成 さ れ た 子 プ ロ セ ス は 親 プ ロ セ ス の シ グ ナ ル マ ス ク の コ ピ ー を 継 承 す る 。 execve (2) の 前 後 で シ グ ナ ル マ ス ク は 保 持 さ れ る 。
A signal may be process-directed or thread-directed. A process-directed signal is one that is targeted at (and thus pending for) the process as a whole. A signal may be process-directed because it was generated by the kernel for reasons other than a hardware exception, or because it was sent using kill (2) or sigqueue (3). A thread-directed signal is one that is targeted at a specific thread. A signal may be thread-directed because it was generated as a consequence of executing a specific machine-language instruction that triggered a hardware exception (e.g., SIGSEGV for an invalid memory access, or SIGFPE for a math error), or because it was targeted at a specific thread using interfaces such as tgkill (2) or 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.
ス レ ッ ド は 、 sigpending (2) を 使 っ て 、 現 在 処 理 待 ち の シ グ ナ ル 集 合 を 取 得 す る こ と が で き る 。 こ の 集 合 は 、 プ ロ セ ス 宛 て の 処 理 待 ち シ グ ナ ル と 呼 び 出 し た ス レ ッ ド 宛 て の シ グ ナ ル の 両 方 か ら 構 成 さ れ る 。
fork (2) 経 由 で 作 成 さ れ た 子 プ ロ セ ス で は 、 処 理 待 ち の シ グ ナ ル 集 合 は 空 の 集 合 で 初 期 化 さ れ る 。 execve (2) の 前 後 で 、 処 理 待 ち の シ グ ナ ル 集 合 は 保 持 さ れ る 。
Execution of signal handlers
Whenever there is a transition from kernel-mode to user-mode execution (e.g., on return from a system call or scheduling of a thread onto the CPU), the kernel checks whether there is a pending unblocked signal for which the process has established a signal handler. If there is such a pending signal, the following steps occur:
|
1. |
The kernel performs the necessary preparatory steps for execution of the signal handler: |
a)
|
The signal is removed from the set of pending signals. |
|||
|
b) |
If the signal handler was installed by a call to sigaction (2) that specified the SA_ONSTACK flag and the thread has defined an alternate signal stack (using sigaltstack (2)), then that stack is installed. |
||
|
c) |
Various pieces of signal-related context are saved into a special frame that is created on the stack. The saved information includes: |
+
|
the program counter register (i.e., the address of the next instruction in the main program that should be executed when the signal handler returns); |
|||
|
+ |
architecture-specific register state required for resuming the interrupted program; |
||
|
+ |
the thread’s current signal mask; |
||
|
+ |
the thread’s alternate signal stack settings. |
(If the signal handler was installed using the sigaction (2) SA_SIGINFO flag, then the above information is accessible via the ucontext_t object that is pointed to by the third argument of the signal handler.)
|
d) |
Any signals specified in act->sa_mask when registering the handler with sigprocmask (2) are added to the thread’s signal mask. The signal being delivered is also added to the signal mask, unless SA_NODEFER was specified when registering the handler. These signals are thus blocked while the handler executes. |
||
|
2. |
The kernel constructs a frame for the signal handler on the stack. The kernel sets the program counter for the thread to point to the first instruction of the signal handler function, and configures the return address for that function to point to a piece of user-space code known as the signal trampoline (described in sigreturn (2)).
|
3. |
The kernel passes control back to user-space, where execution commences at the start of the signal handler function. |
||
|
4. |
When the signal handler returns, control passes to the signal trampoline code. |
||
|
5. |
The signal trampoline calls sigreturn (2), a system call that uses the information in the stack frame created in step 1 to restore the thread to its state before the signal handler was called. The thread’s signal mask and alternate signal stack settings are restored as part of this procedure. Upon completion of the call to sigreturn (2), the kernel transfers control back to user space, and the thread recommences execution at the point where it was interrupted by the signal handler. |
Note that if the signal handler does not return (e.g., control is transferred out of the handler using siglongjmp (3), or the handler executes a new program with execve (2)), then the final step is not performed. In particular, in such scenarios it is the programmer’s responsibility to restore the state of the signal mask (using sigprocmask (2)), if it is desired to unblock the signals that were blocked on entry to the signal handler. (Note that siglongjmp (3) may or may not restore the signal mask, depending on the savesigs value that was specified in the corresponding call to sigsetjmp (3).)
From the kernel’s point of view, execution of the signal handler code is exactly the same as the execution of any other user-space code. That is to say, the kernel does not record any special state information indicating that the thread is currently excuting inside a signal handler. All necessary state information is maintained in user-space registers and the user-space stack. The depth to which nested signal handlers may be invoked is thus limited only by the user-space stack (and sensible software design!).
標 準 シ グ ナ ル
Linux supports the standard signals listed below. The second column of the table indicates which standard (if any) specified the signal: "P1990" indicates that the signal is described in the original POSIX.1-1990 standard; "P2001" indicates that the signal was added in SUSv2 and POSIX.1-2001.
シ グ ナ ル SIGKILL と SIGSTOP は キ ャ ッ チ 、 ブ ロ ッ ク 、 無 視 で き な い 。
Linux 2.2 以 前 で は 、 SIGSYS , SIGXCPU , SIGXFSZ お よ び SPARC と MIPS 以 外 の ア ー キ テ ク チ ャ ー で の SIGBUS の デ フ ォ ル ト の 振 る 舞 い は (コ ア ダ ン プ 出 力 な し の ) プ ロ セ ス 終 了 で あ っ た 。 (他 の UNIX シ ス テ ム に も SIGXCPU と SIGXFSZ の デ フ ォ ル ト の 動 作 が コ ア ダ ン プ な し の プ ロ セ ス 終 了 の も の が あ る 。 ) Linux 2.4 で は 、 POSIX.1-2001 で の 要 求 仕 様 に 準 拠 し て 、 こ れ ら の シ グ ナ ル で 、 プ ロ セ ス を 終 了 さ せ 、 コ ア ダ ン プ を 出 力 す る よ う に な っ て い る 。
SIGEMT は POSIX.1-2001 に 規 定 さ れ て い な い が 、 そ の 他 の 多 く の UNIX シ ス テ ム に 存 在 す る 。 デ フ ォ ル ト の 動 作 は 多 く の 場 合 、 コ ア ダ ン プ 出 力 を 伴 う プ ロ セ ス の 終 了 で あ る 。
SIGPWR は (POSIX.1-2001 に 規 定 さ れ て い な い が ) こ の シ グ ナ ル が 存 在 す る 他 の UNIX シ ス テ ム で は 多 く の 場 合 、 デ フ ォ ル ト 動 作 は 無 視 で あ る 。
SIGIO は (POSIX.1-2001 に 規 定 さ れ て い な い が ) い く つ か の 他 の UNIX シ ス テ ム で は デ フ ォ ル ト 動 作 は 無 視 で あ る 。
Queueing and delivery semantics for standard signals
If multiple standard signals are pending for a process, the order in which the signals are delivered is unspecified.
Standard signals do not queue. If multiple instances of a standard signal are generated while that signal is blocked, then only one instance of the signal is marked as pending (and the signal will be delivered just once when it is unblocked). In the case where a standard signal is already pending, the siginfo_t structure (see sigaction (2)) associated with that signal is not overwritten on arrival of subsequent instances of the same signal. Thus, the process will receive the information associated with the first instance of the signal.
Signal numbering for standard signals
The numeric value for each signal is given in the table below. As shown in the table, many signals have different numeric values on different architectures. The first numeric value in each table row shows the signal number on x86, ARM, and most other architectures; the second value is for Alpha and SPARC; the third is for MIPS; and the last is for PARISC. A dash (-) denotes that a signal is absent on the corresponding architecture.
Note the following:
|
* |
Where defined, SIGUNUSED is synonymous with SIGSYS . Since glibc 2.26, SIGUNUSED is no longer defined on any architecture. |
||
|
* |
Signal 29 is SIGINFO / SIGPWR (synonyms for the same value) on Alpha but SIGLOST on SPARC. |
リ ア ル タ イ ム シ グ ナ ル
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.
The Linux kernel supports a range of 33 different real-time signals, numbered 32 to 64. However, the glibc POSIX threads implementation internally uses two (for NPTL) or three (for LinuxThreads) real-time signals (see pthreads (7)), and adjusts the value of SIGRTMIN suitably (to 34 or 35). Because the range of available real-time signals varies according to the glibc threading implementation (and this variation can occur at run time according to the available kernel and glibc), and indeed the range of real-time signals varies across UNIX systems, programs should never refer to real-time signals using hard-coded numbers , but instead should always refer to real-time signals using the notation SIGRTMIN +n, and include suitable (run-time) checks that SIGRTMIN +n does not exceed SIGRTMAX .
標 準 シ グ ナ ル と 異 な り 、 リ ア ル タ イ ム シ グ ナ ル に は 事 前 に 定 義 さ れ た 意 味 は な い 。 リ ア ル タ イ ム シ グ ナ ル の 全 部 を ア プ リ ケ ー シ ョ ン で 定 義 し た 用 途 に 使 え る 。
ハ ン ド リ ン グ し な い リ ア ル タ イ ム シ グ ナ ル の デ フ ォ ル ト の 動 作 は 受 信 し た プ ロ セ ス の 終 了 で あ る 。
リ ア ル タ イ ム シ グ ナ ル は 以 下 の 特 徴 が あ る :
|
1. |
リ ア ル タ イ ム シ グ ナ ル は 複 数 の 実 体 を キ ュ ー に 入 れ る こ と が で き る 。 一 方 、 標 準 シ グ ナ ル の 場 合 、 そ の シ グ ナ ル が ブ ロ ッ ク さ れ て い る 間 に 同 じ シ グ ナ ル の 複 数 の イ ン ス タ ン ス が 配 送 さ れ て も 、 1 つ だ け が キ ュ ー に 入 れ ら れ る 。 |
||
|
2. |
シ グ ナ ル が sigqueue (3) を 用 い て 送 信 さ れ た 場 合 、 付 属 デ ー タ (整 数 か ポ イ ン タ ー ) を シ グ ナ ル と 共 に 送 信 で き る 。 受 信 側 プ ロ セ ス が sigaction (2) に SA_SIGINFO フ ラ グ を 指 定 し て シ グ ナ ル ハ ン ド ラ ー を 設 定 し た 場 合 、 こ の デ ー タ は siginfo_t 構 造 体 の si_value フ ィ ー ル ド 経 由 で ハ ン ド ラ ー の 第 2 引 数 と し て 渡 さ れ 、 利 用 す る こ と が で き る 。 さ ら に 、 こ の 構 造 体 の si_pid と si_uid フ ィ ー ル ド で シ グ ナ ル を 送 信 し た プ ロ セ ス の PID と 実 ユ ー ザ ー ID を 得 る こ と が で き る 。 |
||
|
3. |
リ ア ル タ イ ム シ グ ナ ル で は 配 送 さ れ る 順 序 が 保 証 さ れ る 。 同 じ タ イ プ の リ ア ル タ イ ム シ グ ナ ル は 送 信 さ れ た 順 番 に 到 着 す る 。 異 な る リ ア ル タ イ ム シ グ ナ ル が 一 つ の プ ロ セ ス に 送 信 さ れ た 場 合 、 番 号 の 小 さ い シ グ ナ ル か ら 先 に 到 着 す る 。 (つ ま り 小 さ い 番 号 の シ グ ナ ル が 高 い 優 先 順 位 を 持 つ 。 ) 対 照 的 に 、 一 つ の プ ロ セ ス に 対 し て 複 数 の 標 準 シ グ ナ ル が 処 理 待 ち と な っ た 場 合 、 こ れ ら の シ グ ナ ル が 配 送 さ れ る 順 序 は 不 定 で あ る 。 |
一 つ の プ ロ セ ス に 対 し て 標 準 シ グ ナ ル と リ ア ル タ イ ム シ グ ナ ル の 両 方 が 処 理 待 ち の 場 合 、 POSIX は ど ち ら が 先 に 配 送 さ れ る か を 規 定 し て い な い 。 Linux で は 、 他 の 多 く の 実 装 と 同 様 、 こ の よ う な 場 合 に は 標 準 シ グ ナ ル が 優 先 さ れ る 。
POSIX に よ れ ば 、 1 プ ロ セ ス 毎 に 最 低 _POSIX_SIGQUEUE_MAX (32) 個 の リ ア ル タ イ ム シ グ ナ ル を キ ュ ー に 入 れ ら れ る べ き と し て い る 。 し か し 、 Linux で は 違 っ た 実 装 に な っ て い る 。 カ ー ネ ル 2.6.7 ま で は (2.6.7 を 含 む )、 全 プ ロ セ ス で キ ュ ー に 入 っ て い る リ ア ル タ イ ム シ グ ナ ル の 数 の 合 計 に つ い て シ ス テ ム 全 体 で の 制 限 が あ る 。 こ の 制 限 は /proc/sys/kernel/rtsig-max フ ァ イ ル で 見 る こ と が で き 、 (権 限 が あ れ ば ) 変 更 も で き る 。 関 係 す る フ ァ イ ル と し て 、 /proc/sys/kernel/rtsig-nr を 見 る こ と で 、 い く つ の リ ア ル タ イ ム シ グ ナ ル が 現 在 キ ュ ー に 入 っ て い る か を 知 る こ と が で き る 。 Linux 2.6.8 で 、 こ れ ら の /proc 経 由 の イ ン タ ー フ ェ ー ス は 、 RLIMIT_SIGPENDING リ ソ ー ス 制 限 に 置 き 換 え ら れ た 。 こ れ は 、 キ ュ ー に 入 る シ グ ナ ル 数 に 関 し て ユ ー ザ ー 単 位 に 上 限 を 指 定 す る も の で あ る 。 詳 し く は 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:
シ グ ナ ル ハ ン ド ラ ー に よ る シ ス テ ム コ ー ル や ラ イ ブ ラ リ 関 数 へ の 割 り 込 み
シ ス テ ム コ ー ル や ラ イ ブ ラ リ が 停 止 (block) し て い る 間 に シ グ ナ ル ハ ン ド ラ ー が 起 動 さ れ る と 、 以 下 の ど ち ら か と な る 。
|
* |
シ グ ナ ル が 返 っ た 後 、 呼 び 出 し は 自 動 的 に 再 ス タ ー ト さ れ る 。 |
|||
|
* |
呼 び 出 し は エ ラ ー EINTR で 失 敗 す る 。 |
こ れ ら の 二 つ の 挙 動 の う ち ど ち ら が 起 こ る か は 、 イ ン タ ー フ ェ イ ス に よ り 依 存 し 、 シ グ ナ ル ハ ン ド ラ ー が SA_RESTART フ ラ グ ( sigaction (2) 参 照 ) を 使 っ て 設 定 さ れ て い た か に も 依 存 す る 。 詳 細 は UNIX シ ス テ ム に よ っ て 異 な る 。 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 :
|
* |
read (2), readv (2), write (2), writev (2), and ioctl (2) calls on "slow" devices. A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. If an I/O call on a slow device has already transferred some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred). Note that a (local) disk is not a slow device according to this definition; I/O operations on disk devices are not interrupted by signals. |
||
|
* |
停 止 (block) す る 可 能 性 の あ る open (2) (例 え ば 、 FIFO の オ ー プ ン 時 ; fifo (7) 参 照 )。 |
||
|
* |
wait (2), wait3 (2), wait4 (2), waitid (2), waitpid (2). |
||
|
* |
ソ ケ ッ ト イ ン タ ー フ ェ イ ス : accept (2), connect (2), recv (2), recvfrom (2), recvmmsg (2), recvmsg (2), send (2), sendto (2), sendmsg (2). 但 し 、 ソ ケ ッ ト に タ イ ム ア ウ ト が 設 定 さ れ て い な い 場 合 (下 記 参 照 )。 |
||
|
* |
フ ァ イ ル ロ ッ ク 用 イ ン タ ー フ ェ イ ス : flock (2), fcntl (2) の F_SETLKW と F_OFD_SETLKW 操 作 。 |
||
|
* |
POSIX メ ッ セ ー ジ キ ュ ー イ ン タ ー フ ェ イ ス : mq_receive (3), mq_timedreceive (3), mq_send (3), mq_timedsend (3). |
||
|
* |
futex (2) FUTEX_WAIT (Linux 2.6.22 以 降 ; そ れ 以 前 は 常 に EINTR で 失 敗 し て い た )。 |
||
|
* |
getrandom (2). |
||
|
* |
pthread_mutex_lock (3), pthread_cond_wait (3) と 関 連 API。 |
||
|
* |
futex (2) FUTEX_WAIT_BITSET . |
||
|
* |
POSIX セ マ フ ォ イ ン タ ー フ ェ イ ス : sem_wait (3), sem_timedwait (3) (Linux 2.6.22 以 降 ; そ れ 以 前 は 常 に EINTR で 失 敗 し て い た )。 |
||
|
* |
read (2) from an inotify (7) file descriptor (since Linux 3.8; beforehand, always failed with EINTR ). |
以 下 の イ ン タ ー フ ェ イ ス は 、 SA_RESTART を 使 っ て い る ど う か に 関 わ ら ず 、 シ グ ナ ル ハ ン ド ラ ー に よ り 割 り 込 ま れ た 後 、 再 ス タ ー ト す る こ と は 決 し て な い 。 こ れ ら は 、 シ グ ナ ル ハ ン ド ラ ー に よ り 割 り 込 ま れ る と 、 常 に エ ラ ー EINTR で 失 敗 す る 。
|
* |
setsockopt (2) を 使 っ て タ イ ム ア ウ ト ( SO_RCVTIMEO ) が 設 定 さ れ て い る 「 入 力 」 ソ ケ ッ ト イ ン タ ー フ ェ ー ス : accept (2), recv (2), recvfrom (2), recvmmsg (2) (NULL 以 外 の timeout 引 数 も 指 定 さ れ て い る 場 合 ), recvmsg (2) |
||
|
* |
"Output" socket interfaces, when a timeout ( SO_RCVTIMEO ) has been set on the socket using setsockopt (2): connect (2), send (2), sendto (2), and sendmsg (2). |
||
|
* |
シ グ ナ ル 待 ち に 使 わ れ る イ ン タ ー フ ェ イ ス : pause (2), sigsuspend (2), sigtimedwait (2), sigwaitinfo (2). |
||
|
* |
フ ァ イ ル デ ィ ス ク リ プ タ ー 多 重 イ ン タ ー フ ェ イ ス : epoll_wait (2), epoll_pwait (2), poll (2), ppoll (2), select (2), pselect (2). |
||
|
* |
System V IPC イ ン タ ー フ ェ イ ス : msgrcv (2), msgsnd (2), semop (2), semtimedop (2). |
||
|
* |
ス リ ー プ 用 の イ ン タ ー フ ェ イ ス : clock_nanosleep (2), nanosleep (2), usleep (3). |
||
|
* |
io_getevents (2). |
sleep (3) 関 数 も 、 ハ ン ド ラ ー に よ り 割 り 込 ま れ た 場 合 、 決 し て 再 ス タ ー ト さ れ る こ と は な い 。 し か し 、 成 功 と な り 、 残 っ て い る 停 止 時 間 を 返 す 。
一 時 停 止 シ グ ナ ル に よ る シ ス テ ム コ ー ル や ラ イ ブ ラ リ 関 数 へ の 割 り 込 み
Linux で は 、 シ グ ナ ル ハ ン ド ラ ー が 設 定 さ れ て い な い 場 合 で も 、 い く つ か の ブ ロ ッ キ ン グ 型 の イ ン タ ー フ ェ イ ス は 、 プ ロ セ ス が 一 時 停 止 (stop) シ グ ナ ル の 一 つ に よ り 停 止 さ れ 、 SIGCONT に よ り 再 開 さ れ た 後 に 、 エ ラ ー EINTR で 失 敗 す る 可 能 性 が あ る 。 こ の 挙 動 は POSIX.1 で 認 め ら れ て お ら ず 、 他 の シ ス テ ム で は 起 こ ら な い 。
こ の 挙 動 を 示 す Linux の イ ン タ ー フ ェ イ ス は 以 下 の 通 り で あ る 。
|
* |
setsockopt (2) を 使 っ て タ イ ム ア ウ ト ( SO_RCVTIMEO ) が 設 定 さ れ て い る 「 入 力 」 ソ ケ ッ ト イ ン タ ー フ ェ ー ス : accept (2), recv (2), recvfrom (2), recvmmsg (2) (NULL 以 外 の timeout 引 数 も 指 定 さ れ て い る 場 合 ), recvmsg (2) |
||
|
* |
"Output" socket interfaces, when a timeout ( SO_RCVTIMEO ) has been set on the socket using setsockopt (2): connect (2), send (2), sendto (2), and sendmsg (2), if a send timeout ( SO_SNDTIMEO ) has been set. |
||
|
* |
epoll_wait (2), epoll_pwait (2). |
||
|
* |
semop (2), semtimedop (2). |
||
|
* |
sigtimedwait (2), sigwaitinfo (2). |
||
|
* |
Linux 3.7 and earlier: read (2) from an inotify (7) file descriptor |
||
|
* |
Linux 2.6.21 以 前 : futex (2) FUTEX_WAIT , sem_timedwait (3), sem_wait (3). |
||
|
* |
Linux 2.6.8 以 前 : msgrcv (2), msgsnd (2). |
||
|
* |
Linux 2.4 以 前 : nanosleep (2). |
準 拠
POSIX.1 (注 記 し た 内 容 以 外 )。
注 意
For a discussion of async-signal-safe functions, see signal-safety (7).
The /proc/[pid]/task/[tid]/status file contains various fields that show the signals that a thread is blocking ( SigBlk ), catching ( SigCgt ), or ignoring ( SigIgn ). (The set of signals that are caught or ignored will be the same across all threads in a process.) Other fields show the set of pending signals that are directed to the thread ( SigPnd ) as well as the set of pending signals that are directed to the process as a whole ( ShdPnd ). The corresponding fields in /proc/[pid]/status show the information for the main thread. See proc (5) for further details.
バ グ
There are six signals that can be delivered as a consequence of a hardware exception: SIGBUS , SIGEMT , SIGFPE , SIGILL , SIGSEGV , and SIGTRAP . Which of these signals is delivered, for any given hardware exception, is not documented and does not always make sense.
For example, an invalid memory access that causes delivery of SIGSEGV on one CPU architecture may cause delivery of SIGBUS on another architecture, or vice versa.
For another example, using the x86 int instruction with a forbidden argument (any number other than 3 or 128) causes delivery of SIGSEGV , even though SIGILL would make more sense, because of how the CPU reports the forbidden operation to the kernel.
関 連 項 目
kill (1), clone (2), getrlimit (2), kill (2), pidfd_send_signal (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), swapcontext (3), sysv_signal (3), core (5), proc (5), nptl (7), pthreads (7), sigevent (7)
こ の 文 書 に つ い て
こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。