{"id":649,"date":"2017-01-18T16:39:52","date_gmt":"2017-01-18T08:39:52","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=649"},"modified":"2017-02-03T15:49:51","modified_gmt":"2017-02-03T07:49:51","slug":"%e4%bf%a1%e5%8f%b7%e9%9b%86","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=649","title":{"rendered":"\u4fe1\u53f7\u96c6"},"content":{"rendered":"<p>\u6211\u4eec\u9700\u8981\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u53bb\u63cf\u7ed8\u591a\u79cd\u4fe1\u53f7\uff0c\u8fd9\u79cd\u6570\u636e\u7c7b\u578b\u88ab\u79f0\u4e3a<em>\u4fe1\u53f7\u96c6<\/em>\u3002\u6211\u4eec\u5c06\u4f7f\u7528<span style=\"color: #993300;\">sigprocmask<\/span>\u51fd\u6570\u544a\u77e5\u5185\u6838\u4e0d\u5141\u8bb8\u54ea\u7c7b\u4fe1\u53f7\u53d1\u751f\u3002\u5c31\u50cf\u4e4b\u524d\u8bf4\u7684\u90a3\u6837\u79cd\u7c7b\u4f17\u591a\u7684\u4fe1\u53f7\u8d85\u51fa\u4e86\u6574\u578b\u80fd\u8868\u793a\u7684\u4f4d\u6570\uff0c\u6240\u4ee5\u4e00\u822c\u6765\u8bf4\u6211\u4eec\u4e0d\u4f7f\u7528\u6574\u578b\u4e2d\u7684\u4e00\u4f4d\u6765\u63cf\u8ff0\u4fe1\u53f7\u3002POSIX.1\u5b9a\u4e49\u7684\u6570\u636e\u7c7b\u578b\u662f<span style=\"color: #993300;\">sigset_t<\/span>\u6765\u5305\u542b\u4fe1\u53f7\u96c6\u5e76\u4e14\u7528\u4e0b\u9762\u4e94\u79cd\u51fd\u6570\u6765\u64cd\u7eb5\u4fe1\u53f7\u96c6\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: 466px;\" border=\"1\" width=\"1122\" 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 sigemptyset(sigset_t *<span class=\"docEmphItalicAlt\">set<\/span>);\r\n\r\nint sigfillset(sigset_t *<span class=\"docEmphItalicAlt\">set<\/span>);\r\n\r\nint sigaddset(sigset_t *<span class=\"docEmphItalicAlt\">set<\/span>, int <span class=\"docEmphItalicAlt\">signo<\/span>);\r\n\r\nint sigdelset(sigset_t *<span class=\"docEmphItalicAlt\">set<\/span>, int <span class=\"docEmphItalicAlt\">signo<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">All four return: 0 if OK, 1 on error<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<pre><span style=\"color: #993300;\">int sigismember(const sigset_t *<span class=\"docEmphItalicAlt\">set<\/span>, int <span class=\"docEmphItalicAlt\">signo<\/span>);\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"right\" valign=\"top\">\n<p class=\"docText\">Returns: 1 if true, 0 if false, 1 on error<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"color: #993300;\">sigemptyset<\/span>\u51fd\u6570\u521d\u59cb\u5316\u4fe1\u53f7\u96c6\uff0c\u8ba9\u5176\u4e0d\u5305\u542b\u4efb\u4f55\u4fe1\u53f7\u3002<span style=\"color: #993300;\">sigfillset<\/span>\u521d\u59cb\u5316\u4fe1\u53f7\u96c6\u5305\u542b\u6240\u6709\u4fe1\u53f7\u3002\u6240\u6709\u7684\u5e94\u7528\u7a0b\u5e8f\u5fc5\u987b\u5728\u4f7f\u7528\u4fe1\u53f7\u96c6\u4e4b\u524d\u4e3a\u6bcf\u4e2a\u4fe1\u53f7\u96c6\u8c03\u7528<span style=\"color: #993300;\">sigemptyset<\/span>\u6216<span style=\"color: #993300;\">sigfillset<\/span>\u51fd\u6570\u4e00\u6b21\uff0cbecause we cannot assume that the C initialization for external and static variables (0) corresponds to the implementaion of signal sets on a given system\u3002\uff08\u4e0d\u77e5\u9053C initialization\u662f\u4ec0\u4e48\u4e1c\u897f\uff0c\u5927\u6982\u610f\u601d\u5e94\u8be5\u662f\u201c\u4e0d\u80fd\u4fdd\u8bc1\u4f60\u6240\u4f7f\u7528\u7684\u7cfb\u7edf\u4e2d\u7684\u6bcf\u4e2a\u4fe1\u53f7\u90fd\u5305\u542b\u5728\u8be5\u4fe1\u53f7\u96c6\u5185\u201d\uff09<\/p>\n<p>\u4e00\u65e6\u6211\u4eec\u521d\u59cb\u5316\u4e86\u4fe1\u53f7\u96c6\uff0c\u6211\u4eec\u80fd\u5728\u8be5\u96c6\u4e2d\u6dfb\u52a0\u548c\u5220\u9664\u6307\u5b9a\u7684\u4fe1\u53f7\u3002<span style=\"color: #993300;\">sigaddset<\/span>\u51fd\u6570\u6dfb\u52a0\u5355\u4e00\u7684\u4fe1\u53f7\u5230\u5df2\u7ecf\u5b58\u5728\u7684\u96c6\u4e2d\uff0c\u800c<span style=\"color: #993300;\">sigdelset<\/span>\u4ece\u96c6\u4e2d\u79fb\u9664\u5355\u4e00\u7684\u4fe1\u53f7\u3002\u8fd9\u51e0\u4e2a\u51fd\u6570\u90fd\u9700\u8981\u4e00\u4e2a\u4fe1\u53f7\u96c6\u53c2\u6570\uff0c\u6211\u4eec\u901a\u8fc7\u4f20\u9001\u4e00\u4e2a\u4fe1\u53f7\u96c6\u5730\u5740\u4f5c\u4e3a\u8fd9\u4e2a\u53c2\u6570\u3002<\/p>\n<h1>\u5b9e\u73b0<\/h1>\n<p>\u5982\u679c\u6240\u7528\u5b9e\u73b0\u4e2d\u6ca1\u6709\u51e0\u4e2a\u4fe1\u53f7\uff0c\u4fe1\u53f7\u6570\u5c11\u4e8e\u6574\u578b\u4f4d\u6570\uff0c\u4fe1\u53f7\u96c6\u7684\u5b9e\u73b0\u53ef\u4ee5\u4f7f\u7528\u6574\u578b\u53d8\u91cf\u7684\u6bcf\u4e00\u4f4d\u8868\u793a\u4e00\u4e2a\u4fe1\u53f7\u3002\u672c\u8282\u5269\u4e0b\u7684\u90e8\u5206\u5047\u5b9a\u5b9e\u73b0\u7684\u7cfb\u7edf\u670931\u4e2a\u4fe1\u53f7\u5e76\u4e14\u6574\u578b\u53d8\u91cf\u662f32\u4f4d\u3002<span style=\"color: #993300;\">sigemptyset<\/span>\u51fd\u6570\u5c06\u6574\u578b\u5f52\u96f6\uff0c<span style=\"color: #993300;\">sigfillset<\/span>\u51fd\u6570\u53ef\u4ee5\u5c06\u6574\u578b\u7684\u6bcf\u4f4d\u7f6e1\u3002\u8fd9\u4e24\u4e2a\u51fd\u6570\u5728<span style=\"color: #993300;\">&lt;signal.h&gt;<\/span>\u5934\u6587\u4ef6\u4e2d\u7528\u5b8f\u5b9e\u73b0\uff1a<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<pre><span style=\"color: #993300;\">   #define sigemptyset(ptr)   (*(ptr) = 0)\r\n   #define sigfillset(ptr)    (*(ptr) = <sup>~<\/sup>(sigset_t)0, 0)\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\uff1a\u51fd\u6570\u5fc5\u987b\u8fd4\u56de0\uff0c\u5e76\u8bbe\u7f6e\u6bcf\u4e00\u4f4d\u90fd\u662f1\uff0c\u6240\u4ee5\u6211\u4eec\u4f7f\u7528\u9017\u53f7\u64cd\u4f5c\u7b26\uff0c\u5b83\u8fd4\u56de\u9017\u53f7\u540e\u9762\u7684\u8868\u8fbe\u5f0f\u503c\u3002\uff08so we use C&#8217;s comma operator, which returns the value after the comma as the value of the expression.\uff09<\/p>\n<p>\u4f7f\u7528\u8fd9\u4e2a\u5b9e\u73b0\uff0c<span style=\"color: #993300;\">sigaddset<\/span>\u6253\u5f00\u4fe1\u53f7\u7684\u67d0\u4e00\u4f4d\uff0csigdelset\u5173\u95ed\u4fe1\u53f7\u7684\u67d0\u4e00\u4f4d\uff1b<span style=\"color: #993300;\">sigisnumber<\/span>\u6d4b\u8bd5\u67d0\u4e00\u4f4d\u3002\u56e0\u4e3a\u6ca1\u6709\u4fe1\u53f7\u662f\u6570\u5b570\uff0c\u6240\u4ee5\u6211\u4eec\u4ece\u4fe1\u53f7\u6570\u4e0a\u51cf1\u6765\u83b7\u5f97\u76f8\u5e94\u7684\u6bd4\u7279\u4f4d\uff0c\u7528\u51fd\u6570\u6765\u64cd\u7eb5\u8be5\u201c\u6570\u201d\u3002\u4e0b\u9762\u663e\u793a\u4e86\u8fd9\u51e0\u4e2a\u51fd\u6570\u7684\u5b9e\u73b0\uff1a<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<h5 class=\"docExampleTitle\">Figure 10.12. An implementation of <tt>sigaddset<\/tt>, <tt>sigdelset<\/tt>, and <tt>sigismember<\/tt><\/h5>\n<pre><span style=\"color: #993300;\">#include     &lt;signal.h&gt;\r\n#include     &lt;errno.h&gt;\r\n\r\n\/* &lt;signal.h&gt; usually defines NSIG to include signal number 0 *\/\r\n#define SIGBAD(signo)   ((signo) &lt;= 0 || (signo) &gt;= NSIG)\r\n\r\nint\r\nsigaddset(sigset_t *set, int signo)\r\n{\r\n    if (SIGBAD(signo)) { errno = EINVAL; return(-1); }\r\n\r\n    *set |= 1 &lt;&lt; (signo - 1);       \/* turn bit on *\/\r\n    return(0);\r\n}\r\n\r\nint\r\nsigdelset(sigset_t *set, int signo)\r\n{\r\n    if (SIGBAD(signo)) { errno = EINVAL; return(-1); }\r\n\r\n    *set &amp;= <sup>~<\/sup>(1 &lt;&lt; (signo - 1));    \/* turn bit off *\/\r\n    return(0);\r\n}\r\n\r\nint\r\nsigismember(const sigset_t *set, int signo)\r\n{\r\n     if (SIGBAD(signo)) { errno = EINVAL; return(-1); }\r\n\r\n     return((*set &amp; (1 &lt;&lt; (signo - 1))) != 0);\r\n}\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u53ef\u4ee5\u8bd5\u56fe\u5b9e\u73b0\u8fd9\u4e09\u4e2a\u51fd\u6570\u505a\u4e3a\u4e00\u4e2a\u4e00\u884c\u957f\u7684\u5b8f\u5728<span style=\"color: #993300;\">&lt;signal.h&gt;<\/span>\u5934\u6587\u4ef6\u4e2d\u5b9e\u73b0\uff0c\u4f46\u662fPOSIX.1\u9700\u8981\u6211\u4eec\u53bb\u68c0\u67e5\u4fe1\u53f7\u6570\u53c2\u6570\u7684\u6709\u6548\u6027\uff0c\u5e76\u4e14\u5982\u679c\u8be5\u4fe1\u53f7\u6570\u65e0\u6548\u7684\u8bdd\u8bbe\u7f6e<span style=\"color: #993300;\">errno<span style=\"color: #000000;\">\u3002\u76f8\u6bd4\u51fd\u6570\u5b9e\u73b0\uff0c\u7528\u5b8f\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u66f4\u56f0\u96be\u3002<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4eec\u9700\u8981\u4e00\u79cd\u6570\u636e\u7c7b\u578b\u53bb\u63cf\u7ed8\u591a\u79cd\u4fe1\u53f7\uff0c\u8fd9\u79cd\u6570\u636e\u7c7b\u578b\u88ab\u79f0\u4e3a\u4fe1\u53f7\u96c6\u3002\u6211\u4eec\u5c06\u4f7f\u7528sigprocmask\u51fd\u6570\u544a\u77e5\u5185\u6838\u4e0d\u5141\u8bb8\u54ea\u7c7b\u4fe1\u53f7\u53d1\u751f\u3002\u5c31\u50cf\u4e4b\u524d\u8bf4\u7684\u90a3\u6837\u79cd\u7c7b\u4f17\u591a\u7684\u4fe1\u53f7\u8d85\u51fa&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=649\"> 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-649","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/649","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=649"}],"version-history":[{"count":4,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/649\/revisions"}],"predecessor-version":[{"id":654,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/649\/revisions\/654"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}