-
Notifications
You must be signed in to change notification settings - Fork 175
csignalライブラリページの追加 #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
K10-K10
wants to merge
6
commits into
master
Choose a base branch
from
feat/csignal
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
csignalライブラリページの追加 #1578
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9fac2fe
new library `csignal`
K10-K10 77b58d3
add new ref `csignal/raise`
K10-K10 77db2de
add new ref `csignal/sig_atomic_t.md`
K10-K10 cbe45c2
add new ref `csignal/signal`
K10-K10 1454a12
ご指摘頂いた箇所の修正
K10-K10 c39ca8f
add 6 page defines signal types macro
K10-K10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| # csignal | ||
| * csignal[meta header] | ||
|
|
||
| `<csignal>`ヘッダでは、シグナル操作のための機能を定義する。 | ||
| シグナルの集合、意味、及びデフォルトの処理は処理系定義である。 | ||
|
|
||
| ## 型 | ||
|
|
||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | [`sig_atomic_t`](csignal/sig_atomic_t.md) | 非同期シグナルハンドラからアトミックなエンティティとしてアクセス可能な整数型 | | | ||
|
|
||
| ## マクロ | ||
|
|
||
| ### `signal`関数用のハンドラ指定子 | ||
|
|
||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | `SIG_DFL` | デフォルト動作を指定する | | | | ||
| | `SIG_ERR` | `signal`関数が失敗したことを示す戻り値 | | | ||
| | `SIG_IGN` | シグナルを無視する | | | ||
|
|
||
| ### シグナル番号を表すマクロ | ||
|
|
||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | [`SIGINT`](csignal/sigint.md) | 割り込みを示すシグナル番号 | | | ||
| | [`SIGILL`](csignal/sigill.md) | 不正な命令を示すシグナル番号 | | | ||
| | [`SIGABRT`](csignal/sigabrt.md) | `abort`関数などによる異常終了を示すシグナル番号 | | | ||
| | [`SIGFPE`](csignal/sigfpe.md) | 算術演算エラーを示すシグナル番号 | | | ||
| | [`SIGSEGV`](csignal/sigsegv.md) | 無効なメモリアクセスを示すシグナル番号 | | | ||
| | [`SIGTERM`](csignal/sigterm.md) | 終了要求を示すシグナル番号 | | | ||
|
|
||
| ## 関数 | ||
|
|
||
| | 名前 | 説明 | 対応バージョン | | ||
| |------|------|----------------| | ||
| | [`signal`](csignal/signal.md) | 特定のシグナルに対するシグナルハンドラを設定する | | | ||
| | [`raise`](csignal/raise.md) | プログラムにシグナルを送信する | | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # raise | ||
| * csignal[meta header] | ||
| * std[meta namespace] | ||
| * function[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std { | ||
| int raise(int sig); | ||
| } | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| 現在のプログラムにシグナルを送信する。 | ||
|
|
||
| ## 引数 | ||
| - `sig`: 送信するシグナル番号 | ||
|
|
||
| ## 戻り値 | ||
| 正常に終了した場合は0を返す。 | ||
| それ以外の場合は非ゼロの値を返す。 | ||
|
|
||
| ## 備考 | ||
| `signal`関数などにより、シグナルハンドラが呼び出された場合、それが終了するまでこの関数は戻らない。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csignal> | ||
|
|
||
| volatile std::sig_atomic_t got_signal = 0; | ||
|
|
||
| void signal_handler(int signum) { | ||
| got_signal = 1; | ||
| } | ||
|
|
||
| int main (){ | ||
| std::signal(SIGABRT, signal_handler); | ||
| std::raise(SIGABRT); | ||
| if (got_signal) | ||
| std::cout << "SIGABRT" << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
| * std::raise[color ff0000] | ||
|
|
||
| ### 出力例 | ||
| ``` | ||
| SIGABRT | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # sig_atomic_t | ||
| * csignal[meta header] | ||
| * std[meta namespace] | ||
| * type-alias[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std { | ||
| using sig_atomic_t = integer-type; | ||
| } | ||
| ``` | ||
| * integer-type[italic] | ||
|
|
||
| ## 概要 | ||
| `sig_atomic_t`は、非同期シグナルハンドラと通常の実行コンテキストの間で、単純な読み書きを分断されずに行えることが保証された整数型である。 | ||
|
|
||
| この型に対して保証されるのは単純な代入および読み出しのみであり、 | ||
| 複合操作や算術演算は保証されない。 | ||
|
|
||
| 実際の使用では通常`volatile`修飾子と組み合わせて用いられる。 | ||
|
|
||
| 具体的な型は処理系定義である。 | ||
|
|
||
| ## 備考 | ||
| 最大値は`SIG_ATOMIC_MAX`、最小値は`SIG_ATOMIC_MIN`に定義されている。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <csignal> | ||
| #include <iostream> | ||
|
|
||
| volatile std::sig_atomic_t flag = 0; | ||
|
|
||
| void signal_handler(int signum) | ||
| { | ||
| flag = 1; | ||
| } | ||
|
|
||
| int main () | ||
| { | ||
| std::signal(SIGINT, signal_handler); | ||
| while (!flag) { | ||
| //処理 | ||
| } | ||
| if (flag) { | ||
| std::cout << "caught SIGINT" << std::endl; | ||
| } | ||
| return 0; | ||
| } | ||
| ``` | ||
| * std::sig_atomic_t[color ff0000] | ||
|
|
||
| ### 出力例 | ||
| ``` | ||
| caught SIGINT | ||
| ``` | ||
| `Ctrl + c`などで割り込みが発生した場合。 | ||
|
|
||
| ## 関連項目 | ||
| - [`SIG_ATOMIC_MAX`](/reference/cstdint/sig_atomic_max.md) | ||
| - [`SIG_ATOMIC_MIN`](/reference/cstdint/sig_atomic_min.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # SIGABRT | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIGABRT see below | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| `abort`関数などによる異常終了時に送られるシグナルの、シグナル番号を表す`int`型のマクロ。 | ||
|
|
||
| 値は正の整数であり、実際の値は処理系定義である。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csignal> | ||
|
|
||
| int main() | ||
| { | ||
| std::cout << SIGABRT << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
| * SIGABRT[color ff0000] | ||
|
|
||
| ## 出力例 | ||
| ``` | ||
| 6 | ||
| ``` | ||
| 処理系により異なる | ||
|
|
||
| ## 関連項目 | ||
| - [`abort`](/reference/cstdlib/abort.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SIGFPE | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIGFPE see below | ||
| ``` | ||
| ## 概要 | ||
| 算術演算エラー(ゼロ除算など)が発生した際に送られるシグナルの、シグナル番号を表す`int`型のマクロ。 | ||
| 値は正の整数であり、実際の値は処理系定義である。 | ||
| ## 例 | ||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csignal> | ||
| int main() | ||
| { | ||
| std::cout << SIGFPE << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
| * SIGFPE[color ff0000] | ||
|
|
||
| ## 出力例 | ||
| ``` | ||
| 8 | ||
| ``` | ||
| 処理系により異なる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SIGILL | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIGILL see below | ||
| ``` | ||
| ## 概要 | ||
| 無効な命令を実行しようとした際に送られるシグナルの、シグナル番号を表す`int`型のマクロ。 | ||
| 値は正の整数であり、実際の値は処理系定義である。 | ||
| ## 例 | ||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csignal> | ||
| int main() | ||
| { | ||
| std::cout << SIGILL << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
| * SIGILL[color ff0000] | ||
|
|
||
| ## 出力例 | ||
| ``` | ||
| 4 | ||
| ``` | ||
| 処理系により異なる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SIGINT | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIGINT see below | ||
| ``` | ||
| ## 概要 | ||
| 外部割り込みが発生した際に送られるシグナルの、シグナル番号を表す`int`型のマクロ。 | ||
| 値は正の整数であり、実際の値は処理系定義である。 | ||
| ## 例 | ||
| ```cpp example | ||
| #include <iostream> | ||
| #include <csignal> | ||
| int main() | ||
| { | ||
| std::cout << SIGINT << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
| * SIGINT[color ff0000] | ||
|
|
||
| ## 出力例 | ||
| ``` | ||
| 2 | ||
| ``` | ||
| 処理系により異なる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # signal | ||
| * csignal[meta header] | ||
| * std[meta namespace] | ||
| * function[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std{ | ||
| extern "C" using signal-handler = void(int); // exposition only | ||
| signal-handler* signal(int sig, signal-handler* func); | ||
| } | ||
| ``` | ||
| * signal-handler[italic] | ||
|
|
||
| ## 概要 | ||
|
|
||
| シグナル番号`sig`の受け取り後の処理を指定する。 | ||
|
|
||
| `func`の値が`SIG_DFL`の場合、そのシグナルに対するデフォルトの処理が行われる。 | ||
| `func`の値が`SIG_IGN`の場合、そのシグナルを無視する。 | ||
| それ以外の場合、関数`func`が実行される。 | ||
|
|
||
| ## 引数 | ||
|
|
||
| - `sig`: シグナルハンドラを設定するシグナル番号 | ||
| - `func`: シグナルに対する処理。以下のいずれかを指定する。 | ||
| - `SIG_DFL`: そのシグナルに対するデフォルト処理を指定する。 | ||
| - `SIG_IGN`: そのシグナルを無視する。 | ||
| - `func`: シグナルハンドラにする関数へのポインタを示す。 | ||
|
|
||
| ### シグナルハンドラ関数の制約 | ||
| シグナルハンドラ関数は戻り値を持たず、`int`型の引数を持つ。 | ||
| この引数にはシグナル番号が格納される。 | ||
|
|
||
| シグナルハンドラ内で以下以外の処理を行うことは未定義動作である。 | ||
| - `volatile std::sig_atomic_t`オブジェクトへの代入 | ||
| - `abort`関数 | ||
| - `_Exit`関数 | ||
| - `quick_exit`関数 | ||
| - `atomic`引数がロックフリーである場合の`<stdatomic.h>`内の関数 | ||
| - 任意の`atomic`引数を持つ`atomic_is_lock_free`関数 | ||
| - `signal`関数(ただし、ハンドラを起こしたシグナル番号に対する呼び出しに限る) | ||
|
|
||
| ## 戻り値 | ||
|
|
||
| 成功した場合、指定されたシグナルに対する直前のハンドラを返す。 | ||
| それ以外の場合は`SIG_ERR`を返す | ||
|
|
||
| ## 備考 | ||
|
|
||
| マルチスレッド内でのこの関数の動作は未定義。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <csignal> | ||
| #include <iostream> | ||
|
|
||
| volatile std::sig_atomic_t flag = 0; | ||
|
|
||
| void signal_handler(int sig) | ||
| { | ||
| flag = 1; | ||
| // std::cout << "signal: " << sig << std::endl; 未定義動作 | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| std::signal(SIGINT, signal_handler); | ||
| while (!flag) { | ||
| //処理 | ||
| } | ||
| if (flag) { | ||
| std::cout << "caught SIGINT" << std::endl; | ||
| } | ||
| return 0; | ||
| } | ||
| ``` | ||
| * std::signal[color ff0000] | ||
|
|
||
| ### 出力例 | ||
| ``` | ||
| caught SIGINT | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.