{"id":731,"date":"2017-03-08T15:49:31","date_gmt":"2017-03-08T07:49:31","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=731"},"modified":"2017-03-08T15:49:31","modified_gmt":"2017-03-08T07:49:31","slug":"%e6%8e%a7%e5%88%b6%e4%bf%a1%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=731","title":{"rendered":"\u63a7\u5236\u4fe1\u53f7"},"content":{"rendered":"<p>POSIX.1\u8003\u8651\u4f7f\u7528\u516d\u79cd\u4efb\u52a1\u63a7\u5236\u4fe1\u53f7\uff1a<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<table style=\"height: 398px;\" width=\"393\" frame=\"void\" rules=\"none\" cellspacing=\"0\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIGCHLD<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u5b50\u8fdb\u7a0b\u5df2\u7ecf\u505c\u6b62\u6216\u7ec8\u6b62\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIGCONT<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u5982\u679c\u8fdb\u7a0b\u5df2\u7ecf\u505c\u6b62\u90a3\u4e48\u7ee7\u7eed\u8fdb\u7a0b\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIGSTOP<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u505c\u6b62\u4fe1\u53f7\uff08\u4e0d\u80fd\u88ab\u6355\u83b7\u6216\u5ffd\u7565\uff09\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt><tt>SIGTSTP<\/tt><\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u4e92\u65a5\u505c\u6b62\u4fe1\u53f7\uff08Interactive stop signal\uff09<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIGTTIN<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u540e\u53f0\u8fdb\u7a0b\u7ec4\u6210\u5458\u8bfb\u53d6\u63a7\u5236\u7ec8\u7aef\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\"><span style=\"color: #993300;\"><tt>SIGTTOU<\/tt><\/span><\/p>\n<\/td>\n<td class=\"docTableCell\" align=\"left\" valign=\"top\">\n<p class=\"docText\">\u7531\u540e\u53f0\u8fdb\u7a0b\u7ec4\u6210\u5458\u5199\u63a7\u5236\u7ec8\u7aef\u3002<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9664\u4e86<span style=\"color: #993300;\">SIGCHLD<\/span>\u4fe1\u53f7\u5916\u591a\u6570\u5e94\u7528\u7a0b\u5e8f\u5e76\u4e0d\u5904\u7406\u8fd9\u4e9b\u4fe1\u53f7\uff1a\u4ea4\u4e92shell\u901a\u5e38\u53bb\u5904\u7406\u8fd9\u4e9b\u4fe1\u53f7\u3002\u5f53\u6211\u4eec\u952e\u5165\u6302\u8d77\u5b57\u7b26\uff08\u4e00\u822c\u662fCtrl+Z\uff09\uff0c<span style=\"color: #993300;\">SIGTSTP<\/span>\u4fe1\u53f7\u88ab\u53d1\u9001\u5230\u6240\u6709\u524d\u53f0\u8fdb\u7a0b\u7ec4\u4e2d\u3002\u5f53\u6211\u4eec\u544a\u8bc9shell\u5728\u524d\u53f0\u6216\u540e\u53f0\u4fdd\u7559\u4e00\u4e2a\u4efb\u52a1\u65f6\uff0cshell\u4f1a\u5411\u6240\u6709\u5de5\u4f5c\u4efb\u52a1\u53d1\u9001\u4e00\u4e2a<span style=\"color: #993300;\">SIGCONT<\/span>\u4fe1\u53f7\u3002\u7c7b\u4f3c\u7684\uff0c\u5982\u679c<span style=\"color: #993300;\">SIGTTIN<\/span>\u6216<span style=\"color: #993300;\">SIGTTOU<\/span>\u88ab\u53d1\u9001\u5230\u8fdb\u7a0b\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f1a\u88ab\u505c\u6b62\uff0c\u5e76\u4e14\u4efb\u52a1\u63a7\u5236shell\u8bb0\u5f55\u4e0b\u8fd9\u4e2a\u5e76\u901a\u77e5\u6211\u4eec\u3002<\/p>\n<p>\u4e00\u4e2a\u4f8b\u5916\u662f\u7ba1\u7406\u7ec8\u7aef\u7684\u8fdb\u7a0b\uff1a\u5982<span style=\"color: #993300;\">vi<\/span>\u7f16\u8f91\u5668\u3002\u5b83\u8981\u77e5\u9053\u7528\u6237\u8981\u6302\u8d77\u5b83\uff0c\u6240\u4ee5\u5b83\u80fd\u6062\u590d\u7ec8\u7aef\u5230\u5b83\u5f00\u59cb\u65f6\u7684\u72b6\u6001\u3002\u540c\u6837\uff0c\u5f53\u5b83\u6062\u590d\u5230\u524d\u53f0\u65f6\uff0c<span style=\"color: #993300;\">vi<\/span>\u7f16\u8f91\u5668\u9700\u8981\u8bbe\u7f6e\u7ec8\u7aef\u72b6\u6001\u5230\u5b83\u60f3\u8981\u7684\u72b6\u6001\uff0c\u5e76\u4e14\u5b83\u9700\u8981\u91cd\u65b0\u7ed8\u5236\u5c4f\u5e55\u3002\u540e\u9762\u7684\u4f8b\u5b50\u4f1a\u663e\u793a\u7a0b\u5e8f\u5982\u4f55\u50cf<span style=\"color: #993300;\">vi<\/span>\u4e00\u6837\u5904\u7406\u3002<\/p>\n<p>\u5728\u4efb\u52a1\u63a7\u5236\u4fe1\u53f7\u4e2d\u6709\u4e00\u4e9b\u4e92\u65a5\u4fe1\u53f7\u3002\u5f53\u67d0\u4e2a\u8fdb\u7a0b\u6536\u5230\u56db\u79cd\u505c\u6b62\u4fe1\u53f7\uff08<span style=\"color: #993300;\">SIGTSTP<\/span>, <span style=\"color: #993300;\">SIGSTOP<\/span>, <span style=\"color: #993300;\">SIGTTIN<\/span>\u6216<span style=\"color: #993300;\">SIGTTOU<\/span>\uff09\u65f6\uff0c\u8be5\u8fdb\u7a0b\u4efb\u4f55\u5904\u4e8epending\u72b6\u6001\u7684<span style=\"color: #993300;\">SIGCONT<\/span>\u4fe1\u53f7\u4f1a\u88ab\u629b\u5f03\u3002\u7c7b\u4f3c\u7684\u5f53\u67d0\u4e2a\u8fdb\u7a0b\u6536\u5230<span style=\"color: #993300;\">SIGCONT<\/span>\u4fe1\u53f7\uff0c\u4efb\u4f55pending\u72b6\u6001\u7684\u505c\u6b62\u4fe1\u53f7\u4e5f\u90fd\u4f1a\u88ab\u629b\u5f03\u3002<\/p>\n<p>\u6ce8\u610f\u5982\u679c\u8fdb\u7a0b\u5df2\u7ecf\u505c\u6b62\uff0c<span style=\"color: #993300;\">SIGCONT<\/span>\u7684\u9ed8\u8ba4\u52a8\u4efb\u662f\u7ee7\u7eed\u8fdb\u7a0b\uff1b\u5176\u5b83\u60c5\u51b5\u4f1a\u5ffd\u7565\u3002\u4e00\u822c\u5730\uff0c\u6211\u4eec\u4e0d\u5fc5\u4e3a\u8fd9\u4e2a\u4fe1\u53f7\u505a\u4efb\u4f55\u4e8b\u60c5\u3002<span style=\"text-decoration: underline;\">\u5f53SIGCONT\u4fe1\u53f7\u4e3a\u67d0\u4e2a\u5df2\u7ecf\u505c\u6b62\u7684\u8fdb\u7a0b\u4ea7\u751f\u65f6\uff0c\u8fd9\u4e2a\u8fdb\u7a0b\u5c31\u4f1a\u7ee7\u7eed\u8fd0\u884c\uff0c\u5373\u4f7f\u8fd9\u4e2a\u4fe1\u53f7\u88ab\u963b\u585e\u6216\u5ffd\u7565<\/span>\u3002<\/p>\n<h1>\u4f8b\u5b50\uff1a<\/h1>\n<p>Figure10.30\u7684\u7a0b\u5e8f\u6f14\u793a\u4e86\u5f53\u4e00\u4e2a\u7a0b\u5e8f\u5904\u7406\u4efb\u52a1\u63a7\u5236\u7684\u6b63\u5e38\u4ee3\u7801\u987a\u5e8f\u3002\u8fd9\u4e2a\u7a0b\u5e8f\u7b80\u5355\u7684\u590d\u5236\u4e86\u5b83\u7684\u6807\u51c6\u8f93\u5165\u5230\u5b83\u7684\u6807\u51c6\u8f93\u51fa\uff0c\u4f46\u662f\u5728\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u4e2d\u7a0b\u5e8f\u7ba1\u7406\u4e86\u5c4f\u5e55\uff08\u6ce8\u91ca\u5199\u660e\u4e86\u5904\u7406\u65b9\u6cd5\uff09\u3002\u5f53Figure10.30\u7a0b\u5e8f\u5f00\u59cb\uff0c\u4ec5\u5f53\u4fe1\u53f7\u7684\u9884\u7f6e\u884c\u4e3a\uff08disposition\uff09\u662f<span style=\"color: #993300;\">SIG_DFL<\/span>\u65f6\uff0c\u5b83\u624d\u4f1a\u53bb\u6355\u83b7<span style=\"color: #993300;\">SIGTSTP<\/span>\u4fe1\u53f7\u3002\u7406\u7531\u662f\u5f53\u7a0b\u5e8f\u88ab\u4e0d\u652f\u6301\u4efb\u52a1\u63a7\u5236\u7684shell\u6267\u884c\u65f6\uff08\u5982<span style=\"color: #993300;\">\/bin\/sh<\/span>\uff09\uff0c\u8be5\u4fe1\u53f7\u7684\u9884\u7f6e\u884c\u4e3a\uff08disposition\uff09\u5c06\u4f1a\u662f<span style=\"color: #993300;\">SIG_IGN<\/span>\u3002\u5b9e\u9645\u4e0a\uff0cshell\u4e0d\u4f1a\u663e\u793a\u7684\u5ffd\u7565\u8fd9\u4e2a\u4fe1\u53f7\uff1b<span style=\"color: #993300;\">init<\/span>\u8bbe\u7f6e\u4e86\u4e09\u4e2a\u4efb\u52a1\u63a7\u5236\u4fe1\u53f7\uff08<span style=\"color: #993300;\">SIGTSTP<\/span>, <span style=\"color: #993300;\">SIGTTIN<\/span>\u548c<span style=\"color: #993300;\">SIGTTOU<\/span>\uff09\u7684\u90e8\u7f72\u662f<span style=\"color: #993300;\">SIG_IGN<\/span>\u3002\u8fd9\u4e2a\u9884\u7f6e\u884c\u4e3a\uff08disposition\uff09\u4f1a\u88ab\u6240\u6709\u767b\u9646shell\u7ee7\u627f\u3002\u53ea\u6709\u5e26\u4efb\u52a1\u63a7\u5236\u7684shell\u4f1a\u91cd\u7f6e\u8fd9\u4e9b\u4fe1\u53f7\u7684\u9884\u7f6e\u884c\u4e3a\uff08disposition\uff09\u5230<span style=\"color: #993300;\">SIG_DFL<\/span>\u3002<\/p>\n<p>\u5f53\u6211\u4eec\u952e\u5165\u6302\u8d77\u5b57\u7b26\uff0c\u8fdb\u7a0b\u6536\u5230<span style=\"color: #993300;\">SIGTSTP<\/span>\u4fe1\u53f7\uff0c\u4e4b\u540e\u4fe1\u53f7\u5904\u7406\u51fd\u6570\u88ab\u8c03\u7528\u3002\u8fd9\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u505a\u4efb\u4f55\u7ec8\u7aef\u76f8\u5173\u7684\u4e8b\u60c5\uff1a\u79fb\u52a8\u5149\u6807\u5230\u5de6\u4e0b\u89d2\uff0c \u6062\u590d\u7ec8\u7aef\u6a21\u5f0f\uff0c \u7b49\u7b49\u3002\u6211\u4eec\u7136\u540e\u53d1\u9001\u6211\u4eec\u81ea\u5df1\u7684\u76f8\u540c\u4fe1\u53f7\uff0c<span style=\"color: #993300;\">SIGTSTP<\/span>\uff0c\u4e4b\u540e\u91cd\u7f6e\u5b83\u7684\u9884\u7f6e\u884c\u4e3a\u5230\u9ed8\u8ba4\uff08\u505c\u6b62\u8fdb\u7a0b\uff09\u5e76\u4e14\u89e3\u9501\u4fe1\u53f7\u3002\u6211\u4eec\u5fc5\u987b\u89e3\u9501\u5b83\uff0c\u56e0\u4e3a\u6211\u4eec\u8981\u6b63\u786e\u5904\u7406\u76f8\u540c\u7684\u4fe1\u53f7\uff0c\u5e76\u4e14\u5f53\u8be5\u4fe1\u53f7\u88ab\u6355\u83b7\u540e\u7cfb\u7edf\u4f1a\u81ea\u52a8\u7684\u9501\u5b9a\u5b83\u3002\u8fd9\u65f6\uff0c\u7cfb\u7edf\u505c\u6b62\u8fdb\u7a0b\u3002\u53ea\u6709\u5f53\u8fdb\u7a0b\u6536\u5230\uff08\u901a\u5e38\u662f\u4ece\u4efb\u52a1\u63a7\u5236SHELL\uff0c\u4f7f\u7528<span style=\"color: #993300;\">fg<\/span>\u547d\u4ee4\u8fdb\u884c\u4ea4\u4e92\uff09<span style=\"color: #993300;\">SIGCONT<\/span>\u4fe1\u53f7\u65f6\u624d\u4f1a\u7ee7\u7eed\u8fd0\u884c\u3002\u6211\u4eec\u4e0d\u6355\u83b7<span style=\"color: #993300;\">SIGCONT<\/span>\uff0c\u5b83\u7684\u9884\u7f6e\u884c\u4e3a\u662f\u7ee7\u7eed\u505c\u7684\u8fdb\u7a0b\uff1b\u5f53\u8fd9\u53d1\u751f\u7684\u65f6\u5019\uff0c\u7a0b\u5e8f\u7ee7\u7eed\u8fd0\u884c\u5c31\u50cf\u4ece<span style=\"color: #993300;\">kill<\/span>\u51fd\u6570\u8fd4\u56de\u4e00\u6837\u3002\uff08When this happens, the program continues as though it returned from the kill function.\uff09\u5f53\u7a0b\u5e8f\u7ee7\u7eed\u8fd0\u884c\u65f6\uff0c\u6211\u4eec\u4e3aSIGTSTP\u4fe1\u53f7\u91cd\u7f6e\u9884\u7f6e\u884c\u4e3a\u5e76\u4e14\u6267\u884c\u4efb\u4f55\u6211\u4eec\u60f3\u6267\u884c\u7684\u547d\u4ee4\uff08\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u91cd\u7ed8\u5c4f\u5e55\uff09\u3002<\/p>\n<table border=\"0\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\">\n<h2 class=\"docExampleTitle\">Figure 10.30. How to handle <span style=\"color: #993300;\"><tt>SIGTSTP<\/tt><\/span><\/h2>\n<pre><span style=\"color: #993300;\">#include \"apue.h\"\r\n\r\n#define BUFFSIZE   1024\r\n\r\nstatic void sig_tstp(int);\r\n\r\nint\r\nmain(void)\r\n{\r\n    int     n;\r\n    char    buf[BUFFSIZE];\r\n\r\n    \/*\r\n     * Only catch SIGTSTP if we're running with a job-control shell.\r\n     *\/\r\n    if (signal(SIGTSTP, SIG_IGN) == SIG_DFL)\r\n        signal(SIGTSTP, sig_tstp);\r\n\r\n    while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) &gt; 0)\r\n        if (write(STDOUT_FILENO, buf, n) != n)\r\n            err_sys(\"write error\");\r\n\r\n    if (n &lt; 0)\r\n        err_sys(\"read error\");\r\n\r\n    exit(0);\r\n}\r\n\r\nstatic void\r\nsig_tstp(int signo) \/* signal handler for SIGTSTP *\/\r\n{\r\n    sigset_t    mask;\r\n\r\n    \/* ... move cursor to lower left corner, reset tty mode ... *\/\r\n\r\n    \/*\r\n     * Unblock SIGTSTP, since it's blocked while we're handling it.\r\n     *\/\r\n    sigemptyset(&amp;mask);\r\n    sigaddset(&amp;mask, SIGTSTP);\r\n    sigprocmask(SIG_UNBLOCK, &amp;mask, NULL);\r\n\r\n    signal(SIGTSTP, SIG_DFL);   \/* reset disposition to default *\/\r\n\r\n    kill(getpid(), SIGTSTP);    \/* and send the signal to ourself *\/\r\n\r\n    \/* we won't return from the kill until we're continued *\/\r\n\r\n    signal(SIGTSTP, sig_tstp);  \/* reestablish signal handler *\/\r\n\r\n    \/* ... reset tty mode, redraw screen ... *\/\r\n}\r\n<\/span><\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>POSIX.1\u8003\u8651\u4f7f\u7528\u516d\u79cd\u4efb\u52a1\u63a7\u5236\u4fe1\u53f7\uff1a SIGCHLD \u5b50\u8fdb\u7a0b\u5df2\u7ecf\u505c\u6b62\u6216\u7ec8\u6b62\u3002 SIGCONT \u5982\u679c\u8fdb\u7a0b\u5df2\u7ecf\u505c\u6b62\u90a3\u4e48\u7ee7\u7eed\u8fdb\u7a0b\u3002 SIGSTOP \u505c\u6b62\u4fe1\u53f7\uff08\u4e0d\u80fd&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=731\"> 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-731","post","type-post","status-publish","format-standard","hentry","category-apue"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/731","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=731"}],"version-history":[{"count":6,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":741,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions\/741"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}