{"id":419,"date":"2023-05-25T21:20:05","date_gmt":"2023-05-26T05:20:05","guid":{"rendered":"http:\/\/bitas.net.cn\/?page_id=419"},"modified":"2023-05-25T21:20:05","modified_gmt":"2023-05-26T05:20:05","slug":"384-2","status":"publish","type":"page","link":"http:\/\/bitas.net.cn\/index.php\/sourcecode\/384-2\/","title":{"rendered":"384 \u5b9a\u65f6\u5668"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#define _POSIX_SOURCE\n#include &lt;signal.h>\n#include &lt;stdio.h>\n#include &lt;unistd.h>\n#include &lt;errno.h>\n\nstatic int nap = 0;\nvoid tip(int unused) {\n    nap = 1;\n    alarm(3);\n}\n\n#if 0\nunsigned int alarm(unsigned int seconds)\n{\n    struct itimerval old, new;\n    new.it_interval.tv_usec = 0;\n    new.it_interval.tv_sec = 0;\n    new.it_value.tv_usec = 0;\n    new.it_value.tv_sec = (long int)seconds;\n    if (setitimer(ITIMER_REAL, &amp;new, &amp;old) &lt; 0) return 0;\n    else return old.it_value.tv_sec;\n}\n#endif\n\nint main(int argc, char *argv&#91;])\n{\n    struct sigaction sa; \n    sa.sa_handler = tip;\n    sigemptyset(&amp;sa.sa_mask);\n    sigaction(SIGALRM, &amp;sa, NULL);\n\n    alarm(3);\n\n\n    char buf&#91;32];\n    do {\n        if (nap) {\n            static int i = 1;\n            nap = 0;\n            fprintf(stderr, \"#%02d have a rest.\\n\", i++);\n        }   \n        read(0, buf, sizeof(buf));\n    } while (1);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":127,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-419","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/comments?post=419"}],"version-history":[{"count":1,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/419\/revisions"}],"predecessor-version":[{"id":420,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/419\/revisions\/420"}],"up":[{"embeddable":true,"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/pages\/127"}],"wp:attachment":[{"href":"http:\/\/bitas.net.cn\/index.php\/wp-json\/wp\/v2\/media?parent=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}