{"id":588,"date":"2016-12-09T16:39:56","date_gmt":"2016-12-09T08:39:56","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=588"},"modified":"2016-12-09T16:39:56","modified_gmt":"2016-12-09T08:39:56","slug":"%e4%b8%8d%e5%8f%af%e9%9d%a0%e7%9a%84%e4%bf%a1%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=588","title":{"rendered":"\u4e0d\u53ef\u9760\u7684\u4fe1\u53f7"},"content":{"rendered":"<p>\u5728\u65e9\u671f\u7684UNIX\u7cfb\u7edf\u7248\u672c\u4e2d\u4fe1\u53f7\u66fe\u662f\u4e0d\u53ef\u9760\u7684\u3002\u5b83\u7684\u610f\u601d\u662f\u4fe1\u53f7\u53ef\u80fd\u4e22\u5931\uff1a\u4e00\u4e2a\u4fe1\u53f7\u53d1\u751f\u540e\u8fdb\u7a0b\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u77e5\u9053\u5b83\u66fe\u53d1\u751f\u8fc7\u3002\u540c\u6837\uff0c\u8fdb\u7a0b\u4e5f\u53ef\u4ee5\u63a7\u5236\u4fe1\u53f7\uff1a\u8fdb\u7a0b\u53ef\u4ee5\u6355\u83b7\u4fe1\u53f7\u6216\u5ffd\u7565\u5b83\u3002\u6709\u65f6\u6211\u4eec\u53ef\u80fd\u5e0c\u671b\u544a\u8bc9\u5185\u6838\u963b\u585e\u4e00\u4e2a\u4fe1\u53f7\uff1a\u522b\u5ffd\u7565\u5b83\uff0c\u5f53\u4fe1\u53f7\u53d1\u751f\u65f6\u8bb0\u4f4f\u5b83\uff0c\u7136\u540e\u5f53\u6211\u4eec\u51c6\u5907\u597d\u540e\u518d\u544a\u8bc9\u6211\u4eec\u3002<\/p>\n<p>\u65e9\u5176\u7248\u672c\u7684\u4e00\u4e2a\u95ee\u9898\u662f\u6bcf\u6b21\u4fe1\u53f7\u53d1\u751f\u65f6\u90fd\u4f1a\u91cd\u7f6e\u5904\u7406\u52a8\u4f5c\u4e3a\u5b83\u7684\u9ed8\u8ba4\u52a8\u4f5c\u3002\uff08\u5728\u4e4b\u524d\u7684\u4f8b\u5b50Figure 10.2\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u6355\u6349\u6bcf\u79cd\u4fe1\u53f7\u4e00\u6b21\uff0c\u6765\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\u3002\uff09\u901a\u5e38\u7684\u5904\u7406\u4ee3\u7801\u5982\u4e0b\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;\">         int     sig_int();        \/* my signal handling function *\/\r\n\r\n         ...\r\n         signal(SIGINT, sig_int);  \/* establish handler *\/\r\n         ...\r\n\r\n     sig_int()\r\n     {\r\n         signal(SIGINT, sig_int);  \/* reestablish handler for next time *\/\r\n         ...                       \/* process the signal ... *\/\r\n     }\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u95ee\u9898\u662f\uff0c\u5f53\u4e00\u4e2a\u4e2d\u65ad\u53d1\u5728\u751f\u53e6\u4e00\u4e2a\u4e2d\u65ad\u5904\u7406\u51fd\u6570\uff08signal handler\uff09\u6b63\u5728\u6267\u884c\u65f6\u6709\u4e00\u4e2a\u65f6\u95f4\u95f4\u9699\uff08\u65f6\u95f4\u7a97\u53e3window of time\uff09\u3002\u7b2c\u4e8c\u4e2a\u4e2d\u65ad\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9ed8\u8ba4\u52a8\u4f5c\u53d1\u751f\uff0c\u5b83\u4f1a\u7ed3\u675f\u8fd9\u4e2a\u4fe1\u53f7\u7684\u8fdb\u7a0b\u3002\u8fd9\u4f1a\u8ba9\u6211\u4eec\u8bef\u8ba4\u4e3a\u8fd9\u662f\u6b63\u5e38\u884c\u4e3a\uff0c\u5176\u5b9e\u5b83\u4e0d\u662f\u3002<\/p>\n<p>\u65e9\u671f\u7248\u672c\u7684\u53e6\u4e00\u4e2a\u95ee\u9898\u662f\u8fdb\u7a0b\u4e0d\u80fd\u5728\u5b83\u4e0d\u60f3\u8ba9\u4fe1\u53f7\u53d1\u751f\u65f6\u5173\u95ed\u4fe1\u53f7\u3002\u6240\u6709\u8fdb\u7a0b\u90fd\u53ef\u80fd\u5ffd\u7565\u4fe1\u53f7\u3002\u67d0\u65f6\u6211\u4eec\u53ef\u80fd\u60f3\u5728\u4fe1\u53f7\u53d1\u751f\u65f6\u53ea\u662f\u7b49\u5f85\u4ee5\u540e\u518d\u5904\u7406\u3002\u5178\u578b\u7684\u5904\u7406\u65b9\u6cd5\u662f\u5982\u679c\u4fe1\u53f7\u53d1\u751f\u4e86\u5bf9\u8fdb\u7a0b\u8bbe\u7f6e\u4e00\u4e2a\u6807\u8bb0\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;\">      int     sig_int_flag;         \/* set nonzero when signal occurs *\/\r\n\r\n      main()\r\n      {\r\n          int      sig_int();       \/* my signal handling function *\/\r\n          ...\r\n          signal(SIGINT, sig_int);  \/* establish handler *\/\r\n          ...\r\n          while (sig_int_flag == 0)\r\n              pause();              \/* go to sleep, waiting for signal *\/\r\n          ...\r\n      }\r\n\r\n      sig_int()\r\n      {\r\n          signal(SIGINT, sig_int);  \/* reestablish handler for next time *\/\r\n          sig_int_flag = 1;         \/* set flag for main loop to examine *\/\r\n      }\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u91cc\uff0c\u8fdb\u7a0b\u8c03\u7528<span style=\"color: #993300;\">pause<\/span>\u51fd\u6570\u8ba9\u5176\u4f11\u7720\u76f4\u5230\u4fe1\u53f7\u88ab\u6355\u83b7\u3002\u5f53\u4fe1\u53f7\u88ab\u6355\u83b7\u65f6\uff0c\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u5c31\u8bbe\u7f6e\u6807\u8bb0<span style=\"color: #993300;\">sig_int_flag<\/span>\u5230\u975e\u96f6\u503c\u3002\u5728\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u53cd\u56de\u540e\u5185\u6838\u81ea\u52a8\u6362\u9192\u8fdb\u7a0b\uff0c\u6ce8\u610f\u6807\u8bb0\u975e\u96f6\u5e76\u4e14\u53ef\u4ee5\u505a\u5b83\u4efb\u4f55\u987b\u8981\u505a\u7684\u3002\u4f46\u662f\u5728\u65f6\u95f4\u95f4\u9699\u4e2d\u53ef\u80fd\u4f1a\u51fa\u4e00\u4e9b\u9519\u8bef\u3002\u5982\u679c\u4fe1\u53f7\u53d1\u751f\u5728\u6d4b\u8bd5<span style=\"color: #993300;\">sig_int_flag<\/span>\u503c\u4e4b\u540e\uff0c\u4f46<span style=\"color: #993300;\">pause<\/span>\u8fd8\u6ca1\u6709\u8c03\u7528\u4e4b\u524d\uff0c\u8fdb\u7a0b\u53ef\u4ee5\u4e00\u76f4\u4f11\u7720\u4e0b\u53bb\uff08\u5047\u8bbe\u8be5\u4fe1\u53f7\u4e0d\u518d\u53d1\u751f\u7b2c\u4e8c\u6b21\uff09\u3002\u8fd9\u5c31\u662f\u4fe1\u53f7\u4e22\u5931\u4e8b\u4ef6\u3002\u8fd9\u4f1a\u4f7f\u5176\u5b83\u4ee3\u7801\u90fd\u51fa\u9519\uff0c\u4f46\u5b83\u4ecd\u7136\u53ef\u4ee5\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u6b63\u5e38\u5de5\u4f5c\u3002\u6240\u4ee5\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u975e\u5e38\u56f0\u96be\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u65e9\u671f\u7684UNIX\u7cfb\u7edf\u7248\u672c\u4e2d\u4fe1\u53f7\u66fe\u662f\u4e0d\u53ef\u9760\u7684\u3002\u5b83\u7684\u610f\u601d\u662f\u4fe1\u53f7\u53ef\u80fd\u4e22\u5931\uff1a\u4e00\u4e2a\u4fe1\u53f7\u53d1\u751f\u540e\u8fdb\u7a0b\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u77e5\u9053\u5b83\u66fe\u53d1\u751f\u8fc7\u3002\u540c\u6837\uff0c\u8fdb\u7a0b\u4e5f\u53ef\u4ee5\u63a7\u5236\u4fe1\u53f7\uff1a\u8fdb\u7a0b\u53ef\u4ee5\u6355\u83b7\u4fe1\u53f7\u6216\u5ffd&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=588\"> 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-588","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/588","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=588"}],"version-history":[{"count":5,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/588\/revisions\/593"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}