{"id":38872,"date":"2025-05-21T15:36:10","date_gmt":"2025-05-21T07:36:10","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38872.html"},"modified":"2025-05-21T15:36:10","modified_gmt":"2025-05-21T07:36:10","slug":"%e3%80%90linux%e3%80%91%e5%ae%88%e6%8a%a4%e8%bf%9b%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38872.html","title":{"rendered":"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521073608-682d8268b77e1.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e2a\u4eba\u4e3b\u9875~<\/p>\n<hr \/>\n<h4>\u5b88\u62a4\u8fdb\u7a0b<\/h4>\n<ul>\n<li>\u4e00\u3001\u5b88\u62a4\u8fdb\u7a0b\u7684\u6982\u5ff5<\/li>\n<li>\u4e8c\u3001\u8c03\u7528\u63a5\u53e3<\/li>\n<li>\n<ul>\n<li>1\u3001\u521b\u5efa\u65b0\u4f1a\u8bdd<\/li>\n<li>2\u3001\u5b88\u62a4\u8fdb\u7a0b<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u8fdb\u7a0b\u5c5e\u6027\u4fe1\u606f<\/li>\n<li>\u56db\u3001\u6df1\u5165\u7406\u89e3\u5b88\u62a4\u8fdb\u7a0b<\/li>\n<li>\n<ul>\n<li>1\u3001\u5b9e\u73b0\u8fc7\u7a0b<\/li>\n<li>2\u3001\u5b9e\u4f8b<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00\u3001\u5b88\u62a4\u8fdb\u7a0b\u7684\u6982\u5ff5<\/h2>\n<p>\u6211\u4eec\u5728\u524d\u9762\u7684\u535a\u6587\u300a\u8fdb\u7a0b\u4fe1\u53f7\u7684\u4ea7\u751f\u300b\u4e2d\u63d0\u5230\u8fc7\u524d\u53f0\u8fdb\u7a0b\u548c\u540e\u53f0\u8fdb\u7a0b\u7684\u6982\u5ff5&#xff0c;\u5b83\u4eec\u4e4b\u95f4\u7684\u533a\u522b\u5c31\u662f\u662f\u5426\u83b7\u5f97\u952e\u76d8\u6587\u4ef6&#xff0c;\u62e5\u6709\u952e\u76d8\u8f93\u5165\u7684\u5c31\u662f\u524d\u53f0\u8fdb\u7a0b&#xff0c;\u540e\u53f0\u8fdb\u7a0b\u83b7\u53d6\u4e0d\u5230\u952e\u76d8\u6587\u4ef6<\/p>\n<p>\u5b88\u62a4\u8fdb\u7a0b\u662f Linux \u7cfb\u7edf\u4e2d\u8fd0\u884c\u5728\u540e\u53f0\u7684\u7279\u6b8a\u8fdb\u7a0b&#xff0c;\u5177\u6709\u65e0\u7ec8\u7aef\u4f9d\u8d56\u3001\u957f\u671f\u8fd0\u884c\u3001\u6743\u9650\u5206\u79bb\u7b49\u7279\u70b9&#xff0c;\u901a\u5e38\u7528\u4e8e\u5b9e\u73b0\u7cfb\u7edf\u670d\u52a1\u3001\u7f51\u7edc\u670d\u52a1\u7b49\u529f\u80fd&#xff0c;\u8fdb\u884c\u5b88\u62a4\u8fdb\u7a0b\u5316\u7684\u8fdb\u7a0b\u5c31\u662f\u5c06\u7ec8\u7aef\u5173\u95ed\u4e5f\u4e0d\u4f1a\u6740\u6b7b&#xff0c;\u53ea\u8981\u670d\u52a1\u5668\u4e00\u76f4\u8fd0\u884c&#xff0c;\u5b83\u5c31\u53ef\u4ee5\u4e00\u76f4\u8fd0\u884c&#xff0c;\u4f46\u53ef\u4ee5\u901a\u8fc7kill\u547d\u4ee4\u6740\u6b7b<\/p>\n<h2>\u4e8c\u3001\u8c03\u7528\u63a5\u53e3<\/h2>\n<h3>1\u3001\u521b\u5efa\u65b0\u4f1a\u8bdd<\/h3>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token class-name\">pid_t<\/span> <span class=\"token function\">setsid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">void<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de\u65b0\u4f1a\u8bddid&#xff0c;\u5931\u8d25\u8fd4\u56de-1<\/p>\n<h3>2\u3001\u5b88\u62a4\u8fdb\u7a0b<\/h3>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token keyword\">int<\/span> <span class=\"token function\">daemon<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> nochdir<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">int<\/span> noclose<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de0&#xff0c;\u5931\u8d25\u8fd4\u56de-1 nochdir&#xff1a;\u5982\u679c\u8be5\u53c2\u6570\u7684\u503c\u4e3a 0&#xff0c;daemon \u51fd\u6570\u4f1a\u5c06\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u66f4\u6539\u4e3a\u6839\u76ee\u5f55&#xff08;\/&#xff09;&#xff0c;\u5982\u679c\u4e3a\u975e 0 \u503c&#xff0c;\u5219\u4e0d\u66f4\u6539\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55 noclose&#xff1a;\u5982\u679c\u8be5\u53c2\u6570\u7684\u503c\u4e3a 0&#xff0c;daemon \u51fd\u6570\u4f1a\u5c06\u6807\u51c6\u8f93\u5165\u3001\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u91cd\u5b9a\u5411\u5230 \/dev\/null&#xff0c;\u5982\u679c\u4e3a\u975e 0 \u503c&#xff0c;\u5219\u4e0d\u8fdb\u884c\u91cd\u5b9a\u5411<\/p>\n<h2>\u4e09\u3001\u8fdb\u7a0b\u5c5e\u6027\u4fe1\u606f<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521073608-682d8268ee01e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\n<p>1. PPID&#xff08;Parent Process ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u7236\u8fdb\u7a0bID<\/li>\n<li>\u542b\u4e49&#xff1a;\u5f53\u524d\u8fdb\u7a0b\u7684\u7236\u8fdb\u7a0b\u7684\u552f\u4e00\u6807\u8bc6\u7b26<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7528\u4e8e\u8ddf\u8e2a\u8fdb\u7a0b\u95f4\u7684\u7236\u5b50\u5173\u7cfb&#xff08;\u4f8b\u5982&#xff0c;\u901a\u8fc7fork()\u521b\u5efa\u7684\u5b50\u8fdb\u7a0b\u4f1a\u7ee7\u627f\u7236\u8fdb\u7a0b\u7684PPID&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>2. PID&#xff08;Process ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u8fdb\u7a0bID<\/li>\n<li>\u542b\u4e49&#xff1a;\u64cd\u4f5c\u7cfb\u7edf\u5206\u914d\u7ed9\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u552f\u4e00\u6570\u5b57\u6807\u8bc6\u7b26&#xff08;\u8303\u56f4\u901a\u5e38\u4e3a1~32768&#xff09;<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7528\u4e8e\u533a\u5206\u548c\u7ba1\u7406\u7cfb\u7edf\u4e2d\u7684\u4e0d\u540c\u8fdb\u7a0b&#xff08;\u4f8b\u5982&#xff0c;\u901a\u8fc7kill\u547d\u4ee4\u7ec8\u6b62\u8fdb\u7a0b&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>3. PGID&#xff08;Process Group ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u8fdb\u7a0b\u7ec4ID<\/li>\n<li>\u542b\u4e49&#xff1a;\u8fdb\u7a0b\u6240\u5c5e\u7684\u8fdb\u7a0b\u7ec4\u7684ID&#xff0c;\u8fdb\u7a0b\u7ec4\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u76f8\u5173\u8fdb\u7a0b\u7684\u96c6\u5408&#xff0c;\u4e00\u4e2a\u4efb\u52a1\u5bf9\u5e94\u4e00\u4e2a\u8fdb\u7a0b\u7ec4<\/li>\n<li>\u4f5c\u7528&#xff1a;\u4fbf\u4e8e\u6279\u91cf\u7ba1\u7406\u76f8\u5173\u8fdb\u7a0b&#xff08;\u5982\u505c\u6b62\u6216\u6062\u590d\u6574\u4e2a\u8fdb\u7a0b\u7ec4&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>4. SID&#xff08;Session ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u4f1a\u8bddID<\/li>\n<li>\u542b\u4e49&#xff1a;\u8fdb\u7a0b\u6240\u5c5e\u7684\u4f1a\u8bdd\u7684ID&#xff0c;\u4f1a\u8bdd\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u8fdb\u7a0b\u7ec4\u7ec4\u6210&#xff0c;\u901a\u5e38\u7531\u767b\u5f55 shell \u521b\u5efa&#xff0c;\u5b9e\u9645\u4e0a\u662fbash\u7684id<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7ba1\u7406\u7ec8\u7aef\u4f1a\u8bdd\u4e2d\u7684\u6240\u6709\u8fdb\u7a0b&#xff08;\u4f8b\u5982&#xff0c;\u5f53\u7528\u6237\u6ce8\u9500\u65f6&#xff0c;\u6574\u4e2a\u4f1a\u8bdd\u7684\u8fdb\u7a0b\u4f1a\u88ab\u7ec8\u6b62&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>5. TTY&#xff08;Teletypewriter&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u7ec8\u7aef\u8bbe\u5907<\/li>\n<li>\u542b\u4e49&#xff1a;\u8fdb\u7a0b\u5173\u8054\u7684\u7ec8\u7aef\u8bbe\u5907&#xff08;\u5982pts\/0\u8868\u793a\u4f2a\u7ec8\u7aef&#xff09;&#xff0c;\u82e5\u663e\u793a\u4e3a?&#xff0c;\u8868\u793a\u8fdb\u7a0b\u65e0\u63a7\u5236\u7ec8\u7aef<\/li>\n<li>\u4f5c\u7528&#xff1a;\u533a\u5206\u8fdb\u7a0b\u662f\u5426\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c&#xff08;\u5982\u540e\u53f0\u670d\u52a1\u901a\u5e38\u65e0\u7ec8\u7aef&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>6. TPGID&#xff08;Foreground Process Group ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u524d\u53f0\u8fdb\u7a0b\u7ec4ID<\/li>\n<li>\u542b\u4e49&#xff1a;\u5f53\u524d\u5728\u7ec8\u7aef\u524d\u53f0\u8fd0\u884c\u7684\u8fdb\u7a0b\u7ec4\u7684ID<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7ec8\u7aef\u8f93\u5165\/\u8f93\u51fa\u4f1a\u88ab\u5206\u914d\u7ed9\u524d\u53f0\u8fdb\u7a0b\u7ec4&#xff08;\u4f8b\u5982&#xff0c;\u6309Ctrl&#043;C\u4f1a\u4e2d\u65ad\u524d\u53f0\u8fdb\u7a0b&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>7. STAT&#xff08;Process Status&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u8fdb\u7a0b\u72b6\u6001<\/li>\n<li>\u542b\u4e49&#xff1a;\u8fdb\u7a0b\u7684\u5f53\u524d\u72b6\u6001&#xff0c;\u5e38\u89c1\u72b6\u6001\u7801\u5305\u62ec&#xff1a;\n<ul>\n<li>R&#xff08;\u8fd0\u884c\u4e2d&#xff09;<\/li>\n<li>S&#xff08;\u7761\u7720\u4e2d&#xff09;<\/li>\n<li>D&#xff08;\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720&#xff09;<\/li>\n<li>T&#xff08;\u505c\u6b62&#xff09;<\/li>\n<li>Z&#xff08;\u50f5\u5c38\u8fdb\u7a0b&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\u4f5c\u7528&#xff1a;\u5feb\u901f\u5224\u65ad\u8fdb\u7a0b\u7684\u8fd0\u884c\u72b6\u6001&#xff08;\u4f8b\u5982&#xff0c;Z\u8868\u793a\u8fdb\u7a0b\u5df2\u7ec8\u6b62\u4f46\u672a\u88ab\u7236\u8fdb\u7a0b\u56de\u6536&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>8. UID&#xff08;User ID&#xff09;<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u7528\u6237ID<\/li>\n<li>\u542b\u4e49&#xff1a;\u542f\u52a8\u8fdb\u7a0b\u7684\u7528\u6237\u7684\u552f\u4e00\u6807\u8bc6\u7b26&#xff08;\u5982root\u7684UID\u4e3a0&#xff09;<\/li>\n<li>\u4f5c\u7528&#xff1a;\u7528\u4e8e\u6743\u9650\u63a7\u5236&#xff08;\u4f8b\u5982&#xff0c;\u666e\u901a\u7528\u6237\u65e0\u6cd5\u4fee\u6539root\u8fdb\u7a0b&#xff09;<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>9. TIME<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;CPU\u65f6\u95f4<\/li>\n<li>\u542b\u4e49&#xff1a;\u8fdb\u7a0b\u81ea\u542f\u52a8\u4ee5\u6765\u7d2f\u8ba1\u4f7f\u7528\u7684CPU\u65f6\u95f4&#xff08;\u683c\u5f0f\u4e3aHH:MM:SS&#xff09;<\/li>\n<li>\u4f5c\u7528&#xff1a;\u8861\u91cf\u8fdb\u7a0b\u5bf9CPU\u8d44\u6e90\u7684\u5360\u7528\u60c5\u51b5<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>10. COMMAND<\/p>\n<ul>\n<li>\u5168\u79f0&#xff1a;\u547d\u4ee4\u540d\u79f0<\/li>\n<li>\u542b\u4e49&#xff1a;\u542f\u52a8\u8fdb\u7a0b\u7684\u547d\u4ee4\u6216\u7a0b\u5e8f\u540d\u79f0&#xff08;\u5982bash\u3001nginx&#xff09;<\/li>\n<li>\u4f5c\u7528&#xff1a;\u5feb\u901f\u8bc6\u522b\u8fdb\u7a0b\u7684\u529f\u80fd&#xff08;\u4f8b\u5982&#xff0c;\u901a\u8fc7COMMAND\u5217\u5224\u65ad\u662f\u5426\u4e3a\u6076\u610f\u7a0b\u5e8f&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u540c\u4e00\u4e2asession\u5185\u542f\u52a8\u7684sid\u90fd\u4e00\u6837 \u540c\u4e00PGID\u7684&#xff0c;\u5373\u4e00\u4e2a\u7ec4\u5185\u7684&#xff0c;PID\u4e0ePGID\u76f8\u540c\u7684\u88ab\u79f0\u4e3a\u7ec4\u957f<\/p>\n<h2>\u56db\u3001\u6df1\u5165\u7406\u89e3\u5b88\u62a4\u8fdb\u7a0b<\/h2>\n<h3>1\u3001\u5b9e\u73b0\u8fc7\u7a0b<\/h3>\n<p>\u9996\u5148\u521b\u5efa\u5b50\u8fdb\u7a0b\u7136\u540e\u9000\u51fa\u7236\u8fdb\u7a0b&#xff0c;\u4f7f\u5b50\u8fdb\u7a0b\u5728\u540e\u53f0\u8fd0\u884c&#xff0c;\u7136\u540e\u521b\u5efa\u65b0\u4f1a\u8bdd&#xff0c;\u8131\u79bb\u6389\u539f\u4f1a\u8bdd\u548c\u63a7\u5236\u7ec8\u7aef&#xff0c;\u4fdd\u8bc1\u8fdb\u7a0b\u4e0d\u53d7\u7ec8\u7aef\u4fe1\u53f7\u5f71\u54cd&#xff0c;\u7136\u540e\u518d\u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u5165\u8f93\u51fa&#xff0c;\u786e\u4fdd\u5b88\u62a4\u8fdb\u7a0b\u4e0d\u4e0e\u7ec8\u7aef\u4ea4\u4e92&#xff0c;\u7136\u540e\u53d8\u66f4\u5de5\u4f5c\u76ee\u5f55&#xff0c;\u5ffd\u7565\u6389\u5b50\u8fdb\u7a0b\u9000\u51fa\u4fe1\u53f7\u548c\u7ec8\u7aef\u505c\u6b62\u4fe1\u53f7&#xff0c;\u6240\u4ee5\u5b88\u62a4\u8fdb\u7a0b\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5b64\u513f\u8fdb\u7a0b<\/p>\n<h3>2\u3001\u5b9e\u4f8b<\/h3>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;sys\/types.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;fcntl.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;syslog.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token function\">daemonize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u521b\u5efa\u5b50\u8fdb\u7a0b\u5e76\u9000\u51fa\u7236\u8fdb\u7a0b&#xff0c;\u5b50\u8fdb\u7a0b\u6210\u4e3a\u5b64\u513f\u8fdb\u7a0b<\/span><br \/>\n    <span class=\"token class-name\">pid_t<\/span> pid <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">fork<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pid <span class=\"token operator\">&lt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_FAILURE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>pid <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_SUCCESS<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u521b\u5efa\u65b0\u4f1a\u8bdd&#xff0c;\u8c03\u7528\u8be5\u51fd\u6570\u7684\u8fdb\u7a0b\u4f1a\u6210\u4e3a\u65b0\u4f1a\u8bdd\u7684\u4f1a\u8bdd\u9996\u8fdb\u7a0b\u3001\u65b0\u8fdb\u7a0b\u7ec4\u7684\u7ec4\u957f\u8fdb\u7a0b<\/span><br \/>\n    <span class=\"token comment\">\/\/\u5e76\u4e14\u4f1a\u8131\u79bb\u539f\u6709\u7684\u63a7\u5236\u7ec8\u7aef<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">setsid<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token function\">exit<\/span><span class=\"token punctuation\">(<\/span>EXIT_FAILURE<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u91cd\u5b9a\u5411\u6807\u51c6\u8f93\u5165\u8f93\u51fa<\/span><br \/>\n    <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>STDIN_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>STDOUT_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span>STDERR_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">int<\/span> fd <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">open<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/dev\/null&#034;<\/span><span class=\"token punctuation\">,<\/span> O_RDWR<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">dup2<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> STDIN_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">dup2<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> STDOUT_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token function\">dup2<\/span><span class=\"token punctuation\">(<\/span>fd<span class=\"token punctuation\">,<\/span> STDERR_FILENO<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5141\u8bb8\u6240\u6709\u6743\u9650<\/span><br \/>\n    <span class=\"token function\">umask<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u53d8\u66f4\u5de5\u4f5c\u76ee\u5f55<\/span><br \/>\n    <span class=\"token function\">chdir<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5ffd\u7565\u5b50\u8fdb\u7a0b\u72b6\u6001\u6539\u53d8\u65f6\u53d1\u9001\u7ed9\u7236\u8fdb\u7a0b\u7684\u4fe1\u53f7<\/span><br \/>\n    <span class=\"token function\">signal<\/span><span class=\"token punctuation\">(<\/span>SIGCHLD<span class=\"token punctuation\">,<\/span> SIG_IGN<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token function\">daemonize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3600<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u6a21\u62df\u5de5\u4f5c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e0a\u9762\u7684\u8fc7\u7a0b&#xff0c;\u53ef\u4ee5\u88ab\u51fd\u6570daemon\u51fd\u6570\u66ff\u6362<\/p>\n<p><span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;unistd.h&gt;<\/span><\/span><br \/>\n<span class=\"token macro property\"><span class=\"token directive-hash\">#<\/span><span class=\"token directive keyword\">include<\/span> <span class=\"token string\">&lt;syslog.h&gt;<\/span><\/span><\/p>\n<p><span class=\"token keyword\">int<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u4f7f\u7528 daemon \u51fd\u6570\u5c06\u5f53\u524d\u8fdb\u7a0b\u8f6c\u6362\u4e3a\u5b88\u62a4\u8fdb\u7a0b<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7b2c\u4e00\u4e2a\u53c2\u6570 0 \u8868\u793a\u5c06\u5de5\u4f5c\u76ee\u5f55\u66f4\u6539\u4e3a\u6839\u76ee\u5f55<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u7b2c\u4e8c\u4e2a\u53c2\u6570 0 \u8868\u793a\u5c06\u6807\u51c6\u8f93\u5165\u3001\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u8f93\u51fa\u91cd\u5b9a\u5411\u5230 \/dev\/null<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token function\">daemon<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">perror<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;daemon&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6a21\u62df\u5b88\u62a4\u8fdb\u7a0b\u6301\u7eed\u5de5\u4f5c<\/span><br \/>\n    <span class=\"token keyword\">while<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u7761\u7720 3600 \u79d2&#xff08;1 \u5c0f\u65f6&#xff09;<\/span><br \/>\n        <span class=\"token function\">sleep<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">3600<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token keyword\">return<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<hr \/>\n<p>\u4eca\u65e5\u5206\u4eab\u5c31\u5230\u8fd9\u91cc\u4e86~ <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521073609-682d826905bba.jpg\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e56\u6b21\uff0c\u6536\u85cf56\u6b21\u3002\u5b88\u62a4\u8fdb\u7a0b\u7684\u5b9e\u73b0\uff0c\u6211\u4eec\u7684\u5f88\u591a\u670d\u52a1\u90fd\u662f\u57fa\u4e8e\u5b88\u62a4\u8fdb\u7a0b\u5b9e\u73b0\u7684<\/p>\n","protected":false},"author":2,"featured_media":38869,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,371,123,43,305,44],"topic":[],"class_list":["post-38872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-371","tag-123","tag-43","tag-305","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38872.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e56\u6b21\uff0c\u6536\u85cf56\u6b21\u3002\u5b88\u62a4\u8fdb\u7a0b\u7684\u5b9e\u73b0\uff0c\u6211\u4eec\u7684\u5f88\u591a\u670d\u52a1\u90fd\u662f\u57fa\u4e8e\u5b88\u62a4\u8fdb\u7a0b\u5b9e\u73b0\u7684\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38872.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-21T07:36:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521073608-682d8268b77e1.jpg\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38872.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38872.html\",\"name\":\"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-21T07:36:10+00:00\",\"dateModified\":\"2025-05-21T07:36:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38872.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38872.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38872.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38872.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e56\u6b21\uff0c\u6536\u85cf56\u6b21\u3002\u5b88\u62a4\u8fdb\u7a0b\u7684\u5b9e\u73b0\uff0c\u6211\u4eec\u7684\u5f88\u591a\u670d\u52a1\u90fd\u662f\u57fa\u4e8e\u5b88\u62a4\u8fdb\u7a0b\u5b9e\u73b0\u7684","og_url":"https:\/\/www.wsisp.com\/helps\/38872.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-21T07:36:10+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250521073608-682d8268b77e1.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38872.html","url":"https:\/\/www.wsisp.com\/helps\/38872.html","name":"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-21T07:36:10+00:00","dateModified":"2025-05-21T07:36:10+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38872.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38872.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38872.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux\u3011\u5b88\u62a4\u8fdb\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38872"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38872\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38869"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38872"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}