-
Notifications
You must be signed in to change notification settings - Fork 175
add new pages sig_dfl,sig_err,sig_ign
#1586
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
5
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.
+155
−3
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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,57 @@ | ||
| # SIG_DFL | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIG_DFL see below | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| `signal`関数に渡される引数として、シグナルハンドラをデフォルトに設定するマクロ。 | ||
|
|
||
| シグナル受信時に`signal`関数で`SIG_DFL`が指定されている場合、そのシグナルに対する実装定義のデフォルト処理が実行される。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <csignal> | ||
| #include <iostream> | ||
| #include <thread> | ||
| #include <chrono> | ||
|
|
||
| volatile std::sig_atomic_t flag = 0; | ||
|
|
||
| void handler(int) | ||
| { | ||
| flag = 1; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| std::signal(SIGINT, handler); | ||
|
|
||
| std::cout << "Press Ctrl+C (handled)" << std::endl; | ||
| while (!flag) { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
| } | ||
|
|
||
| // デフォルトに戻す | ||
| std::signal(SIGINT, SIG_DFL); | ||
| std::cout << "Press Ctrl+C again (default action)" << std::endl; | ||
| for (;;) { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| * SIG_DFL[color ff0000] | ||
K10-K10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * std::signal[color ff0000] | ||
|
|
||
| ### 出力 | ||
|
|
||
| ``` | ||
| Press Ctrl+C (handled) | ||
| Press Ctrl+C again (default action) | ||
| ``` | ||
|
|
||
| ## 関連項目 | ||
| - [`signal`](/reference/csignal/signal.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,52 @@ | ||
| # SIG_ERR | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIG_ERR see below | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| `signal`関数の戻り値で、シグナルハンドラの設定に失敗したことを示す値。 | ||
|
|
||
| `signal`関数が失敗した場合、この値が返される。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <csignal> | ||
| #include <iostream> | ||
| #include <thread> | ||
| #include <chrono> | ||
|
|
||
| volatile std::sig_atomic_t flag = 0; | ||
|
|
||
| void signal_handler(int sig) | ||
| { | ||
| flag = 1; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| if (std::signal(SIGINT, signal_handler) == SIG_ERR) { | ||
| std::cerr << "Failed to set signal handler" << std::endl; | ||
| return 1; | ||
| } | ||
| std::cout << "Signal handler set successfully" << std::endl; | ||
| while (!flag) { | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | ||
| } | ||
| return 0; | ||
| } | ||
| ``` | ||
|
|
||
| * SIG_ERR[color ff0000] | ||
| * std::signal[color ff0000] | ||
|
|
||
| ### 出力例 | ||
|
|
||
| ``` | ||
| Signal handler set successfully | ||
| ``` | ||
|
|
||
| ## 関連項目 | ||
| - [`signal`](/reference/csignal/signal.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,43 @@ | ||
| # SIG_IGN | ||
| * csignal[meta header] | ||
| * macro[meta id-type] | ||
|
|
||
| ```cpp | ||
| #define SIG_IGN see below | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| `signal`関数に渡される引数として、指定されたシグナルを無視させるマクロ。 | ||
|
|
||
| シグナル受信時に`signal`関数で`SIG_IGN`が指定されている場合、そのシグナルは無視される。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <csignal> | ||
| #include <iostream> | ||
| #include <thread> | ||
|
|
||
| int main() | ||
| { | ||
| std::signal(SIGINT, SIG_IGN); | ||
| // Ctrl+Cを押してもプログラムは続行する | ||
| for (int i = 0; i < 10; ++i) { | ||
| std::cout << i << " " << std::flush; | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
| } | ||
K10-K10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::cout << std::endl; | ||
| return 0; | ||
| } | ||
| ``` | ||
|
|
||
| * SIG_IGN[color ff0000] | ||
| * std::signal[color ff0000] | ||
|
|
||
| ### 出力 | ||
|
|
||
| ``` | ||
| 0 1 2 3 4 5 6 7 8 9 | ||
| ``` | ||
|
|
||
| ## 関連項目 | ||
| - [`signal`](/reference/csignal/signal.md) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは用途を記載したほうがいい気がしました。
シグナルハンドラーの登録を解除するものですよね。
サンプルコードもそのような用途を説明するものだとよいかと思います。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
変更しました.