{"id":655,"date":"2017-02-03T22:42:49","date_gmt":"2017-02-03T14:42:49","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=655"},"modified":"2017-02-07T09:50:08","modified_gmt":"2017-02-07T01:50:08","slug":"sigprocmask%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=655","title":{"rendered":"sigprocmask\u51fd\u6570"},"content":{"rendered":"<p>\u56de\u8bb0\u4e00\u4e0b\u4e4b\u524d\u8bf4\u7684<em>\u4fe1\u53f7\u63a9\u7801<\/em>\uff0c\u5b83\u662f\u4e00\u7ec4\u88ab\u8fdb\u7a0b\u963b\u585e\u7684\u4fe1\u53f7\u3002\u8fdb\u7a0b\u53ef\u4ee5\u68c0\u67e5\u5b83\u7684\u4fe1\u53f7\u63a9\u7801\u3001\u6539\u53d8\u5b83\u7684\u4fe1\u53f7\u63a9\u7801\u6216\u901a\u8fc7\u4e00\u4e2a\u64cd\u4f5c\u540c\u65f6\u505a\u8fd9\u4e24\u79cd\u64cd\u4f5c\u2014\u2014\u4f7f\u7528\u4e0b\u9762\u7684\u51fd\u6570\uff1a<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table class=\"allBorders\" style=\"height: 198px;\" border=\"1\" width=\"945\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre><span style=\"color: #993300;\">#include &lt;signal.h&gt;\r\n\r\nint sigprocmask(int <span class=\"docEmphItalicAlt\">how<\/span>, const sigset_t *restrict <span class=\"docEmphItalicAlt\">set<\/span>,\r\n                sigset_t *restrict <span class=\"docEmphItalicAlt\">oset<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9996\u5148\u3001\u5982\u679c<em>oset<\/em>\u662f\u4e00\u4e2a\u975e\u7a7a\u6307\u9488\uff0c\u5f53\u524d\u8fdb\u7a0b\u7684\u4fe1\u53f7<em>\u63a9\u7801\u901a\u8fc7oset<\/em>\u8fd4\u56de\u3002<\/p>\n<p>\u5176\u6b21\uff0c\u5982\u679c<em>set<\/em>\u662f\u4e00\u4e2a\u975e\u7a7a\u6307\u9488\uff0c<em>how<\/em>\u6307\u793a\u4e86\u5982\u4f55\u4fee\u6539\u5f53\u524d\u4fe1\u53f7\u63a9\u7801\u3002<span style=\"color: #0000ff;\">Figure 10.13<\/span>\u63cf\u8ff0\u4e86<em>how<\/em>\u53ef\u80fd\u4f7f\u7528\u7684\u503c\u3002<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table class=\"allBorders\" style=\"height: 285px;\" border=\"1\" width=\"875\" rules=\"groups\" cellspacing=\"0\" cellpadding=\"5\">\n<caption>\n<h5 class=\"docTableTitle\">Figure 10.13. Ways to change current signal mask using <span style=\"color: #993300;\"><tt>sigprocmask<\/tt><\/span><\/h5>\n<\/caption>\n<colgroup>\n<col width=\"150\" \/>\n<col width=\"350\" \/><\/colgroup>\n<thead>\n<tr>\n<th class=\"rightBorder bottomBorder thead\" scope=\"col\" align=\"center\" valign=\"top\">\n<p class=\"docText\"><span class=\"docEmphRoman\"><span class=\"docEmphasis\">how<\/span><\/span><\/p>\n<\/th>\n<th class=\"bottomBorder thead\" scope=\"col\" align=\"center\" valign=\"top\">\n<p class=\"docText\"><span class=\"docEmphRoman\">Description<\/span><\/p>\n<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"rightBorder\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIG_BLOCK<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u8fdb\u7a0b\u7684\u65b0\u4fe1\u53f7\u63a9\u7801\u662f\u7531\u5b83\u5f53\u524d\u7684\u4fe1\u53f7\u63a9\u7801\u548c\u4fe1\u53f7\u96c6\uff08\u7531<em>set<\/em>\u6307\u5411\u4fe1\u53f7\u96c6\uff09\u7ec4\u6210\u3002\u5c31\u662f\uff0c<em>set<\/em>\u5305\u51fd\u4e86\u6211\u4eec\u60f3\u989d\u5916\u963b\u585e\u7684\u4fe1\u53f7\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"rightBorder\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIG_UNBLOCK<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u8fdb\u7a0b\u7684\u65b0\u4fe1\u53f7\u63a9\u7801\u662f\u7531\u5f53\u524d\u4fe1\u53f7\u63a9\u7801\u548c\u4fe1\u53f7\u96c6\u7684\u8865\u96c6\u76f8\u4ea4\u83b7\u5f97\uff08\u4fe1\u53f7\u96c6\u7684\u8865\u96c6\u7531<em>set<\/em>\u6307\u5411\uff09\u3002\u4e5f\u5c31\u662f<em>set<\/em>\u5305\u542b\u4e86\u6211\u4eec\u60f3\u89e3\u9501\u7684\u4fe1\u53f7\u63a9\u7801\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"rightBorder\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIG_SETMASK<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u8fdb\u7a0b\u7684\u65b0\u4fe1\u53f7\u63a9\u7801\u5c31\u662f\u7531<em>set<\/em>\u6307\u5b9a\u3002<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #993300;\">SIG_BLOCK<\/span>\u662f\u903b\u8f91\u6216\u64cd\u4f5c\uff08\u903b\u8f91\u52a0\u6cd5\uff09\uff0c<span style=\"color: #993300;\">SIG_SETMASK<\/span>\u662f\u8bbe\u7f6e\u4e00\u4e2a\u503c\u3002\u6ce8\u610f\uff1a<span style=\"color: #993300;\">SIGKILL<\/span>\u548c<span style=\"color: #993300;\">SIGSTOP<\/span>\u4e0d\u80fd\u88ab\u963b\u585e\u3002<\/p>\n<p>\u5982\u679c<em>set<\/em>\u662f\u7a7a\u6307\u9488\uff0c\u8fdb\u7a0b\u7684\u4fe1\u53f7\u63a9\u7801\u4e0d\u4f1a\u88ab\u4fee\u6539\uff0c\u5e76\u4e14\u5ffd\u7565<em>how<\/em>\u7684\u8bbe\u7f6e\u3002<\/p>\n<p>\u5728\u8c03\u7528<span style=\"color: #993300;\">sigprocmask<\/span>\u540e\uff0c\u5982\u679c\u53d1\u751f\u4efb\u4f55\u672a\u963b\u585e\u7684\u4fe1\u53f7\uff0c\u5728<span style=\"color: #993300;\">sigprocmask<\/span>\u8fd4\u56de\u4e4b\u524d\uff0c\u8fd9\u4e9b\u4fe1\u53f7\u4e4b\u4e00\u4f1a\u88ab\u4f20\u9001\u5230\u8fdb\u7a0b\u3002<\/p>\n<p><em><span style=\"color: #993300;\">sigprocmask<\/span>\u51fd\u6570\u4ec5\u88ab\u5b9a\u4e49\u5728\u5355\u7ebf\u7a0b\u7684\u8fdb\u7a0b\u4e2d\u3002\u5c06\u5728APUE\u768412.8\u8282\u4e2d\u8bb2\u8ff0\u53e6\u4e00\u4e2a\u7528\u4e8e\u591a\u7ebf\u7a0b\u7684\u51fd\u6570\u7248\u672c\u3002<\/em><\/p>\n<h3>\u4f8b\uff1a<\/h3>\n<p>Figure 10.14 \u663e\u793a\u4e86\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u5b83\u6253\u5370\u4e86\u5728\u5f53\u8fdb\u7a0b\u4e2d\u4fe1\u53f7\u63a9\u7801\u6240\u5305\u542b\u7684\u4fe1\u53f7\u540d\u3002\u6211\u4eec\u4f1a\u5728figure 10.20\u548cfigure 10.22\u4e2d\u8c03\u7528\u8fd9\u4e2a\u7a0b\u5e8f\u3002<\/p>\n<p>\u4e3a\u4e86\u8282\u7701\u7a7a\u95f4\u6240\u4ee5\u6211\u4eec\u5e76\u6ca1\u6709\u6d4b\u8bd5\u6bcf\u4e00\u4e2a\u4fe1\u53f7\u3002<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<pre><strong>Figure 10.14. Print the signal mask for the process<\/strong>\r\n#include &lt;signal.h&gt;\r\n#include &lt;errno.h&gt;\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\nvoid\r\npr_mask(const char *str)\r\n{\r\n    sigset_t    sigset;\r\n    int         errno_save;\r\n\r\n    errno_save = errno;     \/* we can be called by signal handlers *\/\r\n    if (sigprocmask(0, NULL, &amp;sigset) &lt; 0)\r\n        printf(\"sigprocmask error\");\r\n\r\n    printf(\"%s\", str);\r\n    if (sigismember(&amp;sigset, SIGINT))   printf(\"SIGINT \");\r\n    if (sigismember(&amp;sigset, SIGQUIT))  printf(\"SIGQUIT \");\r\n    if (sigismember(&amp;sigset, SIGUSR1))  printf(\"SIGUSR1 \");\r\n    if (sigismember(&amp;sigset, SIGALRM))  printf(\"SIGALRM \");\r\n\r\n    \/* remaining signals can go here *\/\r\n\r\n    printf(\"\\n\");\r\n    errno = errno_save;\r\n}\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>\u56de\u8bb0\u4e00\u4e0b\u4e4b\u524d\u8bf4\u7684\u4fe1\u53f7\u63a9\u7801\uff0c\u5b83\u662f\u4e00\u7ec4\u88ab\u8fdb\u7a0b\u963b\u585e\u7684\u4fe1\u53f7\u3002\u8fdb\u7a0b\u53ef\u4ee5\u68c0\u67e5\u5b83\u7684\u4fe1\u53f7\u63a9\u7801\u3001\u6539\u53d8\u5b83\u7684\u4fe1\u53f7\u63a9\u7801\u6216\u901a\u8fc7\u4e00\u4e2a\u64cd\u4f5c\u540c\u65f6\u505a\u8fd9\u4e24\u79cd\u64cd\u4f5c\u2014\u2014\u4f7f\u7528\u4e0b\u9762\u7684\u51fd\u6570\uff1a #includ&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=655\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-655","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=655"}],"version-history":[{"count":11,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/655\/revisions"}],"predecessor-version":[{"id":675,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/655\/revisions\/675"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}