2 .\" Copyright (c) 1994,1995 Mike Battersby <mib@deakin.edu.au>
3 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" based on work by faith@cs.unc.edu
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" Modified, aeb, 960424
27 .\" Modified Fri Jan 31 17:31:20 1997 by Eric S. Raymond <esr@thyrsus.com>
28 .\" Modified Thu Nov 26 02:12:45 1998 by aeb - add SIGCHLD stuff.
29 .\" Modified Sat May 8 17:40:19 1999 by Matthew Wilcox
30 .\" add POSIX.1b signals
31 .\" Modified Sat Dec 29 01:44:52 2001 by Evan Jones <ejones@uwaterloo.ca>
33 .\" Modified 2004-11-11 by Michael Kerrisk <mtk.manpages@gmail.com>
34 .\" Added mention of SIGCONT under SA_NOCLDSTOP
35 .\" Added SA_NOCLDWAIT
36 .\" Modified 2004-11-17 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\" Updated discussion for POSIX.1-2001 and SIGCHLD and sa_flags.
39 .\" 2004-12-09, mtk, added SI_TKILL + other minor changes
40 .\" 2005-09-15, mtk, split sigpending(), sigprocmask(), sigsuspend()
41 .\" out of this page into separate pages.
43 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya all rights reserved.
44 .\" Translated 1997-03-03, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Modified 2000-10-02, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
46 .\" Modified 2001-10-18, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
47 .\" Updated 2005-03-15, Akihiro MOTOKI
48 .\" Updated 2005-10-05, Akihiro MOTOKI
49 .\" Updated 2007-09-08, Akihiro MOTOKI, LDP v2.64
50 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
51 .\" Updated 2010-04-18, Akihiro MOTOKI, LDP v3.24
55 .\"WORD: signal handler シグナルハンドラ
56 .\"WORD: pointer ポインター
58 .\"WORD: block 禁止(block)
59 .\"WORD: suspend 停止(suspend)
60 .\"WORD: stop 停止(stop)
61 .\"WORD: catch 捕獲(catch)
62 .\"WORD: architecture アーキテクチャー
63 .\"WORD: compatible 互換性
66 .TH SIGACTION 2 2009-07-25 "Linux" "Linux Programmer's Manual"
69 .\"O sigaction \- examine and change a signal action
70 sigaction \- シグナルの動作の確認と変更
74 .B #include <signal.h>
76 .BI "int sigaction(int " signum ", const struct sigaction *" act ,
77 .BI " struct sigaction *" oldact );
81 .\"O Feature Test Macro Requirements for glibc (see
82 .\"O .BR feature_test_macros (7)):
84 .RB ( feature_test_macros (7)
90 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _POSIX_SOURCE
96 .\"O system call is used to change the action taken by a process on
97 .\"O receipt of a specific signal.
100 .\"O for an overview of signals.)
102 システムコールは、特定のシグナルを受信した際の
109 .\"O specifies the signal and can be any valid signal except
118 以外の有効なシグナルをどれでも指定できる。
122 .\"O is non-NULL, the new action for signal
124 .\"O is installed from
134 .\"O is non-NULL, the previous action is saved in
143 .\"O structure is defined as something like:
150 void (*sa_handler)(int);
151 void (*sa_sigaction)(int, siginfo_t *, void *);
154 void (*sa_restorer)(void);
159 .\"O On some architectures a union is involved: do not assign to both
162 .\"O .IR sa_sigaction .
163 アーキテクチャによっては共用体 (union) が用いられており、その場合には
171 .\"O element is obsolete and should not be used.
174 .\"O POSIX does not specify a
182 .\"O specifies the action to be associated with
186 .\"O for the default action,
188 .\"O to ignore this signal, or a pointer to a signal handling function.
189 .\"O This function receives the signal number as its only argument.
198 シグナルハンドラ関数へのポインタが設定できる。
199 シグナルハンドラ関数の引き数は一つであり、シグナル番号が引き数として
209 .\"O .IR sa_handler )
210 .\"O specifies the signal-handling function for
212 .\"O This function receives the signal number as its first argument, a
215 .\"O as its second argument and a pointer to a
217 .\"O (cast to \fIvoid\ *\fP) as its third argument.
227 に対応するシグナルハンドル関数が指定される。
228 指定される関数は、最初の引き数としてシグナル番号を、
231 へのポインタを、三番目の引き数として (\fIvoid\ *\fP にキャストした)
236 .\"O specifies a mask of signals which should be blocked
237 .\"O (i.e., added to the signal mask of the thread in which
238 .\"O the signal handler is invoked)
239 .\"O during execution of the signal handler.
240 .\"O In addition, the signal which triggered the handler
241 .\"O will be blocked, unless the
245 は、シグナル・ハンドラ実行中に禁止 (block) すべきシグナルのマスクを指定する
246 (ハンドラ実行中のシグナルの禁止は、シグナル・ハンドラが起動されたスレッド
247 のシグナルのマスクに追加することで行われる)。
250 フラグが指定されていない場合は、ハンドラを起動するきっかけとなる
256 .\"O specifies a set of flags which modify the behavior of the signal.
257 .\"O It is formed by the bitwise OR of zero or more of the following:
259 はシグナル・ハンドラの動作を変更するためのフラグの集合を指定する。
261 には、以下に示すフラグの (0 個以上の) 論理和をとったものを指定する。
269 .\"O do not receive notification when child processes stop (i.e., when they
271 .\"O .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN
274 .\"O or resume (i.e., they receive
278 .\"O This flag is only meaningful when establishing a handler for
286 .BR SIGSTOP ", " SIGTSTP ", " SIGTTIN ", " SIGTTOU
287 を受けたとき) 再開したり (子プロセスが
294 に対してハンドラを設定する際にのみ意味を持つ。
296 .\"O .BR SA_NOCLDWAIT " (Since Linux 2.6)"
297 .BR SA_NOCLDWAIT " (Linux 2.6 以降)"
298 .\"O .\" To be precise: Linux 2.5.60 -- MTK
300 .\" 正確には Linux 2.5.60 以降 -- MTK
305 .\"O do not transform children into zombies when they terminate.
307 .\"O .BR waitpid (2).
315 .\"O This flag is only meaningful when establishing a handler for
317 .\"O or when setting that signal's disposition to
321 に対してハンドラを設定する際、もしくはそのシグナルの処理方法を
327 .\"O flag is set when establishing a handler for
329 .\"O POSIX.1 leaves it unspecified whether a
331 .\"O signal is generated when a child process terminates.
334 .\"O signal is generated in this case;
335 .\"O on some other implementations, it is not.
350 .\"O Do not prevent the signal from being received from within its own signal
352 .\"O This flag is only meaningful when establishing a signal handler.
354 .\"O is an obsolete, nonstandard synonym for this flag.
355 それ自身のシグナル・ハンドラーの内部にいる時でも
357 このフラグはシグナルハンドラを設定する際にのみ意味を持つ。
359 はこのフラグと同じ意味だが、廃止されており、非標準である。
362 .\"O Call the signal handler on an alternate signal stack provided by
363 .\"O .BR sigaltstack (2).
364 .\"O If an alternate stack is not available, the default stack will be used.
365 .\"O This flag is only meaningful when establishing a signal handler.
367 で提供される別のシグナル・スタックでシグナルハンドラを呼び出す。
368 別のシグナル・スタックが利用可能でなければ、デフォルトのスタックが
370 このフラグはシグナルハンドラを設定する際にのみ意味を持つ。
373 .\"O Restore the signal action to the default state once the signal handler
374 .\"O has been called.
375 .\"O This flag is only meaningful when establishing a signal handler.
377 .\"O is an obsolete, nonstandard synonym for this flag.
378 シグナルハンドラが呼ばれる度に、シグナルの動作をデフォルトに戻す。
379 このフラグはシグナルハンドラを設定する際にのみ意味を持つ。
381 はこのフラグと同じ意味だが、廃止されており、非標準である。
384 .\"O Provide behavior compatible with BSD signal semantics by making certain
385 .\"O system calls restartable across signals.
386 .\"O This flag is only meaningful when establishing a signal handler.
389 .\"O for a discussion of system call restarting.
390 いくつかのシステムコールをシグナルの通知の前後で再開できるようにして、
391 BSD シグナル方式 (semantics) と互換性のある動作を提供する。
392 このフラグはシグナルハンドラを設定する際にのみ意味を持つ。
394 に書かれているシステムコールの再開に関する議論を参照のこと。
396 .\"O .BR SA_SIGINFO " (since Linux 2.2)"
397 .BR SA_SIGINFO " (Linux 2.2 以降)"
398 .\"O The signal handler takes 3 arguments, not one.
401 .\"O should be set instead of
402 .\"O .IR sa_handler .
403 .\"O This flag is only meaningful when establishing a signal handler.
405 .\"O .\" .I sa_sigaction
406 .\"O .\" field was added in Linux 2.1.86.)
407 シグナルハンドラは一つではなく、三つの引き数を持つ。この場合は
412 このフラグはシグナルハンドラを設定する際にのみ意味を持つ。
413 .\" .RI ( sa_sigaction
414 .\" フィールドは Linux 2.1.86 で追加された)。
421 .\"O is a struct with the following elements:
430 int si_signo; /* Signal number */
431 int si_errno; /* An errno value */
432 int si_code; /* Signal code */
433 int si_trapno; /* Trap number that caused
434 hardware-generated signal
435 (unused on most architectures) */
437 .\" si_trapno seems to be only used on SPARC and Alpha;
438 .\" this page could use a little more detail on its purpose there.
439 pid_t si_pid; /* Sending process ID */
440 uid_t si_uid; /* Real user ID of sending process */
441 int si_status; /* Exit value or signal */
442 clock_t si_utime; /* User time consumed */
443 clock_t si_stime; /* System time consumed */
444 sigval_t si_value; /* Signal value */
445 int si_int; /* POSIX.1b signal */
446 void *si_ptr; /* POSIX.1b signal */
447 int si_overrun; /* Timer overrun count; POSIX.1b timers */
448 int si_timerid; /* Timer ID; POSIX.1b timers */
449 .\" In the kernel: si_tid
450 void *si_addr; /* Memory location which caused fault */
451 int si_band; /* Band event */
452 int si_fd; /* File descriptor */
457 .\"O .IR si_signo ", " si_errno " and " si_code
458 .\"O are defined for all signals.
460 .\"O is generally unused on Linux.)
461 .IR si_signo ", " si_errno ", " si_code
464 は Linux では一般的には使用されない)。
465 .\"O The rest of the struct may be a union, so that one should only
466 .\"O read the fields that are meaningful for the given signal:
467 構造体の残りの部分は、共用体 (union) になっているかもしれない。
468 その場合は該当するシグナルにおいて意味のあるフィールドのみを読み込む
471 .\"O POSIX.1b signals and
474 .\"O .IR si_pid " and " si_uid .
478 .IR si_pid " と " si_uid
481 .\"O POSIX.1b timers (since Linux 2.6) fill in
484 .\"O .IR si_timerid .
487 .\"O field is an internal ID used by the kernel to identify
488 .\"O the timer; it is not the same as the timer ID returned by
489 .\"O .BR timer_create (2).
490 POSIX.1b タイマ (Linux 2.6 以降) は
496 フィールドはカーネルがタイマを特定するのに使用する内部 ID であり、
502 .\"O .IR si_status ", " si_utime " and " si_stime .
505 .IR si_status ", " si_utime ", " si_stime
511 .\"O fields do not include the times used by waited-for children (unlike
512 .\"O .BR getrusage (2)
515 .\"O In kernels up to 2.6, and since 2.6.27, these fields report
516 .\"O CPU time in units of
517 .\"O .IR sysconf(_SC_CLK_TCK) .
518 .\"O In 2.6 kernels before 2.6.27,
519 .\"O a bug meant that these fields reported time in units
520 .\"O of the (configurable) system jiffy (see
529 には wait 待ちの子プロセスにより使用された時間は含まれない。
530 2.6 より前と 2.6.27 以降のカーネルでは、
531 これらのフィールドに格納される CPU 時間の単位は
532 .I sysconf(_SC_CLK_TCK)
534 2.6.27 より前の 2.6 系のカーネルでは、バグがあり、
535 これらのフィールドの CPU 時間の単位が
536 (カーネルのコンフィグで指定される) システムの jiffy であった
540 .\" When si_utime and si_stime where originally implemented, the
541 .\" measurement unit was HZ, which was the same as clock ticks
542 .\" (sysconf(_SC_CLK_TCK)). In 2.6, HZ became configurable, and
543 .\" was *still* used as the unit to return the info these fields,
544 .\" with the result that the field values depended on the the
545 .\" configured HZ. Of course, the should have been measured in
546 .\" USER_HZ instead, so that sysconf(_SC_CLK_TCK) could be used to
547 .\" convert to seconds. I have a queued patch to fix this:
548 .\" http://thread.gmane.org/gmane.linux.kernel/698061/ .
549 .\" This patch made it into 2.6.27.
550 .\" But note that these fields still don't return the times of
551 .\" waited-for children (as is done by getrusage() and times()
552 .\" and wait4()). Solaris 8 does include child times.
554 .\"O .IR si_int " and " si_ptr
555 .\"O are specified by the sender of the POSIX.1b signal.
556 .IR si_int " と " si_ptr
557 は POSIX.1b シグナルの送信者によって指定される。
559 .\"O .BR sigqueue (2)
560 .\"O for more details.
572 .\"O with the address of the fault.
582 .\"O .IR si_band " and " si_fd .
584 .IR si_band " と " si_fd
588 .\"O is a value (not a bit mask)
589 .\"O indicating why this signal was sent.
591 は、そのシグナルが送信された理由を示す値である (ビットマスクではない)。
592 .\"O The following list shows the values which can be placed in
594 .\"O for any signal, along with reason that the signal was generated.
597 に入りうる値を、シグナルが生成された理由とともに記載する。
609 .\"O Sent by the kernel.
616 .\"O POSIX timer expired
620 .\"O POSIX message queue state changed (since Linux 2.6.6); see
621 .\"O .BR mq_notify (3)
622 POSIX メッセージキューの状態が変化した (Linux 2.6.6 以降)。
623 .BR mq_notify (3) 参照。
637 .\"O (since Linux 2.4.19)
642 .\" SI_DETHREAD is defined in 2.6.9 sources, but isn't implemented
643 .\" It appears to have been an idea that was tried during 2.5.6
644 .\" through to 2.5.24 and then was backed out.
647 .\"O The following values can be placed in
667 .\"O illegal addressing mode
675 .\"O privileged opcode
679 .\"O privileged register
683 .\"O coprocessor error
687 .\"O internal stack error
691 .\"O The following values can be placed in
703 .\"O integer divide by zero
707 .\"O integer overflow
711 .\"O floating-point divide by zero
715 .\"O floating-point overflow
719 .\"O floating-point underflow
723 .\"O floating-point inexact result
724 浮動小数点の不正確な演算結果 (inexact result)
727 .\"O floating-point invalid operation
731 .\"O subscript out of range
735 .\"O The following values can be placed in
747 .\"O address not mapped to object
748 オブジェクトにマッピングされていないアドレス
751 .\"O invalid permissions for mapped object
752 マッピングされたオブジェクトに対するアクセス許可がない
755 .\"O The following values can be placed in
767 .\"O invalid address alignment
768 不正なアドレス・アライメント (alignment)
771 .\"O nonexistent physical address
775 .\"O object-specific hardware error
779 .\"O The following values can be placed in
791 .\"O process breakpoint
795 .\"O process trace trap
799 .\"O The following values can be placed in
811 .\"O child has exited
815 .\"O child was killed
819 .\"O child terminated abnormally
823 .\"O traced child has trapped
824 トレース対象の子プロセスがトラップを上げた
827 .\"O child has stopped
831 .\"O stopped child has continued (since Linux 2.6.9)
832 停止していた子プロセスが再開した (Linux 2.6.9 以降)
835 .\"O The following values can be placed in
847 .\"O data input available
851 .\"O output buffers available
855 .\"O input message available
863 .\"O high priority input available
867 .\"O device disconnected
870 .\"O .SH "RETURN VALUE"
872 .\"O .BR sigaction ()
873 .\"O returns 0 on success and \-1 on error.
875 は成功すれば 0 を返し、エラーならば \-1 を返す。
880 .\"O .IR act " or " oldact
881 .\"O points to memory which is not a valid part of the process address space.
883 が指しているメモリが正しいプロセスのアドレス空間にない。
886 .\"O An invalid signal was specified.
887 .\"O This will also be generated if an attempt
888 .\"O is made to change the action for
889 .\"O .BR SIGKILL " or " SIGSTOP ", "
890 .\"O which cannot be caught or ignored.
891 無効なシグナルが指定された。補足 (catch) したり無視したりできない
893 .BR SIGKILL " や " SIGSTOP
894 に対する動作を変更しようとした場合にも発生する。
895 .\"O .SH "CONFORMING TO"
898 .\"O .\" SVr4 does not document the EINTR condition.
899 .\" SVr4 には EINTR についての記述はない。
902 .\"O A child created via
904 .\"O inherits a copy of its parent's signal dispositions.
907 .\"O the dispositions of handled signals are reset to the default;
908 .\"O the dispositions of ignored signals are left unchanged.
910 経由で作成された子プロセスは、親プロセスのシグナルの処理方法の
913 の前後で、ハンドラが設定されているシグナルの処理方法はデフォルトにリセットされ、
914 無視が設定されているシグナルの処理方法は変更されずそのままとなる。
916 .\"O According to POSIX, the behavior of a process is undefined after it
922 .\"O signal that was not generated by
926 .\"O Integer division by zero has undefined result.
927 .\"O On some architectures it will generate a
930 .\"O (Also dividing the most negative integer by \-1 may generate
932 .\"O Ignoring this signal might lead to an endless loop.
941 を無視 (ignore) した場合、その後の動作は未定義である。
942 ゼロによる整数割り算の結果は未定義となる。
949 このシグナルを無視すると無限ループに陥るかもしれない。
951 .\"O POSIX.1-1990 disallowed setting the action for
955 .\"O POSIX.1-2001 allows this possibility, so that ignoring
957 .\"O can be used to prevent the creation of zombies (see
959 .\"O Nevertheless, the historical BSD and System V behaviors for ignoring
961 .\"O differ, so that the only completely portable method of ensuring that
962 .\"O terminated children do not become zombies is to catch the
964 .\"O signal and perform a
972 POSIX.1-2001 では認められており、
974 を無視することでゾンビプロセスの生成を防止することができる
980 そのため、完全に移植性がある方法で、終了した子プロセスがゾンビにならないこと
987 .\"O POSIX.1-1990 only specified
988 .\"O .BR SA_NOCLDSTOP .
989 .\"O POSIX.1-2001 added
990 .\"O .BR SA_NOCLDWAIT ,
991 .\"O .BR SA_RESETHAND ,
992 .\"O .BR SA_NODEFER ,
994 .\"O .BR SA_SIGINFO .
995 .\"O Use of these latter values in
997 .\"O may be less portable in applications intended for older
998 .\"O Unix implementations.
1008 Unix の古い実装で動かすアプリケーションで、
1014 .\"O .B SA_RESETHAND
1015 .\"O flag is compatible with the SVr4 flag of the same name.
1017 フラグは SVr4 の同じ名前のフラグと互換性がある。
1021 .\"O flag is compatible with the SVr4 flag of the same name under kernels
1022 .\"O 1.3.9 and newer.
1023 .\"O On older kernels the Linux implementation
1024 .\"O allowed the receipt of any signal, not just the one we are installing
1025 .\"O (effectively overriding any
1029 フラグは 1.3.9 以降のカーネルでは同じ名前の SVr4 のフラグと互換性がある。
1030 ぞれ以前の Linux カーネルの実装では、このフラグを設定しているシグナル
1031 だけでなく、どのシグナルでも受けることを許していた (実際には
1035 .\"O .BR sigaction ()
1036 .\"O can be called with a null second argument to query the current signal
1038 .\"O It can also be used to check whether a given signal is valid for
1039 .\"O the current machine by calling it with null second and third arguments.
1041 の二番目の引き数に NULL を指定して呼び出すと、現在のシグナルハンドラを確認する
1042 ことができる。また、二番目と三番目の引き数を NULL にて呼び出すことで、
1043 指定されたシグナルが現在のマシンで使えるかどうかチェックできる。
1045 .\"O It is not possible to block
1046 .\"O .BR SIGKILL " or " SIGSTOP
1047 .\"O (by specifying them in
1049 .\"O Attempts to do so are silently ignored.
1059 .\"O .BR sigsetops (3)
1060 .\"O for details on manipulating signal sets.
1067 .\"O for a list of the async-signal-safe functions that can be
1068 .\"O safely called inside from inside a signal handler.
1069 シグナルハンドラ内から安全に呼び出すことができる、
1070 async-signal-safe functions (非同期シングルで安全な関数) の
1074 .\"O .SS Undocumented
1076 .\"O Before the introduction of
1078 .\"O it was also possible to get some additional information,
1079 .\"O namely by using a
1081 .\"O with second argument of type
1082 .\"O .IR "struct sigcontext".
1083 .\"O See the relevant kernel sources for details.
1084 .\"O This use is obsolete now.
1087 .I "struct sigcontext"
1091 いくつかの追加の情報を入手することができた。
1092 詳細についてはカーネルソースの関連部分を見てほしい。
1096 .\"O In kernels up to and including 2.6.13, specifying
1100 .\"O prevents not only the delivered signal from being masked during
1101 .\"O execution of the handler, but also the signals specified in
1103 .\"O This bug was fixed in kernel 2.6.14.
1109 ハンドラが実行中に配送されたシグナル自身がマスクされなくなるだけでなく、
1111 に指定されたシグナルもマスクされなくなる。
1112 このバグは、カーネル 2.6.14 で修正された。
1116 .\"O .BR mprotect (2).
1125 .BR sigaltstack (2),
1129 .BR sigprocmask (2),
1134 .BR siginterrupt (3),