{"id":120218,"date":"2026-10-31T07:57:00","date_gmt":"2026-10-30T23:57:00","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/120218.html"},"modified":"2026-10-31T07:57:00","modified_gmt":"2026-10-30T23:57:00","slug":"linux12-%e7%ba%bf%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/120218.html","title":{"rendered":"linux(12) \u7ebf\u7a0b"},"content":{"rendered":"<h2>\u524d\u8a00&#xff1a;<\/h2>\n<p>\u9996\u5148\u5462&#xff0c;\u7ebf\u7a0b\u5c06\u4f1a\u662f\u6211\u4eeclinux\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u7ae0\u8282&#xff0c;\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u540e&#xff0c;\u6211\u4eec\u8fd8\u8981\u5199\u4e00\u4e2a\u7ebf\u7a0b\u6c60&#xff0c;\u90a3\u4e48\u6211\u4eec\u7684linux\u7cfb\u7edf\u5c31\u7ed3\u675f\u4e86&#xff1b;<\/p>\n<p>\u5728\u90a3\u4e4b\u540e&#xff0c;\u4f1a\u5f00\u59cb\u5199\u8ba1\u7b97\u673a\u7f51\u7edc\u76f8\u5173\u7684\u5185\u5bb9&#xff0c;\u5f53\u7136&#xff0c;\u4e5f\u4f1a\u5199\u4e00\u4e9bc&#043;&#043;,\u6216\u8005leetcode\u5237\u9898\u7684\u6587\u7ae0&#xff0c;\u4ee5\u524d\u503e\u5411\u4e8e\u505a\u7b14\u8bb0&#xff0c;\u73b0\u5728\u5f00\u59cb\u7528\u535a\u5ba2\u8bb0\u5f55&#xff0c;\u611f\u89c9\u6548\u679c\u4e5f\u4e0d\u9519&#xff08;\u5176\u5b9e\u662f\u5199\u5b57\u592a\u4e11\u81ea\u5df1\u4e5f\u4e0d\u8ba4\u8bc6&#xff09;<\/p>\n<p>\u90a3\u4e48\u5e9f\u8bdd\u5c11\u8bf4&#xff0c;\u6211\u4eec\u63a5\u4e0b\u6765\u5c31\u8fdb\u5165\u4eca\u5929\u7684\u6b63\u9898.\u7ebf\u7a0b\u6211\u6253\u7b97\u600e\u4e48\u8bb2&#xff1f;<\/p>\n<li>\u8981\u5c06\u7ebf\u7a0b&#xff0c;\u9996\u5148\u6211\u5f97\u7ed9\u5927\u5bb6\u5148\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0b\u7ebf\u7a0b&#xff0c;\u4f46\u662f\u5462&#xff0c;\u76f4\u63a5\u4e0a\u6765\u8c08\u7ebf\u7a0b&#xff0c;\u4f1a\u6709\u4e9b\u903b\u8f91\u4e0d\u592a\u6e05\u695a&#xff0c;\u6240\u4ee5\u5728\u6b64\u4e4b\u524d&#xff0c;\u6211\u4eec\u8981\u5bf9\u865a\u62df\u5730\u5740\u6765\u6700\u540e\u7684\u4e00\u6b21\u52a0\u6df1\u7406\u89e3&#xff0c;\u6211\u4eec\u8fd9\u4e00\u6b21&#xff0c;\u4f1a\u6765\u4ecb\u7ecd\u7269\u7406\u5730\u5740&#xff0c;\u4ee5\u53ca\u9875\u8868&#xff1b;<\/li>\n<li>\u4e4b\u540e\u5462&#xff0c;\u4fbf\u662f\u8bb2\u8bb2\u7ebf\u7a0b\u7684\u6982\u5ff5&#xff0c;\u4f18\u7f3a\u70b9&#xff0c;\u4ee5\u53ca\u7ebf\u7a0b\u4e4b\u95f4\u4ec0\u4e48\u662f\u5171\u4eab\u7684&#xff0c;\u4ec0\u4e48\u662f\u72ec\u7acb\u7684&#xff0c;\u8fd8\u6709\u5176\u4e0e\u8fdb\u7a0b\u7684\u5173\u7cfb&#xff0c;\u4ee5\u53ca\u5728\u4e0d\u540c\u64cd\u4f5c\u7cfb\u7edf\u4e0b\u7684\u533a\u522b<\/li>\n<li>\u5728\u6b64\u4e4b\u540e&#xff0c;\u6211\u4eec\u5c31\u6765\u6b63\u5f0f\u7406\u89e3\u7ebf\u7a0b\u7684\u4f7f\u7528\u4e86&#xff0c;\u6b63\u5982\u540c\u6211\u4eec\u8bb2\u89e3\u8fdb\u7a0b\u4e00\u6837&#xff0c;\u6211\u4eec\u4e5f\u662f\u8981\u8bb2\u7ebf\u7a0b\u7684\u521b\u5efa&#xff0c;\u7ec8\u6b62&#xff0c;\u7b49\u5f85&#8230;&#8230;<\/li>\n<li>\u5f53\u7136&#xff0c;\u5728\u6211\u4eec\u8bb23\u7684\u65f6\u5019&#xff0c;\u4f1a\u9047\u5230\u4e00\u4e2a\u95ee\u9898&#xff0c;\u201cid\u201d&#xff0c;\u65e0\u9700\u62c5\u5fc3&#xff0c;\u6211\u4eec\u81ea\u7136\u4f1a\u5728\u4e0b\u9762\u8fdb\u884c\u8bb2\u89e3<\/li>\n<li>\u4e4b\u540e&#xff0c;\u6211\u4eec\u8981\u8bb2\u7ebf\u7a0b\u4e0e\u7ebf\u7a0b\u4e4b\u95f4\u7684\u534f\u540c\u5de5\u4f5c\u4e86&#xff0c;\u5176\u4e2d\u7ed5\u4e0d\u5f00\u7684\u5c31\u662f&#xff1a;\u4e92\u65a5&#xff0c;\u540c\u6b65&#xff1b;\u6240\u4ee5&#xff0c;\u6211\u4eec\u8981\u8bb2\u89e3\u4e00\u4e0b\u9501\u548c\u6761\u4ef6\u53d8\u91cf<\/li>\n<li>\u518d\u7136\u540e&#xff0c;\u6211\u4eec\u4f1a\u804a\u4e00\u804a\u7ebf\u7a0b\u5b89\u5168\u7684\u8bdd\u9898&#xff08;\u5f53\u7136\u4e0e\u51fd\u6570\u91cd\u5165\u4e00\u8d77\u8bb2\u89e3&#xff09;<\/li>\n<li>\u6700\u540e\u6211\u4eec\u6765\u804a\u804a\u6b7b\u9501\u8fd9\u4e2a\u8bdd\u9898<\/li>\n<li>\u8fd9\u65f6\u5019\u6709\u4eba\u5c31\u8981\u95ee\u4e86&#xff0c;\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u6a21\u578b\u4e0d\u8bb2\u4e48&#xff1f;\u6211\u4eec\u7559\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0&#xff0c;\u6765\u5b9e\u73b0\u7ebf\u7a0b\u6c60\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u5728\u8fdb\u884c\u8be6\u7ec6\u4ecb\u7ecd<\/li>\n<p>\u597d&#xff0c;\u90a3\u4e48\u4ee5\u4e0a\u5c31\u662f\u6211\u4eec\u4eca\u5929\u7684\u4efb\u52a1\u4e86&#xff0c;\u611f\u89c9\u538b\u529b\u5de8\u5927\u5462&#8230;..<\/p>\n<h2>\u6b63\u6587&#xff1a;<\/h2>\n<\/p>\n<h3>\u5730\u5740\u7a7a\u95f4&#xff1a;<\/h3>\n<h4>\u865a\u62df\u5730\u5740\u7684\u7531\u6765&#xff1a;<\/h4>\n<p>\u9996\u5148\u6211\u4eec\u5df2\u7ecf\u8bb2\u8fc7\u4e09\u6b21\u865a\u62df\u5730\u5740\u7a7a\u95f4\u4e86&#xff0c;\u90a3\u4e48\u6211\u4eec\u4e3a\u4ec0\u4e48\u9700\u8981\u7528\u865a\u62df\u5730\u5740&#xff0c;\u901a\u8fc7\u9875\u8868\u6765\u6620\u5c04\u7269\u7406\u5185\u5b58\u5462&#xff0c;\u865a\u62df\u5730\u5740\u53c8\u662f\u600e\u4e48\u7f16\u5199\u7684&#xff0c;\u548c\u7269\u7406\u5185\u5b58\u7684\u5173\u7cfb\u662f\u4ec0\u4e48\u5462&#xff0c;\u6211\u4eec\u4ee5\u524d\u5e76\u6ca1\u6709\u63d0\u53ca\u8fc7&#xff0c;\u4e0d\u8fc7\u4eca\u5929\u6211\u4eec\u5c31\u8981\u4e00\u4e2a\u4e2a\u6765\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u9996\u5148\u6765\u770b&#xff0c;\u6211\u4eec\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u865a\u62df\u5730\u5740&#xff1f;<\/p>\n<p>\u7b54&#xff1a;\u5728\u6211\u4eec\u7684\u7269\u7406\u5185\u5b58\u4e4b\u4e2d&#xff0c;\u5fc5\u7136\u4f1a\u6709\u5f88\u591a\u7684\u8fdb\u7a0b&#xff0c;\u800c\u6bcf\u4e00\u4e2a\u8fdb\u7a0b&#xff0c;\u5b83\u7684\u5927\u5c0f\u5fc5\u7136\u90fd\u662f\u4e0d\u4e00\u6837\u7684&#xff0c;\u800c\u6bcf\u9694\u4e00\u4f1a&#xff0c;\u6709\u7684\u8fdb\u7a0b\u8981\u521b\u5efa&#xff0c;\u6709\u7684\u8fdb\u7a0b\u8981\u9000\u51fa&#xff0c;\u6240\u4ee5\u4e0d\u53ef\u907f\u514d\u7684&#xff0c;\u8fdb\u7a0b\u4e0e\u8fdb\u7a0b\u4e4b\u95f4&#xff0c;\u5c31\u4f1a\u5b58\u5728\u5f88\u591a\u7684\u201c\u788e\u7247\u201d&#xff1b;\u800c\u6211\u4eec\u4f5c\u4e3a\u7528\u6237&#xff0c;\u6211\u5e0c\u671b\u80fd\u65b9\u4fbf\u7684\u7ba1\u7406\u6211\u4eec\u7684\u8fdb\u7a0b&#xff0c;\u6240\u4ee5\u6211\u5e0c\u671b\u8fdb\u7a0b\u8fd9\u4e00\u5757\u5730\u5740&#xff0c;\u5b83\u662f\u8fde\u7eed\u7684&#xff0c;\u800c\u7ad9\u5728\u7269\u7406\u5185\u5b58\u89d2\u5ea6&#xff0c;\u6211\u53c8\u5e0c\u671b\u8fd9\u4e00\u7247\u8fdb\u7a0b\u5b83\u4e0d\u8fde\u7eed&#xff0c;\u8fd9\u6837\u6211\u5c31\u53ef\u4ee5\u628a\u6211\u7684\u788e\u7247\u5730\u5740\u7ed9\u5b83&#xff0c;\u8fd9\u6837\u53ef\u4ee5\u5b9e\u73b0\u6700\u5927\u7a0b\u5ea6\u7684\u5229\u7528&#xff1b;<\/p>\n<p>\u4f46\u663e\u7136&#xff0c;\u9762\u5bf9\u8fd9\u79cd\u8981\u6c42&#xff0c;\u53ea\u6709\u7269\u7406\u5185\u5b58&#xff0c;\u662f\u4e0d\u73b0\u5b9e\u7684<\/p>\n<p>\u6240\u4ee5\u8fd9\u65f6\u5019&#xff0c;\u6211\u4eec\u5c31\u63d0\u51fa\u4e86\u865a\u62df\u5730\u5740&#xff0c;\u6211\u4eec\u5728\u8fdb\u7a0b\u89d2\u5ea6\u4f7f\u7528\u865a\u62df\u5730\u5740&#xff0c;\u770b\u5230\u7684\u5c31\u662f\u4e00\u7247\u8fde\u7eed\u7684\u7a7a\u95f4&#xff0c;\u540c\u65f6\u901a\u8fc7\u9875\u8868\u6620\u5c04\u5230\u7269\u7406\u5730\u5740&#xff0c;\u6211\u5728\u7269\u7406\u5185\u5b58\u89d2\u5ea6&#xff0c;\u5c31\u53ef\u4ee5\u628a\u90a3\u4e9b\u788e\u7247\u5730\u5740\u548c\u5b83\u5efa\u7acb\u6620\u5c04&#xff0c;\u4ece\u800c\u5b9e\u73b0\u6211\u4eec\u4e0a\u8ff0\u7684\u76ee\u7684&#xff0c;\u8fd9\u5c31\u662f\u865a\u62df\u5730\u5740\u7684\u7531\u6765&#xff1b;<\/p>\n<h4>\u7269\u7406\u5185\u5b58\u662f\u600e\u4e48\u6837\u7684&#xff1f;<\/h4>\n<p>\u00a0\u6211\u4eec\u7684\u7269\u7406\u5185\u5b58&#xff0c;\u662f\u4ee5\u4e00\u4e2a\u4e2a\u9875\u6846\u8fdb\u884c\u5206\u5272\u7684&#xff0c;\u800c\u9875\u6846\u7684\u5927\u5c0f&#xff0c;32\u4f4d\u4e0b\u4e3a4kb,64\u4f4d\u4e0b\u4e3a8kb,\u6211\u4eec\u8fd9\u91cc\u5c31\u6309\u716732\u4f4d\u8bb2\u54af<\/p>\n<p>\u6211\u4eec32\u4f4d\u5e73\u53f0\u4e0b&#xff0c;\u7269\u7406\u5185\u5b58\u4e3a4GB&#xff0c;\u6211\u4eec\u628a\u5b83\u9664\u4ee54KB&#xff0c;\u53ef\u4ee5\u5f97\u52301024*1024&#xff0c;\u90a3\u4e48\u8fd9\u4e2a\u6570\u5b57&#xff0c;\u5c31\u662f\u6211\u4eec\u7684\u7269\u7406\u5185\u5b58\u4e2d&#xff0c;\u4f1a\u6709\u591a\u5c11\u4e2a\u9875\u6846&#xff08;1048576&#xff09;<\/p>\n<p>\u90a3\u4e48\u8fd9\u4e2a\u65f6\u5019&#xff0c;\u6709\u7684\u7269\u7406\u5185\u5b58\u6b63\u5728\u88ab\u4f7f\u7528&#xff0c;\u6709\u7684\u7269\u7406\u5185\u5b58\u6b63\u5728\u88ab\u91ca\u653e&#xff0c;\u6709\u7684\u7269\u7406\u5185\u5b58\u6b63\u5728\u88ab\u7533\u8bf7&#8230;&#8230;\u8fd9\u4e48\u591a\u72b6\u6001&#xff0c;\u6211\u4eec\u662f\u4e0d\u662f\u5e94\u8be5\u5bf9\u7269\u7406\u5185\u5b58\u8fdb\u884c\u7ba1\u7406&#xff1f;\u5f53\u7136\u8981&#xff0c;\u600e\u4e48\u7ba1\u7406&#xff1f;<\/p>\n<p>\u5148\u63cf\u8ff0\u518d\u7ec4\u7ec7<\/p>\n<p>\u63cf\u8ff0&#xff1a;<\/p>\n<p>\u6211\u4eec\u7528struct page\u6765\u8868\u793a\u7269\u7406\u5185\u5b58\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5185\u5b58\u9875&#xff0c;\u5f53\u7136&#xff0c;\u5b83\u7684\u6210\u5458\u5f88\u591a&#xff0c;\u6211\u4eec\u53ea\u662f\u5217\u51fa\u4e86\u4e00\u90e8\u5206&#xff0c;\u4f46\u662f\u522b\u770b\u6210\u5458\u591a&#xff0c;\u5176\u4e2d\u5927\u90e8\u5206\u4f7f\u7528\u4e86\u8054\u5408\u4f53&#xff08;union&#xff09;&#xff0c;\u6240\u4ee5\u5b83\u7684\u5b9e\u9645\u5927\u5c0f\u5e76\u4e0d\u4f1a\u592a\u5927<\/p>\n<p>struct page {<br \/>\n    unsigned long flags;        \/\/ \u3010\u91cd\u70b9\u3011\u9875\u72b6\u6001\u6807\u5fd7\u4f4d&#xff1a;PG_locked(\u9875\u9501)\u3001PG_dirty(\u810f\u9875)\u3001PG_reserved\u7b49<br \/>\n    union {<br \/>\n        struct list_head lru;   \/\/ \u3010\u91cd\u70b9\u3011LRU\u94fe\u8868\u8282\u70b9&#xff0c;\u9875\u9762\u56de\u6536\u7528&#xff08;\u51b7\u70ed\u9875&#xff0c;\u4f19\u4f34\u7cfb\u7edf\/kswapd&#xff09;<br \/>\n        struct page *next;<br \/>\n    };<br \/>\n    struct address_space *mapping; \/\/\u3010\u91cd\u70b9\u3011\u5f52\u5c5e&#xff1a;\u5c5e\u4e8e\u54ea\u4e2a\u9875\u7f13\u5b58&#xff08;\u6587\u4ef6\u6620\u5c04&#xff09;&#xff1b;NULL&#061;\u533f\u540d\u9875<br \/>\n    pgoff_t index;              \/\/\u3010\u91cd\u70b9\u3011\u5728address_space\u91cc\u7684\u504f\u79fb&#xff08;\u6587\u4ef6\u5185\u9875\u504f\u79fb&#xff09;<br \/>\n    atomic_t _refcount;         \/\/\u3010\u91cd\u70b9\u3011\u5f15\u7528\u8ba1\u6570&#xff01;\u591a\u5c11\u5730\u65b9\u6b63\u5728\u5f15\u7528\u8fd9\u4e2a\u7269\u7406\u9875&#xff0c;\u52300\u624d\u53ef\u4ee5\u91ca\u653e<br \/>\n    unsigned int mapcount;      \/\/\u3010\u91cd\u70b9\u3011\u9875\u8868\u6620\u5c04\u8ba1\u6570&#xff1a;\u591a\u5c11\u4e2a\u8fdb\u7a0b\u9875\u8868\u6620\u5c04\u4e86\u8fd9\u4e2a\u7269\u7406\u9875<br \/>\n    void *private;              \/\/ \u79c1\u6709\u6307\u9488&#xff1a;\u5757IO\u3001buffer_head\u3001slab\u7b49\u9644\u5c5e\u6570\u636e<br \/>\n};<\/p>\n<p>\u6211\u4eec\u5047\u8bbe\u5b83\u670950\u5b57\u8282\u7684\u5927\u5c0f&#xff0c;\u6211\u4eec\u5185\u5b58\u91cc\u67091024*1024\u4e2a\u5b83&#xff0c;\u90a3\u4e48\u6211\u4eec\u7684page\u7ed3\u6784\u4f53\u52a0\u8d77\u6765\u4e5f\u624d50MB&#xff0c;\u5e76\u4e0d\u7b97\u592a\u5927&#xff0c;\u6240\u4ee5\u6211\u4eec\u662f\u53ef\u4ee5\u63a5\u53d7\u7684&#xff1b;<\/p>\n<h4>\u9875\u8868&#xff1a;<\/h4>\n<p>\u6211\u4eec\u5728\u524d\u51e0\u6b21\u8bb2\u89e3\u865a\u62df\u5730\u5740\u7684\u65f6\u5019&#xff0c;\u6211\u4eec\u5bf9\u9875\u8868\u7684\u5370\u8c61\u8fd8\u505c\u7559\u4e8e&#xff0c;\u865a\u62df\u5730\u5740\u901a\u8fc7\u9875\u8868\u6620\u5c04\u7269\u7406\u5730\u5740&#xff0c;\u90a3\u4e48\u8fd9\u4e2a\u8fc7\u7a0b\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462&#xff1f;\u6211\u4eec\u5c31\u8981\u6765\u770b\u4e00\u4e0b\u9875\u8868\u7684\u7ed3\u6784\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u9996\u5148\u8981\u77e5\u9053&#xff0c;\u5185\u6838\u91cc\u9762\u521b\u5efa\u9875\u8868&#xff0c;\u662f\u901a\u8fc7\u4e00\u4e2a\u6570\u7ec4\u7684&#xff0c;\u800c\u6570\u7ec4\u53c8\u662f\u4e00\u6bb5\u4e0b\u6807\u8fde\u7eed\u7684\u7a7a\u95f4&#xff0c;\u800c\u6211\u4eec\u8981\u6620\u5c041024*1024\u4e2a\u9875\u6846&#xff0c;\u6211\u4eec\u5c31\u8981\u67091024*1024\u4e2a\u9875\u8868\u9879&#xff0c;\u5047\u8bbe\u6bcf\u4e00\u4e2a\u56db\u5b57\u8282&#xff0c;\u90a3\u4e48\u6700\u540e\u5373\u662f4MB&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u9875\u8868\u81ea\u5df1\u672c\u8eab&#xff0c;\u5c31\u8981\u5360\u75281024\u4e2a\u8fde\u7eed\u7684\u5185\u5b58\u5757&#xff0c;\u8fd9\u4f3c\u4e4e\u4e0e\u6211\u4eec\u6700\u5f00\u59cb\u7684\u76ee\u7684\u6709\u70b9\u80cc\u9053\u800c\u9a70\u4e86&#8230;&#8230;<\/p>\n<p>\u6211\u4eec\u6700\u5f00\u59cb\u5f15\u5165\u9875\u8868&#xff0c;\u5c31\u662f\u4e3a\u4e86\u589e\u52a0\u788e\u7247\u5316\u7269\u7406\u7a7a\u95f4\u7684\u4f7f\u7528\u7387&#xff0c;\u4f46\u662f\u73b0\u5728&#xff0c;\u5f15\u5165\u9875\u8868\u4e4b\u540e&#xff0c;\u5b83\u672c\u8eab\u5c31\u9700\u8981\u5927\u5757\u7684\u5b8c\u6574\u7a7a\u95f4&#xff0c;\u5e76\u4e14\u540c\u65f6&#xff0c;\u6211\u4eec\u4f3c\u4e4e\u5e76\u4e0d\u9700\u8981\u4f7f\u7528\u6240\u6709\u9875\u8868\u5427&#xff1f;\u6211\u4eec\u5728\u4e00\u4e2a\u8fdb\u7a0b\u4e2d&#xff0c;\u5f80\u5f80\u53ea\u9700\u8981\u4f7f\u7528\u4e09\u56db\u4e2a\u9875\u8868\u5c31\u8db3\u591f\u4e86&#xff0c;\u6240\u4ee5\u6b64\u65f6\u6211\u4eec\u60f3\u5230\u4e86\u4ec0\u4e48\u529e\u6cd5&#xff1f;<\/p>\n<p>\u6b63\u5982\u540c\u6211\u4eec\u5f53\u5e74\u5728\u8bb2\u6587\u4ef6\u7cfb\u7edf\u7684\u6570\u636e\u5757\u548cinode\u7684\u65f6\u5019&#xff0c;\u7531\u4e8e\u6570\u636e\u5757\u5b9e\u5728\u662f\u592a\u591a\u4e86&#xff0c;\u6211\u4eec\u4e3a\u4e86\u7528\u6709\u6548\u7684\u7a7a\u95f4\u8868\u793a\u8db3\u591f\u591a\u7684\u6570\u636e\u5757&#xff0c;\u6211\u4eec\u5c31\u5f15\u5165\u4e86\u5206\u7ea7\u6570\u636e\u5757&#xff0c;\u6b64\u65f6\u6211\u4eec\u4e5f\u53ef\u4ee5\u6309\u7167\u8fd9\u4e2a\u601d\u8def&#xff0c;\u5f15\u5165\u591a\u7ea7\u9875\u8868<\/p>\n<h5>\u957f\u4ec0\u4e48\u6837&#xff1a;<\/h5>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"729\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235656-6ae52ec8a4df9.png\" width=\"1029\" \/><\/p>\n<\/p>\n<p>\u6b64\u65f6&#xff0c;\u6211\u4eec\u5c31\u5f15\u5165\u4e86\u9875\u76ee\u5f55&#xff0c;\u4e5f\u5c31\u76f8\u5f53\u4e8e\u9875\u8868\u4e00\u7ea7\u7d22\u5f15\u4e86&#xff08;\u7406\u89e3\u4e0a&#xff09;&#xff0c;\u5b83\u5b58\u7684\u662f\u9875\u8868\u7684\u8d77\u59cb\u5730\u5740\u3002\u540c\u65f6&#xff0c;\u8be5\u5730\u5740\u4e5f\u662f\u7269\u7406\u5730\u5740&#xff0c;\u4e0d\u662f\u865a\u62df\u5730\u5740&#xff1b;<\/p>\n<p>\u9875\u76ee\u5f55\u4e2d\u5b58\u653e\u4e861024\u4e2a\u9875\u8868\u8d77\u59cb\u5730\u5740&#xff0c;\u800c\u6bcf\u4e2a\u9875\u8868\u91cc\u53c8\u67091024\u4e2a\u9875\u8868\u9879&#xff0c;\u6240\u4ee5\u4e00\u5171\u5c31\u53ef\u4ee5\u8868\u793a1024*1024\u4e2a\u5185\u5b58\u5757<\/p>\n<h5>\u4f4e\u5341\u4e8c\u4f4d&#xff1a;<\/h5>\n<p>\u800c\u9875\u8868\u5b58\u7684\u662f\u7269\u7406\u9875\u8d77\u59cb\u5730\u5740&#xff0c;\u4e5f\u662f\u7269\u7406\u5730\u5740&#xff0c;\u5e76\u4e14\u6307\u5411\u4e00\u6574\u57574KB\u7684\u7a7a\u95f4&#xff0c;\u6240\u4ee5\u8be5\u5730\u5740\u5fc5\u7136\u662f4096\u7684\u6574\u6570\u500d&#xff0c;4096\u53c8\u662f2^12&#xff0c;\u6240\u4ee5\u6211\u4eec\u9875\u8868\u7684\u4f4e\u5341\u4e8c\u4f4d&#xff0c;\u5176\u5b9e\u90fd\u662f\u4e3a0\u7684&#8230;&#8230;<\/p>\n<p>\u540c\u65f6&#xff0c;\u90a3\u9875\u76ee\u5f55\u4e2d\u5b58\u7684\u662f\u9875\u8868\u7684\u8d77\u59cb\u5730\u5740&#xff0c;\u9875\u8868\u672c\u8eab\u4e5f\u662f\u63094KB\u5bf9\u9f50\u5b58\u653e\u7684&#xff0c;\u6240\u4ee5\u9875\u8868\u8d77\u59cb\u5730\u5740\u4e5f\u662f4096\u7684\u6574\u6570\u500d&#xff0c;\u6240\u4ee5\u9875\u76ee\u5f55\u7684\u7b2c\u5341\u4e8c\u4f4d&#xff0c;\u4e5f\u90fd\u4e3a0&#xff1b;<\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u4ee5\u524d\u8bf4\u8fc7&#xff0c;\u9875\u8868\u4e2d\u53ef\u662f\u6709\u6743\u9650\u4f4d\u7684&#xff0c;\u90a3\u4e48\u5728\u54ea\u91cc\u5462&#xff1f;\u6ca1\u9519&#xff0c;\u5c31\u662f\u5728\u8fd9\u9875\u76ee\u5f55\u548c\u9875\u8868\u7684\u4f4e\u5341\u4e8c\u4f4d\u653e\u7740<\/p>\n<table>\n<tr>\u6807\u5fd7\u4f4d\u9875\u76ee\u5f55\u9879 PDE&#xff08;\u6307\u5411\u9875\u8868&#xff09;\u9875\u8868\u9879 PTE&#xff08;\u6307\u5411\u7269\u7406\u9875\u6846&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>P (\u7b2c 0 \u4f4d&#xff0c;Present)<\/td>\n<td>\u9875\u8868\u662f\u5426\u5728\u5185\u5b58\u3002P&#061;0&#xff1a;\u9875\u8868\u4e0d\u5728\u5185\u5b58&#xff0c;\u89e6\u53d1\u7f3a\u9875&#xff0c;\u5730\u5740\u5b57\u6bb5\u65e0\u6548<\/td>\n<td>\u7269\u7406\u9875\u662f\u5426\u5728\u5185\u5b58\u3002P&#061;0&#xff1a;\u7269\u7406\u9875\u4e0d\u5728\u5185\u5b58&#xff0c;\u7f3a\u9875\u5f02\u5e38<\/td>\n<\/tr>\n<tr>\n<td>R\/W (\u7b2c 1 \u4f4d&#xff0c;\u8bfb\u5199)<\/td>\n<td>\u63a7\u5236\u6574\u5f20\u9875\u8868\u4e0b\u6240\u6709\u9875\u7684\u8bfb\u5199\u6743\u9650&#xff08;\u53ef\u4ee5\u88ab PTE \u7684 R\/W \u7ec6\u5316\u7ea6\u675f&#xff09;<\/td>\n<td>\u63a7\u5236\u8fd9\u5355\u4e2a\u7269\u7406\u9875\u80fd\u4e0d\u80fd\u5199<\/td>\n<\/tr>\n<tr>\n<td>U\/S (\u7b2c 2 \u4f4d&#xff0c;\u7528\u6237 \/ \u8d85\u7ea7)<\/td>\n<td>\u6574\u5f20\u9875\u8868&#xff1a;0 &#061; \u5185\u6838\u6001\u624d\u80fd\u8bbf\u95ee&#xff1b;1 &#061; \u7528\u6237\u6001\u53ef\u8bbf\u95ee<\/td>\n<td>\u4ec5\u5f53\u524d\u8fd9\u4e00\u9875&#xff1a;0 &#061; \u5185\u6838\u6001&#xff1b;1 &#061; \u7528\u6237\u6001<\/td>\n<\/tr>\n<tr>\n<td>PWT (\u7b2c 3 \u4f4d)<\/td>\n<td>\u9875\u8868\u7684\u7f13\u5b58\u5199\u901a\u7b56\u7565<\/td>\n<td>\u5f53\u524d\u7269\u7406\u9875\u7684\u7f13\u5b58\u5199\u901a\u7b56\u7565<\/td>\n<\/tr>\n<tr>\n<td>PCD (\u7b2c 4 \u4f4d)<\/td>\n<td>\u662f\u5426\u7981\u6b62\u7f13\u5b58\u8fd9\u5f20\u9875\u8868<\/td>\n<td>\u662f\u5426\u7981\u6b62\u7f13\u5b58\u5f53\u524d\u7269\u7406\u9875<\/td>\n<\/tr>\n<tr>\n<td>A (\u7b2c 5 \u4f4d&#xff0c;Accessed)<\/td>\n<td>CPU \u8bbf\u95ee\u8fd9\u4e2a\u9875\u8868\u65f6&#xff0c;\u786c\u4ef6\u81ea\u52a8\u7f6e 1&#xff08;\u8bbf\u95ee\u6807\u8bb0&#xff09;<\/td>\n<td>CPU \u8bbf\u95ee\u8fd9\u4e2a\u7269\u7406\u9875\u65f6&#xff0c;\u786c\u4ef6\u81ea\u52a8\u7f6e 1<\/td>\n<\/tr>\n<tr>\n<td>D (\u7b2c 6 \u4f4d&#xff0c;Dirty)<\/td>\n<td>PDE\u6ca1\u6709 D \u4f4d&#xff01;\u6c38\u8fdc\u65e0\u6548<\/td>\n<td>\u9875\u5199\u5165\u65f6\u786c\u4ef6\u81ea\u52a8\u7f6e 1&#xff0c;\u7528\u6765\u5224\u65ad\u8981\u4e0d\u8981\u5237\u56de\u78c1\u76d8<\/td>\n<\/tr>\n<tr>\n<td>PAT (\u7b2c 7 \u4f4d)<\/td>\n<td>\u5185\u5b58\u7c7b\u578b\u6269\u5c55\u4f4d&#xff0c;\u914d\u5408 PWT\u3001PCD<\/td>\n<td>\u5185\u5b58\u7c7b\u578b\u6269\u5c55\u4f4d<\/td>\n<\/tr>\n<tr>\n<td>G (\u7b2c 8 \u4f4d&#xff0c;Global)<\/td>\n<td>PDE \u65e0 G \u4f4d<\/td>\n<td>\u5168\u5c40\u9875&#xff0c;\u5207\u6362 CR3 \u7684\u65f6\u5019 TLB \u4e0d\u5237\u8fd9\u4e2a\u8868\u9879<\/td>\n<\/tr>\n<tr>\n<td>9~11 \u4f4d<\/td>\n<td>\u4fdd\u7559\u4f4d&#xff0c;\u8f6f\u4ef6\u81ea\u7528<\/td>\n<td>\u4fdd\u7559\u4f4d&#xff0c;\u8f6f\u4ef6\u81ea\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4fbf\u662f\u4e8c\u8005\u7684\u5bf9\u6bd4&#xff0c;\u4e0d\u8fc7\u6700\u91cd\u8981\u7684\u662f&#xff1a;<\/p>\n<ul>\n<li>PDE \u7ba1\u4e00\u6574\u4e2a\u9875\u8868\u533a\u57df&#xff0c;\u7c92\u5ea6\u5927&#xff0c;\u6ca1\u6709\u810f\u4f4d D&#xff1b;<\/li>\n<li>PTE \u53ea\u7ba1\u5355\u72ec\u4e00\u9875\u7269\u7406\u5185\u5b58&#xff0c;\u7c92\u5ea6\u7cbe\u7ec6&#xff0c;\u6709\u810f\u4f4d D&#xff0c;\u8bb0\u5f55\u9875\u6709\u6ca1\u6709\u88ab\u4fee\u6539<\/li>\n<\/ul>\n<h5>\u901a\u8fc7\u865a\u62df\u5730\u5740\u7d22\u5f15\u7269\u7406\u5730\u5740&#xff1a;<\/h5>\n<p>\u9996\u5148\u6211\u4eec\u77e5\u9053&#xff0c;\u4e00\u4e2a\u865a\u62df\u5730\u57404\u5b57\u8282&#xff0c;\u670932\u4f4d&#xff1b;<\/p>\n<p>\u9875\u76ee\u5f55\u4e00\u51711024\u4e2a\u6210\u5458&#xff0c;2^10;<\/p>\n<p>\u9875\u8868\u91cc\u4e00\u51711024\u4e2a\u6210\u5458&#xff0c;2^10&#xff1b;<\/p>\n<p>\u800c\u5728\u4e00\u4e2a\u5185\u5b58\u5757\u4e2d4096\u4e2a\u5b57\u8282&#xff0c;2^12;<\/p>\n<p>\u6240\u4ee5\u865a\u62df\u5730\u5740&#xff0c;\u5b9e\u9645\u4e0a\u662f\u4ee5\u4e0a\u4e09\u8005\u62fc\u63a5\u800c\u6765&#xff0c;\u901a\u8fc7\u9ad810\u4f4d&#xff0c;\u4e2d10\u4f4d&#xff0c;\u4f4e12\u4f4d\u7684\u7d22\u5f15&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u9501\u5b9a\u7269\u7406\u5185\u5b58\u4e2d\u7684\u4efb\u4f55\u4e00\u4e2a\u5b57\u8282<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"944\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235657-6ae52ec9662e5.png\" width=\"1193\" \/><\/p>\n<p>\u7d22\u5f15\u6d41\u7a0b\u5982\u4e0a&#xff1b;<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u6b64\u65f6\u518d\u60f3\u60f3&#xff0c;\u865a\u62df\u5730\u5740&#xff0c;\u662f\u4e0d\u662f\u5c31\u6620\u5c04\u7740\u4e00\u5757\u7269\u7406\u5730\u5740&#xff0c;\u90a3\u4e48\u662f\u5426\u5c31\u8c61\u5f81\u7740\u8d44\u6e90&#xff0c;\u865a\u62df\u5730\u5740\u8d8a\u591a&#xff0c;\u662f\u4e0d\u662f\u6211\u6240\u5f97\u5230\u7684\u8d44\u6e90\u5c31\u8d8a\u591a&#xff1f;<\/p>\n<p>\u800c\u4e14\u6211\u4eec\u60f3\u60f3&#xff0c;\u8fd9\u4e2a\u67e5\u8868\u7684\u5de5\u4f5c&#xff0c;\u5b83\u4e00\u5b9a\u4f1a\u5f88\u9891\u7e41\u7684&#xff0c;\u56e0\u4e3a\u6211\u57fa\u672c\u65e0\u65f6\u65e0\u523b\u90fd\u5728\u8bbf\u95ee\u4e00\u4e2a\u5730\u5740&#xff0c;\u800c\u8fd9\u4e2a\u5de5\u4f5c&#xff0c;\u53c8\u975e\u5e38\u673a\u68b0\u5316&#xff0c;\u683c\u5916\u7684\u7b80\u5355&#xff0c;\u8fd9\u4e2a\u5de5\u4f5c\u4ea4\u7ed9\u8c01\u6765\u5e72\u5462&#xff1f;<\/p>\n<p>\u6ca1\u9519&#xff0c;\u786c\u4ef6\u7535\u8def\u6765\u5e72\u5c31\u975e\u5e38\u5408\u9002&#xff0c;\u6240\u4ee5\u67e5\u8868\u7684\u5de5\u4f5c&#xff0c;\u6211\u4eec\u4f1a\u4ea4\u7ed9MMU&#xff1b;\u800c\u4e0a\u8ff0\u6211\u4eec\u7684\u865a\u62df\u5730\u5740\u8f6c\u7269\u7406\u5730\u5740\u7684\u8fc7\u7a0b&#xff0c;\u5c31\u662fMMU\u5de5\u4f5c\u6d41\u7a0b<\/p>\n<p>\u4ee5\u4e0a&#xff0c;\u5c31\u662f\u6211\u4eec\u5173\u4e8e\u5730\u5740\u7a7a\u95f4\u7684\u6700\u540e\u4e00\u8bb2~\u7ed9\u5927\u5bb6\u8865\u4e0a\u4e86\u5b8c\u6574\u7684\u6982\u5ff5~<\/p>\n<h3>\u7ebf\u7a0b<\/h3>\n<h4>\u6982\u5ff5&#xff1a;<\/h4>\n<p><span style=\"color:#fe2c24\">\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d&#xff1b;<\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u7ebf\u7a0b\u662f CPU \u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d\u3002<\/span><\/p>\n<p>\u5728\u8fd9\u91cc\u5148\u7ea0\u6b63\u4e00\u4e0b\u4ee5\u524d\u7684\u4e00\u4e2a\u8bef\u533a&#xff0c;\u6211\u4eec\u4ee5\u524d\u8bb2\u7684\u65f6\u5019&#xff0c;CPU\u8c03\u5ea6\u7684\u4e0d\u662f\u8fdb\u7a0b\u4e48&#xff1f;<\/p>\n<p>\u5176\u5b9e&#xff0c;\u6211\u4eec\u5728\u5b66\u7ebf\u7a0b\u4ee5\u524d&#xff0c;\u6211\u4eec\u7684\u8fdb\u7a0b&#xff0c;\u90fd\u53ef\u4ee5\u770b\u4f5c\u662f\u53ea\u6709\u4e00\u4e2a\u7ebf\u7a0b\u7684\u8fdb\u7a0b&#xff01;<\/p>\n<p>\u54a6&#xff1f;\u6240\u4ee5\u4e00\u4e2a\u8fdb\u7a0b\u91cc\u9762&#xff0c;\u4f1a\u6709\u591a\u4e2a\u7ebf\u7a0b\u4e48&#xff1f;<\/p>\n<p>\u6ca1\u9519&#xff01;<\/p>\n<p><span style=\"color:#fe2c24\">\u5728\u2f00\u4e2a\u7a0b\u5e8f\u2fa5\u7684\u2f00\u4e2a\u6267\u2f8f\u8def\u7ebf\u5c31\u53eb\u505a\u7ebf\u7a0b&#xff08;thread&#xff09;\u3002\u66f4\u51c6\u786e\u7684\u5b9a\u4e49\u662f&#xff1a;\u7ebf\u7a0b\u662f\u201c\u2f00\u4e2a\u8fdb\u7a0b\u5185\u90e8 <\/span><\/p>\n<p><span style=\"color:#fe2c24\">\u7684\u63a7\u5236\u5e8f\u5217\u201d<\/span><\/p>\n<p>\u6240\u4ee5\u7ebf\u7a0b\u624d\u662fCPU\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d&#xff01;<\/p>\n<p>\u90a3\u4e48&#xff0c;\u7b2c\u4e00\u53e5\u8bdd\u5982\u4f55\u7406\u89e3\u5462&#xff1f;\u4ec0\u4e48\u53eb\u505a\u8fdb\u7a0b\u662f\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u8d44\u6e90\u5206\u914d\u7684\u57fa\u672c\u5355\u4f4d&#xff1f;\u4ec0\u4e48\u8d44\u6e90&#xff1f;\u8c01\u6765\u5206\u8d70\u5b83\u7684\u8d44\u6e90&#xff1f;<\/p>\n<p>\u6211\u4eec\u5148\u753b\u4e00\u5f20\u56fe&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"719\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235657-6ae52ec9d148f.png\" width=\"1200\" \/><\/p>\n<p>\u95ee\u95ee\u5927\u5bb6&#xff0c;\u8fd9\u5f20\u56fe\u91cc\u9762\u54ea\u4e9b\u6570\u636e\u5c5e\u4e8e\u6211\u4eec\u8fdb\u7a0b\u7684\u8d44\u6e90&#xff1f;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"808\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235658-6ae52eca2eb3f.png\" width=\"1249\" \/><\/p>\n<p>\u7b54\u6848\u662f\u7d2b\u6846\u90e8\u5206&#xff0c;\u6211\u7684pcb&#xff0c;\u9875\u8868&#xff0c;\u8fd8\u6709\u6574\u5757\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u90fd\u662f\u6211\u8fdb\u7a0b\u7684\u8d44\u6e90<\/p>\n<p>\u4ece\u56fe\u4e2d\u6211\u4eec\u4e5f\u53ef\u4ee5\u770b\u51fa&#xff0c;\u5728linux\u7cfb\u7edf\u4e2d&#xff0c;\u7ebf\u7a0b\u5176\u5b9e\u662f\u4e00\u4e2apcb?\u00a0<\/p>\n<p>\u6ca1\u9519\u5c31\u662f\u8fd9\u6837&#xff0c;\u5728linux\u7cfb\u7edf\u4e4b\u4e2d&#xff0c;\u5f53\u65f6\u8bbe\u8ba1\u7684\u65f6\u5019&#xff0c;\u5982\u679c\u8bbe\u8ba1\u7ebf\u7a0b\u7ed3\u6784\u4f53tcb&#xff0c;\u90a3\u6211\u662f\u4e0d\u662f\u8fd8\u8981\u91cd\u5199\u4e00\u6574\u5957\u914d\u5957\u7684\u51fd\u6570&#xff1f;\u8fd9\u5de5\u4f5c\u91cf\u6709\u70b9\u5927&#xff0c;\u6240\u4ee5\u6211\u4eec\u7684linux\u7a0b\u5e8f\u5458\u9009\u62e9\u76f4\u63a5\u590d\u7528pcb\u7684\u4ee3\u7801&#xff0c;\u6545\u5176\u5b9e\u5728linux\u5185\u6838\u4e4b\u4e2d&#xff0c;\u662f\u6ca1\u6709\u7ebf\u7a0b\u7684\u6982\u5ff5\u7684&#xff0c;\u6211\u4eec\u628a\u7ebf\u7a0b\u53eb\u505a\u8f7b\u91cf\u7ea7\u8fdb\u7a0b\u3002\u800c\u5728CPU\u773c\u4e2d&#xff0c;\u4e0d\u7ba1\u662f\u8fdb\u7a0b\u8fd8\u662f\u73b0\u573a&#xff0c;\u7edf\u4e00\u90fd\u662f\u8f7b\u91cf\u7ea7\u8fdb\u7a0b<\/p>\n<p>\u90a3\u4e48&#8230;..\u522b\u7684\u7cfb\u7edf\u4e5f\u8fd9\u6837\u4e48&#xff1f;<\/p>\n<p>\u5e76\u4e0d\u662f&#xff0c;\u5728Windows\u7cfb\u7edf\u4e4b\u4e2d&#xff0c;\u5b83\u771f\u7684\u7ed9\u7ebf\u7a0b\u8bbe\u8ba1\u4e86\u4e00\u4e2a\u72ec\u7acb\u7684\u7ed3\u6784\u4f53&#xff1a;<\/p>\n<ul>\n<li>EPROCESS&#xff1a;\u8fdb\u7a0b&#xff0c;\u627f\u8f7d\u8d44\u6e90&#xff08;\u5730\u5740\u7a7a\u95f4\u3001\u53e5\u67c4\u8868&#xff09;&#xff0c;\u4e00\u4efd<\/li>\n<li>ETHREAD&#xff1a;\u7ebf\u7a0b&#xff0c;\u53ea\u627f\u8f7d\u8c03\u5ea6\u4e0a\u4e0b\u6587&#xff0c;\u4f9d\u9644\u5728 EPROCESS \u4e0a&#xff1b;\u5185\u6838\u539f\u751f\u5c31\u628a\u8fdb\u7a0b\u3001\u7ebf\u7a0b\u5206\u6210\u4e24\u79cd\u4e0d\u540c\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u5728Windows\u7cfb\u7edf\u4e4b\u4e2d&#xff0c;\u5b83\u662f\u6709\u7ebf\u7a0b\u7684\u6982\u5ff5\u7684&#xff1b;<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u6700\u540e\u603b\u7ed3\u4e00\u4e0b&#xff1a;<\/p>\n<p>Linux \u5185\u6838\u91cc&#xff0c;\u7ebf\u7a0b\u672c\u8d28\u5c31\u662f\u4e00\u6761\u72ec\u7acb\u6267\u884c\u6d41&#xff1b;\u5b83\u5728\u5185\u6838\u4e0a\u4f9d\u7136\u662f task_struct&#xff08;PCB&#xff09;&#xff0c;\u53ea\u662f\u5b83\u548c\u540c\u7ec4\u5176\u4ed6 task_struct \u5171\u4eab mm_struct\u3001\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\u7b49\u8fdb\u7a0b\u8d44\u6e90\u3002<\/p>\n<h4>\u4f18\u7f3a\u70b9&#xff1a;<\/h4>\n<h5>\u4f18\u70b9&#xff1a;<\/h5>\n<li>\u5207\u6362\u5f00\u9500\u5c0f&#xff1a;\u540c\u8fdb\u7a0b\u7ebf\u7a0b\u5207\u6362&#xff0c;\u4e0d\u9700\u8981\u5207\u6362\u9875\u8868&#xff08;\u4e0d\u7528\u6362 CR3&#xff09;&#xff0c;\u53ea\u6362\u5bc4\u5b58\u5668\u3001\u6808\u3001TLS&#xff0c;\u6bd4\u8fdb\u7a0b\u5207\u6362\u5feb\u5f88\u591a\u3002<\/li>\n<li>\u901a\u4fe1\u7b80\u5355&#xff1a;\u5171\u4eab\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff0c;\u5168\u5c40\u53d8\u91cf\u3001\u5806\u53ef\u4ee5\u76f4\u63a5\u8bfb\u5199&#xff0c;\u4e0d\u7528\u8fdb\u7a0b\u95f4\u901a\u4fe1&#xff08;\u7ba1\u9053 \/ \u5171\u4eab\u5185\u5b58\u7b49&#xff09;\u3002<\/li>\n<li>\u521b\u5efa\u9500\u6bc1\u5feb&#xff1a;clone\u65f6\u53ea\u65b0\u5efa task_struct\u3001\u7ebf\u7a0b\u6808&#xff0c;\u4e0d\u7528\u91cd\u65b0\u5206\u914d mm_struct\u3001\u9875\u8868\u8fd9\u5957\u8d44\u6e90\u3002<\/li>\n<li>\u5145\u5206\u5229\u7528\u591a\u6838 CPU&#xff1a;\u4e00\u4e2a\u8fdb\u7a0b\u5185\u591a\u4e2a\u7ebf\u7a0b\u53ef\u4ee5\u5e76\u884c\u8dd1\u5728\u591a\u4e2a\u6838\u5fc3\u4e0a&#xff0c;\u63d0\u5347 CPU \u5bc6\u96c6\u578b\u3001IO \u5bc6\u96c6\u578b\u7a0b\u5e8f\u6548\u7387\u3002<\/li>\n<h5>\u7f3a\u70b9&#xff1a;<\/h5>\n<li>\u7f3a\u4e4f\u9694\u79bb&#xff0c;\u5b89\u5168\u6027\u5dee&#xff1a;\u4e00\u4e2a\u7ebf\u7a0b\u5d29\u6e83&#xff08;\u91ce\u6307\u9488\u3001\u8d8a\u754c&#xff09;&#xff0c;\u6574\u4e2a\u8fdb\u7a0b\u76f4\u63a5\u6302\u6389&#xff1b;\u8fdb\u7a0b\u4e4b\u95f4\u5929\u7136\u9694\u79bb\u3002<\/li>\n<li>\u5171\u4eab\u8d44\u6e90\u5e26\u6765\u5e76\u53d1\u95ee\u9898&#xff1a;\u591a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee\u5171\u4eab\u6570\u636e&#xff0c;\u4f1a\u4ea7\u751f\u7ade\u6001\u6761\u4ef6&#xff0c;\u9700\u8981\u9501\u3001\u6761\u4ef6\u53d8\u91cf&#xff0c;\u7f16\u7801\u96be\u5ea6\u4e0a\u5347&#xff0c;\u5bb9\u6613\u6b7b\u9501\u3002<\/li>\n<li>\u8d44\u6e90\u62a2\u5360&#xff1a;\u540c\u8fdb\u7a0b\u6240\u6709\u7ebf\u7a0b\u5171\u4eab\u6587\u4ef6\u63cf\u8ff0\u7b26\u3001\u4fe1\u53f7\u5904\u7406\u8868\u7b49&#xff0c;\u4fe1\u53f7\u3001fd \u5728\u591a\u7ebf\u7a0b\u573a\u666f\u884c\u4e3a\u4f1a\u53d8\u590d\u6742&#xff08;\u4fe1\u53f7\u53d1\u7ed9\u6574\u4e2a\u8fdb\u7a0b&#xff09;\u3002<\/li>\n<li>\u8c03\u8bd5\u66f4\u9ebb\u70e6&#xff1a;\u591a\u7ebf\u7a0b\u65f6\u5e8f\u4e0d\u786e\u5b9a&#xff0c;bug \u96be\u4ee5\u590d\u73b0&#xff08;\u6d77\u68ee\u5821 bug&#xff09;\u3002<\/li>\n<h4>\u5171\u4eab\u4e0e\u72ec\u7acb&#xff1a;<\/h4>\n<p>\u5f53\u7136&#xff0c;\u6211\u4eec\u7ebf\u7a0b\u4e4b\u95f4&#xff0c;\u6709\u5171\u4eab\u7684\u8d44\u6e90&#xff0c;\u4e5f\u6709\u72ec\u7acb\u7684\u8d44\u6e90&#xff1a;<\/p>\n<h5>\u5171\u4eab&#xff1a;<\/h5>\n<li>\u9875\u8868&#xff1a;CR3<\/li>\n<li>\u865a\u62df\u5730\u5740\u7a7a\u95f4<\/li>\n<li>\u6587\u4ef6\u76f8\u5173&#xff1a;\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868&#xff0c;\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55&#xff0c;umask<\/li>\n<li>\u4fe1\u53f7:\u4e09\u5f20\u8868&#xff0c;\u4fe1\u53f7\u662f\u53d1\u7ed9\u8fdb\u7a0b\u7684<\/li>\n<li>pid<\/li>\n<h5>\u72ec\u7acb&#xff1a;<\/h5>\n<li>\u6808&#xff1a;\u6bcf\u4e00\u4e2a\u7ebf\u7a0b\u5c24\u5176\u72ec\u7acb\u7684\u6808<\/li>\n<li>\u4e00\u4e9b\u5bc4\u5b58\u5668\u8d44\u6e90<\/li>\n<li>\u7ebf\u7a0bid(tid)<\/li>\n<li>\u7ebf\u7a0b\u5c40\u90e8\u5b58\u50a8&#xff1a;__thread<\/li>\n<h4>\u7ebf\u7a0b\u4e0e\u8fdb\u7a0b\u5173\u7cfb<\/h4>\n<p>\u8fdb\u7a0b\u662f\u8d44\u6e90\u5206\u914d\u7684\u5bb9\u5668&#xff0c;\u7ebf\u7a0b\u662f\u8dd1\u5728\u8fd9\u4e2a\u5bb9\u5668\u91cc\u9762\u3001\u5171\u4eab\u5bb9\u5668\u8d44\u6e90\u7684\u72ec\u7acb CPU \u6267\u884c\u6d41\u3002<\/p>\n<\/p>\n<h3>\u7ebf\u7a0b\u4f7f\u7528&#xff1a;<\/h3>\n<p>\u5934\u6587\u4ef6&#xff1a;&lt;pthread.h&gt;&#xff0c;\u7f16\u8bd1\u52a0 -lpthread<\/p>\n<h4>1. pthread_create \u521b\u5efa\u7ebf\u7a0b<\/h4>\n<p>int pthread_create(pthread_t *thread, const pthread_attr_t *attr,<br \/>\n                   void *(*start_routine)(void*), void *arg);<\/p>\n<ul>\n<li>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f\u8fd4\u56de 0&#xff0c;\u5931\u8d25\u8fd4\u56de\u9519\u8bef\u53f7&#xff08;\u4e0d\u8bbe\u7f6e errno&#xff09;<\/li>\n<li>\u53c2\u6570\n<li>thread&#xff1a;\u8f93\u51fa\u578b\u53c2\u6570&#xff0c;\u62ff\u5230\u65b0\u7ebf\u7a0b id<\/li>\n<li>attr&#xff1a;\u7ebf\u7a0b\u5c5e\u6027&#xff0c;NULL \u7528\u9ed8\u8ba4&#xff08;\u53ef\u8bbe\u7f6e\u5206\u79bb\u6001\u3001\u6808\u5927\u5c0f&#xff09;<\/li>\n<li>start_routine&#xff1a;\u7ebf\u7a0b\u5165\u53e3\u51fd\u6570&#xff0c;\u7b7e\u540d\u56fa\u5b9a&#xff1a;void* func(void*)<\/li>\n<li>arg&#xff1a;\u4f20\u7ed9\u5165\u53e3\u51fd\u6570\u7684\u53c2\u6570&#xff0c;\u53ea\u80fd\u4f20\u4e00\u4e2a<\/li>\n<\/li>\n<li>\u7ec6\u8282&#xff1a;\n<ul>\n<li>\u65b0\u7ebf\u7a0b\u548c\u4e3b\u7ebf\u7a0b\u5171\u4eab\u5730\u5740\u7a7a\u95f4&#xff0c;\u6808\u72ec\u7acb<\/li>\n<li>\u7ebf\u7a0b\u8c03\u5ea6\u987a\u5e8f\u4e0d\u786e\u5b9a&#xff0c;\u521b\u5efa\u5b8c\u4e0d\u4e00\u5b9a\u7acb\u523b\u8dd1<\/li>\n<li>\u9ed8\u8ba4\u662f\u53ef\u7ed3\u5408\u6001&#xff08;joinable&#xff09;&#xff0c;\u5fc5\u987b join&#xff0c;\u5426\u5219\u8d44\u6e90\u6cc4\u6f0f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. pthread_exit \u7ebf\u7a0b\u7ec8\u6b62<\/h4>\n<p>void pthread_exit(void *retval);<\/p>\n<ul>\n<li>\u4f5c\u7528&#xff1a;\u672c\u7ebf\u7a0b\u4e3b\u52a8\u9000\u51fa&#xff0c;\u4e0d\u4f1a\u5f71\u54cd\u540c\u8fdb\u7a0b\u5176\u4ed6\u7ebf\u7a0b<\/li>\n<li>retval&#xff1a;\u9000\u51fa\u8fd4\u56de\u503c&#xff0c;\u540e\u9762 pthread_join \u53ef\u4ee5\u62ff\u5230<\/li>\n<li>\u7ec6\u8282\u91cd\u70b9&#xff1a;\n<ul>\n<li>return \u5728\u5165\u53e3\u51fd\u6570\u91cc\u7b49\u4ef7 pthread_exit&#xff1b;\u4e3b\u7ebf\u7a0b return &#061; \u6574\u4e2a\u8fdb\u7a0b\u9000\u51fa&#xff0c;\u6240\u6709\u7ebf\u7a0b\u5168\u6740<\/li>\n<li>\u4e0d\u8981\u5728\u7ebf\u7a0b\u91cc\u8c03\u7528 exit()&#xff0c;exit \u76f4\u63a5\u7ed3\u675f\u6574\u4e2a\u8fdb\u7a0b<\/li>\n<li>retval \u4e0d\u80fd\u662f\u7ebf\u7a0b\u6808\u4e0a\u5c40\u90e8\u53d8\u91cf&#xff08;\u7ebf\u7a0b\u9000\u51fa\u6808\u56de\u6536&#xff0c;\u91ce\u6307\u9488&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff0c;\u7ebf\u7a0b\u53ef\u4ee5\u8c03\u7528pthread_exit\u7ec8\u6b62\u81ea\u5df1&#xff0c;\u540c\u65f6\u4e5f\u53ef\u4ee5\u5728\u7ebf\u7a0b\u7684\u56de\u8c03\u51fd\u6570\u5185\u90e8return&#xff0c;\u4f46\u662f\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u4e3b\u7ebf\u7a0b\u4e0d\u9002\u7528&#xff0c;\u4e3b\u7ebf\u7a0breturn&#xff0c;\u90a3\u4e48\u6211\u7684\u6574\u4e2a\u8fdb\u7a0b\u90fd\u9000\u4e86<\/p>\n<h4>3. pthread_join \u7b49\u5f85\u7ebf\u7a0b<\/h4>\n<p>int pthread_join(pthread_t thread, void **retval);<\/p>\n<ul>\n<li>\u8fd4\u56de\u503c&#xff1a;\u6210\u529f 0&#xff0c;\u5931\u8d25\u9519\u8bef\u7801<\/li>\n<li>\u53c2\u6570\n<li>thread&#xff1a;\u8981\u7b49\u5f85\u7684\u7ebf\u7a0b ID<\/li>\n<li>retval&#xff1a;\u8f93\u51fa&#xff0c;\u63a5\u6536\u7ebf\u7a0b exit \u8fd4\u56de\u503c&#xff0c;\u4e0d\u9700\u8981\u4f20 NULL<\/li>\n<\/li>\n<li>\u7ec6\u8282\u91cd\u70b9&#xff1a;\n<ul>\n<li>\u963b\u585e\u7b49\u5f85\u76ee\u6807\u7ebf\u7a0b\u7ed3\u675f&#xff1b;\u76ee\u6807\u5df2\u7ecf\u7ed3\u675f&#xff0c;join \u76f4\u63a5\u8fd4\u56de<\/li>\n<li>\u53ea\u80fd\u7b49 joinable&#xff08;\u975e\u5206\u79bb&#xff09;\u7ebf\u7a0b&#xff0c;\u5206\u79bb\u7ebf\u7a0b pthread_join \u4f1a\u5931\u8d25<\/li>\n<li>\u4e00\u6b21 join \u53ea\u80fd\u56de\u6536\u4e00\u4e2a\u7ebf\u7a0b&#xff1b;\u56de\u6536\u540e\u8be5 tid \u5931\u6548&#xff0c;\u4e0d\u80fd\u91cd\u590d join<\/li>\n<li>\u7528\u9014&#xff1a;\u62ff\u5230\u8fd4\u56de\u503c &#043; \u56de\u6536\u7ebf\u7a0b\u5185\u6838\u8d44\u6e90&#xff08;PCB&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4. \u5206\u79bb\u7ebf\u7a0b&#xff1a;pthread_detach&#xff08;\u5206\u79bb&#xff0c;\u4e0d\u7528 join&#xff09;<\/h4>\n<p>int pthread_detach(pthread_t thread);<\/p>\n<ul>\n<li>\u628a\u7ebf\u7a0b\u8bbe\u4e3a\u5206\u79bb\u6001&#xff0c;\u7ebf\u7a0b\u7ed3\u675f\u81ea\u52a8\u91ca\u653e\u8d44\u6e90&#xff0c;\u4e0d\u80fd\u518d join<\/li>\n<\/ul>\n<h4>\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/h4>\n<p>\u597d&#xff0c;\u6211\u77e5\u9053\u5728\u8fd9\u91cc\u6211\u4eec\u4f1a\u6709\u4e00\u4e9b\u7591\u60d1&#xff0c;\u4e0d\u8fc7\u6211\u4eec\u7a0d\u540e\u89e3\u7b54&#xff0c;\u8fd8\u662f\u5148\u5199\u4e00\u6bb5\u4ee3\u7801<\/p>\n<p>#include&lt;stdio.h&gt;<br \/>\n#include&lt;pthread.h&gt;<br \/>\n#include&lt;unistd.h&gt;<br \/>\nvoid* thread_run(void* argc)<br \/>\n{<br \/>\n    for(int i&#061;0;i&lt;5;i&#043;&#043;)<br \/>\n    {<br \/>\n        sleep(1);<br \/>\n        printf(&#034;\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f%lu\\\\n&#034;,pthread_self());<br \/>\n        printf(&#034;%s\\\\n&#034;,(char*)argc);<br \/>\n    }<br \/>\n    return (void*)1;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    pthread_t id;<br \/>\n    pthread_create(&amp;id,nullptr,thread_run,(void*)&#034;ruonawa&#034;);<br \/>\n    printf(&#034;%lu\\\\n&#034;,id);<br \/>\n    sleep(7);<br \/>\n    void* ret;<br \/>\n    pthread_join(id,&amp;ret);<br \/>\n    printf(&#034;%d\\\\n&#034;,(int)ret);<br \/>\n    return 0;<\/p>\n<p>}<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c&#xff1a;<\/p>\n<p>wuchun&#064;VM-0-10-ubuntu:~\/10_28$ ps -aL<br \/>\n    PID     LWP TTY          TIME CMD<br \/>\n3115883 3115883 pts\/0    00:00:00 ceshi<br \/>\n3115883 3115884 pts\/0    00:00:00 ceshi<br \/>\n3115934 3115934 pts\/1    00:00:00 ps<\/p>\n<p>LWP&#061;gettid()<\/p>\n<p>tid\u662f\u5185\u6838\u8c03\u5ea6\u7684\u57fa\u672c\u5355\u4f4d<\/p>\n<p>\u6bcf\u4e2a\u7ebf\u7a0b\u552f\u4e00<\/p>\n<p>139259430303424<br \/>\n\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f139259430303424<br \/>\nruonawa<br \/>\n\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f139259430303424<br \/>\nruonawa<br \/>\n\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f139259430303424<br \/>\nruonawa<br \/>\n\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f139259430303424<br \/>\nruonawa<br \/>\n\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b\u6211\u7684id\u662f139259430303424<br \/>\nruonawa<br \/>\n1<\/p>\n<p>\u6211\u4eec\u5728\u8fd9\u91cc\u4f1a\u53d1\u73b0&#xff0c;\u7ebf\u7a0bid\u662f\u4e00\u4e2a\u5f88\u957f\u7684\u6570\u5b57\u90a3\u8fd9\u4e2a\u6570\u5b57\u662f\u4ec0\u4e48\u5462&#xff1f;<\/p>\n<h3><\/h3>\n<h3>\u7ebf\u7a0bid<\/h3>\n<p>\u6211\u4eec\u9996\u5148\u77e5\u9053&#xff0c;\u5728linux\u5185\u6838\u4e2d&#xff0c;\u5176\u5b9e\u662f\u6ca1\u6709\u7ebf\u7a0b\u7684\u6982\u5ff5\u7684&#xff0c;\u4f46\u662f&#xff0c;\u5185\u6838\u4e2d\u6ca1\u6709&#xff0c;\u4e0d\u4ee3\u8868\u4e0d\u80fd\u5728\u5e93\u91cc\u9762\u5c01\u88c5\u4e00\u4e2a&#xff0c;\u6240\u4ee5\u6211\u4eec\u7684linux\u5728\u539f\u751f\u7ebf\u7a0b\u5e93\u4e2d&#xff0c;\u5c01\u88c5\u4e86\u7ebf\u7a0b&#xff1b;<\/p>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"902\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235658-6ae52eca89d1f.png\" width=\"1005\" \/><\/p>\n<p>struct thread \u5c31\u662f\u7ebf\u7a0b\u5728\u5e93\u4e2d\u7684\u5c01\u88c5&#xff0c;\u800cthread_t,\u5219\u662f\u6307\u5411struct thread \u7684\u6307\u9488&#xff1a;<\/p>\n<p>\u5728 glibc \u7684 NPTL \u5b9e\u73b0\u91cc&#xff1a; pthread_t &#061; struct pthread *<\/p>\n<p>\u5c31\u662f\u6307\u5411\u8fd9\u4e2a\u7528\u6237\u6001\u7ebf\u7a0b\u63a7\u5236\u5757\u7684\u6307\u9488\u3002<\/p>\n<p>\u5728\u8fd9\u91cc\u533a\u5206\u4e00\u4e0b&#xff1a;<\/p>\n<li>\u5185\u6838\u8bc6\u522b&#xff1a;gettid ()&#xff0c;\u5185\u6838 task_struct \u91cc\u7684\u7ebf\u7a0b id&#xff0c;\u5185\u6838\u8c03\u5ea6\u3001\u4fe1\u53f7\u3001\u7cfb\u7edf\u8c03\u7528\u770b\u8fd9\u4e2a\u3002<\/li>\n<li>pthread \u5e93\u3001\u7528\u6237\u4ee3\u7801\u8bc6\u522b&#xff1a;pthread_self ()&#xff0c;\u8fd4\u56depthread_t&#xff08;struct pthread*&#xff09;&#xff0c;\u5e93\u7684\u63a5\u53e3&#xff08;join\u3001detach&#xff09;\u8ba4\u5b83<\/li>\n<p>struct pthread<br \/>\n{<br \/>\n    \/\/ TCB \u7ebf\u7a0b\u63a7\u5236\u5757\u5934&#xff0c;TLS\u4f9d\u8d56<br \/>\n    tcbhead_t header;<\/p>\n<p>    void *start_routine;   \/\/ \u4f60\u7684\u7ebf\u7a0b\u56de\u8c03\u51fd\u6570<br \/>\n    void *arg;             \/\/ \u4f20\u7ed9\u56de\u8c03\u7684\u53c2\u6570<br \/>\n    void *result;          \/\/ \u91cd\u70b9&#xff1a;\u7ebf\u7a0b\u8fd4\u56de\u503c&#xff0c;pthread_join\u8bfb\u53d6\u7684\u5c31\u662f\u5b83<br \/>\n    int tid;               \/\/ \u5185\u6838tid&#xff08;gettid()\u7684\u503c&#xff09;<\/p>\n<p>    void *stackaddr;       \/\/ \u7ebf\u7a0b\u6808\u8d77\u59cb\u5730\u5740<br \/>\n    size_t stacksize;      \/\/ \u6808\u5927\u5c0f<br \/>\n    void *stack_guard;     \/\/ \u6808\u6ea2\u51fa\u4fdd\u62a4\u9875<\/p>\n<p>    int cancelstate;<br \/>\n    int canceltype;<br \/>\n    int canceled;<\/p>\n<p>    \/\/ \u5206\u79bb \/ \u53ef\u7ed3\u5408\u72b6\u6001\u6807\u8bb0<br \/>\n    enum<br \/>\n    {<br \/>\n        PTHREAD_JOINABLE,<br \/>\n        PTHREAD_DETACHED<br \/>\n    } joinstate;<\/p>\n<p>    \/\/ \u6e05\u7406\u56de\u8c03&#xff08;pthread_cleanup_push&#xff09;<br \/>\n    struct pthread_cleanup_buffer *cleanup;<\/p>\n<p>    dtv_t *dtv;            \/\/ TLS\u52a8\u6001\u5411\u91cf&#xff0c;__thread \u9760\u8fd9\u4e2a<br \/>\n    list_t list;           \/\/ \u5e93\u5185\u7ebf\u7a0b\u94fe\u8868\u8282\u70b9<br \/>\n};<\/p>\n<p>\u6240\u4ee5\u5462&#xff0c;\u6211\u7684\u7ebf\u7a0bid\u662f\u4ec0\u4e48&#xff1f;<\/p>\n<p>\u7b54&#xff1a;\u662f\u6307\u5411\u5e93\u4e2dstruct pthread\u7684\u6307\u9488<\/p>\n<p>\u540c\u65f6&#xff0c;\u6211\u4eec\u8bf4\u8fc7&#xff0c;\u6bcf\u4e2a\u7ebf\u7a0b\u62e5\u6709\u5176\u81ea\u5df1\u7684\u6307\u9488&#xff0c;\u90a3\u4e48\u5728\u54ea\u91cc&#xff1f;\u5728\u5e93\u4e2d&#xff0c;\u5e93\u4e2d\u7ed9\u5176\u5f00\u8f9f\u597d\u6808&#xff0c;\u7136\u540e\u5c06\u8d77\u59cb\u5730\u5740\u5b58\u5230 struct pthread\u4e4b\u4e2d<\/p>\n<p>\u540c\u65f6&#xff0c;\u6211\u4eec\u4e5f\u89e3\u51b3\u4e86\u5982\u4f55\u83b7\u53d6\u8fd4\u56de\u503c\u7684\u95ee\u9898&#xff0c;\u6211\u4eec\u8c03\u7528pthread_join,\u4ece\u800c\u901a\u8fc7\u4f20\u53c2\u4f20\u5165\u7684id\u627e\u5230\u4e86\u6211\u4eec\u7ebf\u7a0b\u5728\u5e93\u4e2d\u7684\u5730\u5740&#xff0c;\u4ece\u800c\u8bbf\u95eestruct pthread\u7ed3\u6784\u4f53&#xff0c;\u5176\u4e2d\u5c31\u5b58\u653e\u7740\u6211\u4eec\u7684\u8fd4\u56de\u503c<\/p>\n<p>\u8bdd\u8bf4&#xff0c;\u6709\u6ca1\u6709\u611f\u89c9\u5230\u6709\u4e00\u4e9b\u719f\u6089\u5462&#xff0c;\u8fd9\u6837\u7684\u5c01\u88c5&#xff08;tid\u4e0epthread&#xff09;&#8230;&#8230;\u4f3c\u4e4e\u6211\u4eec\u524d\u51e0\u8282\u8bfe\u8bb2\u7684\u6587\u4ef6\u7cfb\u7edffd\u4e0efile&#xff0c;\u662f\u540c\u4e00\u79cd<\/p>\n<h3>\u7ebf\u7a0b\u4e92\u65a5&#xff1a;<\/h3>\n<p>\u5148\u628a\u6982\u5ff5\u518d\u7ed9\u5927\u5bb6\u63d0\u4e00\u904d&#xff1a;<\/p>\n<li><span style=\"color:#646a73\">\u5171\u4eab\u8d44\u6e90&#xff1a;\u6ca1\u4ec0\u4e48\u8bf4\u7684<\/span><\/li>\n<li><span style=\"color:#646a73\">\u4e34\u754c\u8d44\u6e90&#xff1a;\u591a\u7ebf\u7a0b\u6267\u2f8f\u6d41\u88ab\u4fdd\u62a4\u7684\u5171\u4eab\u7684\u8d44\u6e90\u5c31\u53eb\u505a\u4e34\u754c\u8d44\u6e90 <\/span><\/li>\n<li><span style=\"color:#646a73\">\u4e34\u754c\u533a&#xff1a;\u6bcf\u4e2a\u7ebf\u7a0b\u5185\u90e8&#xff0c;\u8bbf\u95ee\u4e34\u754c\u8d44\u6e90\u7684\u4ee3\u7801&#xff0c;\u5c31\u53eb\u505a\u4e34\u754c\u533a <\/span><\/li>\n<li><span style=\"color:#646a73\">\u4e92\u65a5&#xff1a;\u4efb\u4f55\u65f6\u523b&#xff0c;\u4e92\u65a5\u4fdd\u8bc1\u6709\u4e14\u53ea\u6709\u2f00\u4e2a\u6267\u2f8f\u6d41\u8fdb\u2f0a\u4e34\u754c\u533a&#xff0c;\u8bbf\u95ee\u4e34\u754c\u8d44\u6e90&#xff0c;\u901a\u5e38\u5bf9\u4e34\u754c\u8d44\u6e90\u8d77<\/span><span style=\"color:#646a73\">\u4fdd\u62a4\u4f5c\u2f64 <\/span><\/li>\n<li><span style=\"color:#646a73\">\u539f\u2f26\u6027&#xff1a;\u4e0d\u4f1a\u88ab\u4efb\u4f55\u8c03\u5ea6\u673a\u5236\u6253\u65ad\u7684\u64cd\u4f5c&#xff0c;\u8be5\u64cd\u4f5c\u53ea\u6709\u4e24\u6001&#xff0c;\u8981\u4e48\u5b8c\u6210&#xff0c;<\/span><span style=\"color:#646a73\">\u8981\u4e48\u672a\u5b8c\u6210<\/span><\/li>\n<p>\u4e0b\u9762\u662f CPU \u786c\u4ef6\u5c42\u9762\u5b9e\u73b0\u539f\u5b50\u64cd\u4f5c\u7684\u4e24\u5927\u7c7b\u65b9\u5f0f&#xff1a;<\/p>\n<p>&#xff08;<span style=\"color:#fe2c24\">\u4e86\u89e3\u4e00\u4e0b\u5373\u53ef&#xff0c;\u6211\u4e3b\u8981\u60f3\u8bf4\u7684\u662f\u7b2c\u4e00\u70b9<\/span>&#xff09;<\/p>\n<p>\u2460\u5355\u6761\u6307\u4ee4\u539f\u5b50&#xff08;x86 \u5e38\u7528&#xff09;<\/p>\n<p>\u4e00\u6761\u6c47\u7f16\u6307\u4ee4&#xff0c;\u786c\u4ef6\u4fdd\u8bc1\u6574\u4e2a\u6267\u884c\u8fc7\u7a0b\u4e0d\u53ef\u88ab\u6253\u65ad\u3002<\/p>\n<ul>\n<li>\u81ea\u5e26\u539f\u5b50&#xff1a;xchg&#xff08;\u4ea4\u6362&#xff0c;\u81ea\u5e26\u9690\u5f0f lock&#xff09;<\/li>\n<li>lock\u524d\u7f00 &#043; \u666e\u901a\u6307\u4ee4&#xff1a;lock add \/ lock cmpxchg<\/li>\n<li>\u9002\u7528&#xff1a;x86 \u67b6\u6784\u3002<\/li>\n<li>\u7279\u70b9&#xff1a;\u4e00\u6761\u6307\u4ee4\u5b8c\u6210<\/li>\n<\/ul>\n<p>\u2461\u00a0 LL\/SC \u6307\u4ee4\u5bf9&#xff08;Load-Linked \/ Store-Conditional&#xff09; \u4e24\u6761\u914d\u5957\u6307\u4ee4\u914d\u5408\u5b9e\u73b0\u539f\u5b50&#xff0c;ARM\u3001RISC-V \u4f7f\u7528\u3002<\/p>\n<ul>\n<li>ll&#xff1a;\u8bfb\u53d6\u53d8\u91cf&#xff0c;\u786c\u4ef6\u6807\u8bb0\u76d1\u89c6\u8be5\u5185\u5b58\u5730\u5740<\/li>\n<li>sc&#xff1a;\u5c1d\u8bd5\u5199\u5165&#xff1b;\u5982\u679c\u8fd9\u6bb5\u5185\u5b58\u6ca1\u6709\u88ab\u522b\u7684 CPU \u4fee\u6539&#xff0c;\u5199\u5165\u6210\u529f&#xff0c;\u5426\u5219\u5931\u8d25\u91cd\u8bd5<\/li>\n<li>\u7279\u70b9&#xff1a;\u4e0d\u662f\u5355\u6761\u6307\u4ee4&#xff0c;\u4f9d\u9760\u786c\u4ef6\u76d1\u89c6\u6807\u8bb0&#xff0c;\u5931\u8d25\u9700\u8981\u5faa\u73af\u91cd\u8bd5<\/li>\n<\/ul>\n<p><span style=\"color:#fe2c24\">\u56de\u5f52\u4e3b\u9898&#xff1a;<\/span><\/p>\n<p>\u76f4\u63a5\u770b\u73b0\u8c61&#xff1a;<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\nint ticket &#061; 100;<br \/>\nvoid *thread_run(void *argc)<br \/>\n{<br \/>\n    char *id &#061; (char *)argc;<br \/>\n    while (1)<br \/>\n    {<br \/>\n        if (ticket &gt; 0)<br \/>\n        {<br \/>\n            usleep(100);<br \/>\n            printf(&#034;%s get ticket: %d\\\\n&#034;,(char*)argc,ticket);<br \/>\n            ticket&#8211;;<br \/>\n        }<br \/>\n        else{<br \/>\n            break;<br \/>\n        }<br \/>\n    }<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    pthread_t id1,id2,id3,id4;<br \/>\n    pthread_create(&amp;id1,nullptr,thread_run,(void*)&#034;thread_1&#034;);<br \/>\n    pthread_create(&amp;id2,nullptr,thread_run,(void*)&#034;thread_2&#034;);<br \/>\n    pthread_create(&amp;id3,nullptr,thread_run,(void*)&#034;thread_3&#034;);<br \/>\n    pthread_create(&amp;id4,nullptr,thread_run,(void*)&#034;thread_4&#034;);<br \/>\n    sleep(100);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u6211\u4eec\u4eca\u5929\u521b\u5efa\u4e86\u56db\u4e2a\u8fdb\u7a0b&#xff0c;\u6765\u6a21\u62df\u4e00\u4e2a\u62a2\u7968\u7684\u573a\u666f&#xff0c;\u90a3\u6211\u4eec\u8fd0\u884c\u8d77\u6765\u4f1a\u600e\u4e48\u6837\u5462&#xff1f;<\/p>\n<p>thread_1 get ticket: 100<br \/>\nthread_4 get ticket: 99<br \/>\nthread_2 get ticket: 98<br \/>\nthread_3 get ticket: 97<br \/>\nthread_1 get ticket: 96<br \/>\nthread_4 get ticket: 95<br \/>\nthread_2 get ticket: 95<br \/>\nthread_3 get ticket: 95<br \/>\nthread_1 get ticket: 95<br \/>\nthread_2 get ticket: 91<br \/>\nthread_3 get ticket: 90<br \/>\nthread_1 get ticket: 89<br \/>\nthread_4 get ticket: 88<br \/>\nthread_2 get ticket: 87<br \/>\nthread_3 get ticket: 86<br \/>\nthread_1 get ticket: 85<br \/>\nthread_4 get ticket: 87<br \/>\nthread_4 get ticket: 83<br \/>\nthread_1 get ticket: 82<br \/>\nthread_3 get ticket: 81<br \/>\nthread_2 get ticket: 80<br \/>\nthread_3 get ticket: 79<br \/>\nthread_1 get ticket: 79<br \/>\nthread_2 get ticket: 79<br \/>\nthread_4 get ticket: 78<br \/>\nthread_3 get ticket: 75<br \/>\nthread_1 get ticket: 74<br \/>\nthread_2 get ticket: 74<br \/>\nthread_4 get ticket: 74<br \/>\nthread_2 get ticket: 71<br \/>\nthread_1 get ticket: 71<br \/>\nthread_4 get ticket: 71<br \/>\nthread_3 get ticket: 71<br \/>\nthread_3 get ticket: 67<br \/>\nthread_4 get ticket: 67<br \/>\nthread_2 get ticket: 67<br \/>\nthread_1 get ticket: 67<br \/>\nthread_3 get ticket: 63<br \/>\nthread_4 get ticket: 63<br \/>\nthread_1 get ticket: 63<br \/>\nthread_2 get ticket: 63<br \/>\nthread_2 get ticket: 59<br \/>\nthread_3 get ticket: 59<br \/>\nthread_4 get ticket: 59<br \/>\nthread_1 get ticket: 57<br \/>\nthread_3 get ticket: 55<br \/>\nthread_2 get ticket: 55<br \/>\nthread_4 get ticket: 55<br \/>\nthread_1 get ticket: 55<br \/>\nthread_3 get ticket: 51<br \/>\nthread_1 get ticket: 50<br \/>\nthread_2 get ticket: 49<br \/>\nthread_4 get ticket: 48<br \/>\nthread_3 get ticket: 47<br \/>\nthread_1 get ticket: 46<br \/>\nthread_2 get ticket: 45<br \/>\nthread_4 get ticket: 44<br \/>\nthread_3 get ticket: 43<br \/>\nthread_4 get ticket: 42<br \/>\nthread_1 get ticket: 41<br \/>\nthread_2 get ticket: 40<br \/>\nthread_3 get ticket: 39<br \/>\nthread_2 get ticket: 38<br \/>\nthread_4 get ticket: 37<br \/>\nthread_1 get ticket: 36<br \/>\nthread_3 get ticket: 35<br \/>\nthread_1 get ticket: 34<br \/>\nthread_2 get ticket: 33<br \/>\nthread_4 get ticket: 32<br \/>\nthread_3 get ticket: 31<br \/>\nthread_1 get ticket: 30<br \/>\nthread_4 get ticket: 29<br \/>\nthread_2 get ticket: 28<br \/>\nthread_2 get ticket: 27<br \/>\nthread_4 get ticket: 26<br \/>\nthread_1 get ticket: 25<br \/>\nthread_3 get ticket: 24<br \/>\nthread_1 get ticket: 23<br \/>\nthread_4 get ticket: 22<br \/>\nthread_3 get ticket: 21<br \/>\nthread_2 get ticket: 20<br \/>\nthread_3 get ticket: 19<br \/>\nthread_4 get ticket: 18<br \/>\nthread_2 get ticket: 17<br \/>\nthread_3 get ticket: 16<br \/>\nthread_1 get ticket: 15<br \/>\nthread_3 get ticket: 14<br \/>\nthread_1 get ticket: 13<br \/>\nthread_2 get ticket: 12<br \/>\nthread_4 get ticket: 11<br \/>\nthread_3 get ticket: 10<br \/>\nthread_1 get ticket: 9<br \/>\nthread_2 get ticket: 8<br \/>\nthread_4 get ticket: 7<br \/>\nthread_2 get ticket: 6<br \/>\nthread_3 get ticket: 5<br \/>\nthread_1 get ticket: 4<br \/>\nthread_4 get ticket: 3<br \/>\nthread_2 get ticket: 2<br \/>\nthread_3 get ticket: 1<br \/>\nthread_1 get ticket: 0<br \/>\nthread_4 get ticket: -1<br \/>\nthread_2 get ticket: -2<\/p>\n<p>\u6211\u4eec\u53d1\u73b0&#xff0c;\u5c45\u7136\u8fd8\u80fd\u62a2\u52300&#xff0c;-1&#xff0c;-2&#xff1f;&#xff01;<\/p>\n<p>\u8fd9\u663e\u7136\u4e0d\u7b26\u5408\u5e38\u7406&#xff0c;\u4e5f\u4e0d\u7b26\u5408\u6211\u7684\u4ee3\u7801&#xff0c;\u6211\u660e\u660e\u8bbe\u7f6e\u4e86\u5224\u65ad&#xff0c;\u53ea\u6709\u5f53\u62a2\u7968\u65f6&#xff0c;\u7968\u6570\u5927\u4e8e0&#xff0c;\u6211\u624d\u53ef\u4ee5\u8fdb\u5165\u5faa\u73af&#xff0c;\u5f00\u59cb\u62a2\u7968\u7684&#xff0c;\u4e3a\u4ec0\u4e48\u8fd8\u4f1a\u51fa\u73b0\u8fd9\u4e2a\u95ee\u9898&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u4eca\u5929\u4e0d\u662f\u5355\u7ebf\u7a0b\u4e86&#xff0c;\u6211\u4eec\u662f\u591a\u7ebf\u7a0b&#xff01;&#xff01;&#xff01;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"764\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235658-6ae52ecac89d8.png\" width=\"1281\" \/><\/p>\n<p>\u5c31\u5982\u8fd9\u5f20\u56fe\u4e2d\u6240\u5199<\/p>\n<p>\u90a3\u4e48\u8fd9\u65f6\u5019\u5c31\u6709\u4eba\u8981\u8bf4\u4e86&#xff0c;\u54ce\u5440&#xff0c;\u90a3\u6211\u662f\u4e0d\u662f&#xff0c;\u53ea\u8981\u5728\u5224\u65ad\u8bed\u53e5\u91cc\u9762\u585e\u4e00\u4e2aticket&#8211;\u8bed\u53e5&#xff0c;\u662f\u4e0d\u662f\u4e00\u4e0b\u5b50\u5c31\u6267\u884c\u5b8c\u4e86&#xff0c;\u5c31\u4e0d\u4f1a\u56e0\u4e3a\u5207\u6362\u7ebf\u7a0b\u5bfc\u81f4\u7684\u5e76\u53d1\u95ee\u9898&#xff1f;<\/p>\n<p>\u6211\u4eec\u7684ticket&#8211;&#xff0c;\u5b83\u662f\u4e00\u6761\u8bed\u53e5\u5bf9\u5427&#xff1f;<\/p>\n<p>\u4f46\u6211\u4eec\u7684\u7a0b\u5e8f&#xff0c;\u5b83\u5b9e\u9645\u8981\u6267\u884c\u7684\u662f\u4e8c\u8fdb\u5236\u7a0b\u5e8f\u554a&#xff0c;\u4e8c\u8fdb\u5236\u7a0b\u5e8f\u53c8\u662f\u81ea\u6c47\u7f16\u8bed\u8a00\u800c\u6765&#xff0c;\u6211\u4eec\u6765\u770b\u770bticket&#8211;\u5728\u6c47\u7f16\u4e0b\u957f\u4ec0\u4e48\u6837\u5b50&#xff1f;<\/p>\n<p>\u53d6\u51faticket&#8211;\u90e8\u5206\u7684\u6c47\u7f16\u4ee3\u7801<br \/>\nobjdump -d a.out &gt; test.objdump<br \/>\n152 40064b: 8b 05 e3 04 20 00 mov 0x2004e3(%rip),%eax #600b34 &lt;ticket&gt;<br \/>\n153 400651: 83 e8 01 sub $0x1,%eax<br \/>\n154 400654: 89 05 da 04 20 00 mov %eax,0x2004da(%rip) #600b34 &lt;ticket&gt;<\/p>\n<p>\u53ef\u60dc\u4e86&#xff0c;\u539f\u672c\u4e00\u6761ticket&#8211;\u7684\u6307\u4ee4&#xff0c;\u5728\u6211\u4eec\u6c47\u7f16\u4ee3\u7801\u4e0b&#xff0c;\u53d8\u6210\u4e86\u4e09\u6761\u8bed\u53e5&#xff1b;<\/p>\n<p><span style=\"color:#646a73\">load <\/span><span style=\"color:#646a73\">&#xff1a;\u5c06\u5171\u4eab\u53d8\u91cfticket\u4ece\u5185\u5b58\u52a0\u8f7d\u5230\u5bc4\u5b58\u5668\u4e2d <\/span><\/p>\n<p><span style=\"color:#646a73\">update <\/span><span style=\"color:#646a73\">: \u66f4\u65b0\u5bc4\u5b58\u5668\u2fa5\u2faf\u7684\u503c&#xff0c;\u6267\u2f8f-1\u64cd\u4f5c <\/span><\/p>\n<p><span style=\"color:#646a73\">store <\/span><span style=\"color:#646a73\">&#xff1a;\u5c06\u65b0\u503c&#xff0c;\u4ece\u5bc4\u5b58\u5668\u5199\u56de\u5171\u4eab\u53d8\u91cfticket\u7684\u5185\u5b58\u5730\u5740<\/span><\/p>\n<p>\u6240\u4ee5\u6b64\u65f6&#xff0c;\u6211\u5c31\u60f3\u60f3&#xff0c;\u6211\u662f\u4e00\u4e2a\u7ebf\u7a0b&#xff0c;\u6211\u5728\u6267\u884c\u4e34\u754c\u533a\u7684\u65f6\u5019&#xff0c;\u6211\u4e0d\u60f3\u522b\u4eba\u4e5f\u8fdb\u6765&#xff0c;\u8fd9\u5c31\u9700\u8981\u9501&#xff01;<\/p>\n<h4>\u4e92\u65a5\u9501pthread_mutex_t&#xff1a;<\/h4>\n<p>pthread_mutex_t mutex;<\/p>\n<p>\u5b9a\u4e49\u9501\u53d8\u91cf<\/p>\n<p>pthread_mutex_init \u521d\u59cb\u5316\u9501<\/p>\n<p>int pthread_mutex_init(pthread_mutex_t *restrict mutex,<br \/>\n           const pthread_mutexattr_t *restrict attr);<\/p>\n<ul>\n<li>attr&#xff1a;\u9501\u5c5e\u6027&#xff0c;\u4f20NULL\u4ee3\u8868\u9ed8\u8ba4\u5c5e\u6027<\/li>\n<li>\u4f5c\u7528&#xff1a;\u628a\u9501\u521d\u59cb\u5316\u6210\u672a\u4e0a\u9501\u72b6\u6001<\/li>\n<li>\u7b80\u5199\u65b9\u5f0f&#xff08;\u9759\u6001\u521d\u59cb\u5316&#xff0c;\u5168\u5c40\u9501\u63a8\u8350&#xff09;&#xff1a;pthread_mutex_t mutex &#061; PTHREAD_MUTEX_INITIALIZER;<\/li>\n<\/ul>\n<p>pthread_mutex_lock \u52a0\u9501&#xff08;\u963b\u585e&#xff09;<\/p>\n<p>int pthread_mutex_lock(pthread_mutex_t *mutex);<\/p>\n<ul>\n<li>\u5982\u679c\u9501\u7a7a\u95f2&#xff1a;\u62ff\u5230\u9501&#xff0c;\u7ee7\u7eed\u5f80\u4e0b\u8d70<\/li>\n<li>\u5982\u679c\u9501\u5df2\u7ecf\u88ab\u522b\u4eba\u6301\u6709&#xff1a;\u963b\u585e\u6302\u8d77&#xff0c;\u5361\u5728\u8fd9\u4e00\u884c&#xff0c;\u76f4\u5230\u9501\u91ca\u653e<\/li>\n<\/ul>\n<p>pthread_mutex_trylock \u5c1d\u8bd5\u52a0\u9501&#xff08;\u975e\u963b\u585e&#xff09;<\/p>\n<p>int pthread_mutex_trylock(pthread_mutex_t *mutex);<\/p>\n<ul>\n<li>\u9501\u7a7a\u95f2&#xff1a;\u62ff\u5230\u9501&#xff0c;\u8fd4\u56de 0<\/li>\n<li>\u9501\u88ab\u5360\u7528&#xff1a;\u76f4\u63a5\u8fd4\u56deEBUSY&#xff0c;\u4e0d\u4f1a\u5361\u4f4f\u7ebf\u7a0b<\/li>\n<li>\u9002\u5408\u4e0d\u60f3\u963b\u585e\u7b49\u5f85\u7684\u573a\u666f<\/li>\n<\/ul>\n<p>pthread_mutex_unlock \u89e3\u9501<\/p>\n<p>int pthread_mutex_unlock(pthread_mutex_t *mutex);<\/p>\n<ul>\n<li>\u91ca\u653e\u9501&#xff0c;\u5524\u9192\u7b49\u5f85\u8fd9\u4e2a\u9501\u7684\u5176\u4ed6\u7ebf\u7a0b<\/li>\n<li>\u8c01\u52a0\u9501&#xff0c;\u8c01\u89e3\u9501&#xff1b;\u4e0d\u80fd\u89e3\u522b\u4eba\u7684\u9501<\/li>\n<\/ul>\n<p>pthread_mutex_destroy \u9500\u6bc1\u9501<\/p>\n<p>int pthread_mutex_destroy(pthread_mutex_t *mutex);<\/p>\n<ul>\n<li>\u91ca\u653e\u9501\u5185\u90e8\u8d44\u6e90<\/li>\n<li>\u9759\u6001\u521d\u59cb\u5316PTHREAD_MUTEX_INITIALIZER\u7684\u9501&#xff0c;\u53ef\u4ee5\u4e0d destroy<\/li>\n<\/ul>\n<p>\u90a3\u4e48&#xff0c;\u6211\u4eec\u73b0\u5728\u5c31\u7528\u4e00\u628a\u9501&#xff0c;\u6765\u4fee\u6539\u4e00\u4e0b\u6211\u4eec\u7684\u62a2\u7968\u4ee3\u7801<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\npthread_mutex_t mutex&#061;PTHREAD_MUTEX_INITIALIZER;<br \/>\nint ticket &#061; 100;<br \/>\nvoid *thread_run(void *argc)<br \/>\n{<br \/>\n    char *id &#061; (char *)argc;<br \/>\n    while (1)<br \/>\n    {<br \/>\n        pthread_mutex_lock(&amp;mutex);<br \/>\n        if (ticket &gt; 0)<br \/>\n        {<br \/>\n            usleep(100);<br \/>\n            printf(&#034;%s get ticket: %d\\\\n&#034;,(char*)argc,ticket);<br \/>\n            ticket&#8211;;<br \/>\n        }<br \/>\n        else{<br \/>\n            break;<br \/>\n        }<br \/>\n        pthread_mutex_unlock(&amp;mutex);<br \/>\n    }<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    pthread_t id1,id2,id3,id4;<br \/>\n    pthread_create(&amp;id1,nullptr,thread_run,(void*)&#034;thread_1&#034;);<br \/>\n    pthread_create(&amp;id2,nullptr,thread_run,(void*)&#034;thread_2&#034;);<br \/>\n    pthread_create(&amp;id3,nullptr,thread_run,(void*)&#034;thread_3&#034;);<br \/>\n    pthread_create(&amp;id4,nullptr,thread_run,(void*)&#034;thread_4&#034;);<br \/>\n    sleep(100);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;<\/p>\n<p>wuchun&#064;VM-0-10-ubuntu:~\/10_28$ .\/ceshi1<br \/>\nthread_1 get ticket: 100<br \/>\nthread_1 get ticket: 99<br \/>\nthread_1 get ticket: 98<br \/>\nthread_2 get ticket: 97<br \/>\nthread_2 get ticket: 96<br \/>\nthread_2 get ticket: 95<br \/>\nthread_2 get ticket: 94<br \/>\nthread_2 get ticket: 93<br \/>\nthread_2 get ticket: 92<br \/>\nthread_1 get ticket: 91<br \/>\nthread_1 get ticket: 90<br \/>\nthread_1 get ticket: 89<br \/>\nthread_2 get ticket: 88<br \/>\nthread_2 get ticket: 87<br \/>\nthread_2 get ticket: 86<br \/>\nthread_2 get ticket: 85<br \/>\nthread_2 get ticket: 84<br \/>\nthread_2 get ticket: 83<br \/>\nthread_1 get ticket: 82<br \/>\nthread_1 get ticket: 81<br \/>\nthread_1 get ticket: 80<br \/>\nthread_1 get ticket: 79<br \/>\nthread_1 get ticket: 78<br \/>\nthread_1 get ticket: 77<br \/>\nthread_2 get ticket: 76<br \/>\nthread_2 get ticket: 75<br \/>\nthread_2 get ticket: 74<br \/>\nthread_2 get ticket: 73<br \/>\nthread_2 get ticket: 72<br \/>\nthread_2 get ticket: 71<br \/>\nthread_1 get ticket: 70<br \/>\nthread_1 get ticket: 69<br \/>\nthread_1 get ticket: 68<br \/>\nthread_2 get ticket: 67<br \/>\nthread_2 get ticket: 66<br \/>\nthread_2 get ticket: 65<br \/>\nthread_2 get ticket: 64<br \/>\nthread_2 get ticket: 63<br \/>\nthread_2 get ticket: 62<br \/>\nthread_2 get ticket: 61<br \/>\nthread_1 get ticket: 60<br \/>\nthread_1 get ticket: 59<br \/>\nthread_1 get ticket: 58<br \/>\nthread_2 get ticket: 57<br \/>\nthread_2 get ticket: 56<br \/>\nthread_2 get ticket: 55<br \/>\nthread_2 get ticket: 54<br \/>\nthread_2 get ticket: 53<br \/>\nthread_2 get ticket: 52<br \/>\nthread_1 get ticket: 51<br \/>\nthread_1 get ticket: 50<br \/>\nthread_1 get ticket: 49<br \/>\nthread_1 get ticket: 48<br \/>\nthread_1 get ticket: 47<br \/>\nthread_1 get ticket: 46<br \/>\nthread_2 get ticket: 45<br \/>\nthread_2 get ticket: 44<br \/>\nthread_2 get ticket: 43<br \/>\nthread_2 get ticket: 42<br \/>\nthread_2 get ticket: 41<br \/>\nthread_2 get ticket: 40<br \/>\nthread_2 get ticket: 39<br \/>\nthread_2 get ticket: 38<br \/>\nthread_2 get ticket: 37<br \/>\nthread_2 get ticket: 36<br \/>\nthread_2 get ticket: 35<br \/>\nthread_2 get ticket: 34<br \/>\nthread_1 get ticket: 33<br \/>\nthread_1 get ticket: 32<br \/>\nthread_1 get ticket: 31<br \/>\nthread_1 get ticket: 30<br \/>\nthread_1 get ticket: 29<br \/>\nthread_1 get ticket: 28<br \/>\nthread_2 get ticket: 27<br \/>\nthread_2 get ticket: 26<br \/>\nthread_2 get ticket: 25<br \/>\nthread_1 get ticket: 24<br \/>\nthread_1 get ticket: 23<br \/>\nthread_1 get ticket: 22<br \/>\nthread_1 get ticket: 21<br \/>\nthread_1 get ticket: 20<br \/>\nthread_1 get ticket: 19<br \/>\nthread_2 get ticket: 18<br \/>\nthread_2 get ticket: 17<br \/>\nthread_2 get ticket: 16<br \/>\nthread_2 get ticket: 15<br \/>\nthread_2 get ticket: 14<br \/>\nthread_2 get ticket: 13<br \/>\nthread_1 get ticket: 12<br \/>\nthread_1 get ticket: 11<br \/>\nthread_1 get ticket: 10<br \/>\nthread_1 get ticket: 9<br \/>\nthread_1 get ticket: 8<br \/>\nthread_1 get ticket: 7<br \/>\nthread_1 get ticket: 6<br \/>\nthread_1 get ticket: 5<br \/>\nthread_1 get ticket: 4<br \/>\nthread_1 get ticket: 3<br \/>\nthread_2 get ticket: 2<br \/>\nthread_2 get ticket: 1<\/p>\n<p>\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u6b64\u65f6\u6211\u4eec\u5c31\u4e0d\u4f1a\u51fa\u73b0ticket&lt;&#061;0\u7684\u60c5\u51b5\u4e86&#xff0c;\u4f46\u540c\u65f6&#xff0c;\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u6211\u4eec\u7684\u8fdb\u7a0b\u6267\u884c\u7684\u901f\u5ea6\u6162\u4e86\u4e00\u4e9b&#xff0c;\u8fd9\u4e2a\u65f6\u5019&#xff0c;\u6211\u4eec\u5c31\u8981\u6765\u8bf4\u8bf4\u9501\u7684\u7279\u6027\u4e86<\/p>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"537\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235659-6ae52ecb32ebb.png\" width=\"1498\" \/><\/p>\n<p>\u4e2d\u95f4\u7684\u7eff\u8272\u533a\u57df&#xff0c;\u5c31\u662f\u6211\u4eec\u7684\u4e34\u754c\u533a&#xff0c;\u53ea\u6709\u62a2\u5230\u9501\u7684\u4eba&#xff0c;\u624d\u80fd\u8fdb\u5165&#xff1b;\u5982\u679c\u6211\u6ca1\u6709\u62a2\u5230\u9501&#xff0c;\u90a3\u6211\u5c31\u8fd4\u56de&#xff0c;\u6216\u8005\u5728\u62a2\u9501\u7684\u5730\u65b9\u963b\u585e\u4f4f&#xff0c;\u7b49\u62a2\u5230\u9501\u7684\u4eba\u91ca\u653e\u4e86\u9501&#xff0c;\u6211\u624d\u80fd\u7ee7\u7eed\u53bb\u62a2\u9501&#xff0c;\u76f4\u5230\u62a2\u5230\u9501&#xff0c;\u624d\u80fd\u8bbf\u95ee\u4e34\u754c\u533a&#xff0c;\u6240\u4ee5\u8fd9\u4e2a\u8fc7\u7a0b&#xff0c;\u5c31\u662f\u4ece\u5e76\u884c&#xff0c;\u53d8\u6210\u4e32\u884c\u7684\u8fc7\u7a0b&#xff0c;\u6240\u4ee5\u5440&#xff0c;\u6211\u4eec\u9501\u8981\u4fdd\u62a4\u7684\u533a\u57df\u8981\u5c3d\u53ef\u80fd\u7684\u5c0f&#xff0c;\u4e0d\u7136\u4f1a\u5bf9\u6211\u4eec\u7684\u6548\u7387\u9020\u6210\u8f83\u5927\u7684\u5f71\u54cd<\/p>\n<h4>\u9501\u7684\u539f\u7406&#xff1a;<\/h4>\n<p>lock:<br \/>\n    movb $0, %al<br \/>\n    xchgb %al, mutex<br \/>\n    if(al\u5bc4\u5b58\u5668\u7684\u5185\u5bb9 &gt; 0){<br \/>\n        return 0;<br \/>\n    } else<br \/>\n        \u6302\u8d77\u7b49\u5f85;<br \/>\n    goto lock;<\/p>\n<p>unlock:<br \/>\n    movb $1, mutex<br \/>\n    \u5524\u9192\u7b49\u5f85Mutex\u7684\u7ebf\u7a0b;<br \/>\n    return 0;<\/p>\n<p>\u597d&#xff0c;\u6211\u4eec\u73b0\u5728\u6765\u770b\u770b\u4e0a\u9762\u7684\u6c47\u7f16\u4ee3\u7801\u4ec0\u4e48\u610f\u601d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"513\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235659-6ae52ecb748bb.png\" width=\"737\" \/><\/p>\n<p>\u9996\u5148\u5462&#xff0c;\u6211\u4eec\u7684\u7ebf\u7a0b\u5728\u88ab\u8c03\u5ea6\u7684\u65f6\u5019&#xff0c;\u5bc4\u5b58\u5668\u4e2d\u4fdd\u5b58\u7684\u5c31\u662f\u6211\u4eec\u7684\u7684\u7ebf\u7a0b\u4e0a\u4e0b\u6587\u6570\u636e&#xff0c;\u800c\u5185\u5b58\u4e2d\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2amutex\u7684\u53d8\u91cf&#xff0c;\u5176\u503c\u4e3a1&#xff0c;\u5728\u6211\u4e0a\u9501\u7684\u65f6\u5019&#xff0c;\u6211\u628a\u6211\u7684al\u5bc4\u5b58\u5668\u5148\u7f6e\u4e3a0&#xff0c;\u7136\u540e\u6211\u4eec\u4ea4\u6362al\u5bc4\u5b58\u5668\u4e0emutex\u7684\u503c&#xff0c;\u4ece\u800cmutex\u4e3a0&#xff0c;al\u5bc4\u5b58\u5668\u4e2d\u7684\u503c\u4e3a1&#xff0c;\u63a5\u4e0b\u6765&#xff0c;\u53ea\u6709\u6211al\u5bc4\u5b58\u5668\u4e2d\u7684\u6570\u5927\u4e8e0\u65f6&#xff0c;\u6211\u624d\u53ef\u4ee5\u8fd0\u884c\u6211\u4e0b\u9762\u7684\u4ee3\u7801&#xff0c;\u5426\u5219\u6211\u5c31\u6302\u8d77\u7b49\u5f85&#xff0c;\u7136\u540e\u6211\u53c8\u91cd\u590d\u6b64\u903b\u8f91&#xff0c;\u7ee7\u7eed\u5c1d\u8bd5\u62a2\u593a\u9501&#xff1b;<\/p>\n<p>\u4f46\u662f\u6211\u60f3\u60f3&#xff0c;\u5982\u679c\u518d\u53d1\u751f\u6211\u5728\u8fd0\u884c\u7684\u65f6\u5019&#xff0c;CPU\u628a\u6211\u5207\u8d70&#xff0c;\u8c03\u5ea6\u522b\u7684\u7ebf\u7a0b\u600e\u4e48\u529e&#xff1f;<\/p>\n<p>\u5b8c\u5168\u6ca1\u5173\u7cfb&#xff01;<\/p>\n<p>\u56e0\u4e3a\u6b64\u65f6mutex&#xff1b;\u91cc\u9762\u7684\u503c\u4ecd\u7136\u4e3a0&#xff0c;\u5b83\u76841\u4f5c\u4e3a\u6211\u7684\u88ab\u5207\u8d70\u7ebf\u7a0b\u7684\u4e0a\u4e0b\u6587\u6570\u636e\u88ab\u5e26\u8d70\u4e86&#xff0c;\u6240\u4ee5\u5c31\u7b97\u8c03\u5ea6\u522b\u7684\u7ebf\u7a0b&#xff0c;\u4ed6\u4e5f\u65e0\u6cd5\u6267\u884c\u9501\u5185\u4ee3\u7801&#xff0c;\u76f4\u5230\u6211\u88abCPU\u5207\u56de\u6765&#xff0c;\u8fd0\u884c\u5b8c\u6211\u7684\u4ee3\u7801\u4e4b\u540e&#xff0c;\u7136\u540e\u91ca\u653e\u9501<\/p>\n<p>\u6240\u4ee5&#xff0c;\u62a2\u9501\u7684\u8fc7\u7a0b&#xff0c;\u5c31\u662f\u6211\u628a\u516c\u5171\u8d44\u6e90\u5360\u4e3a\u5df1\u6709\u7684\u8fc7\u7a0b<\/p>\n<p>\u800c\u91ca\u653e\u9501\u5f88\u7b80\u5355&#xff0c;\u5c31\u662f\u628amutex\u518d\u7f6e\u4e3a1&#xff0c;\u5c31\u76f8\u5f53\u4e8e\u516c\u5171\u8d44\u6e90\u7684\u5f52\u8fd8<\/p>\n<p>\u90a3\u4e48\u6211\u539f\u672c\u5bc4\u5b58\u5668\u4e2d\u4e0d\u8fd8\u662f1\u4e48&#xff0c;\u6ca1\u5173\u7cfb&#xff0c;\u4e0a\u9501\u65f6\u4f1a\u628a\u4ed6\u7f6e\u4e3a0<\/p>\n<h3>\u7ebf\u7a0b\u540c\u6b65&#xff1a;<\/h3>\n<p>\u6211\u5148\u6765\u7ed9\u5927\u5bb6\u4e3e\u4e00\u4e2a\u4f8b\u5b50\u5427&#xff1f;<\/p>\n<p>\u4eca\u5929\u6211\u4eec\u5b66\u6821\u6709\u4e00\u4e2assssssvip\u7f51\u5427\u5305\u95f4&#xff0c;\u6bcf\u6b21\u53ea\u6709\u4e00\u4e2a\u4eba\u53ef\u4ee5\u8fdb\u53bb&#xff0c;\u800c\u6211\u5462&#xff0c;\u6211\u8d77\u5f97\u65e9&#xff0c;\u6240\u4ee5\u6211\u516d\u70b9\u8d77\u6765&#xff0c;\u65e9\u65e9\u5730\u5c31\u53bb\u4e86\u81ea\u4e60\u5ba4&#xff0c;\u6211\u628a\u5899\u4e0a\u6302\u7740\u7684\u94a5\u5319\u53d6\u8d70&#xff0c;\u7136\u540e\u5f00\u59cb\u770b\u4e66&#xff0c;\u800d\u624b\u673a&#xff1f;\u7136\u540e\u6b64\u65f6\u5c4b\u5916\u6162\u6162\u7684\u5806\u4e86\u4e00\u7fa4\u4eba&#xff0c;\u4f46\u53ef\u60dc&#xff0c;\u6211\u8fd9\u4e2a\u81ea\u4e60\u5ba4&#xff0c;\u5b83\u4e00\u6b21\u6027\u53ea\u80fd\u6709\u4e00\u4e2a\u4eba\u53ef\u4ee5\u8fdb\u6765&#xff08;\u4e92\u65a5&#xff09;&#xff0c;\u6240\u4ee5&#xff0c;\u4ed6\u4eec\u867d\u7136\u65b0\u751f\u7231\u6155&#xff0c;\u4f46\u5bf9\u6211\u4e5f\u4e0d\u80fd\u600e\u4e48\u6837&#xff0c;\u6bd5\u7adf\u6211\u9075\u5b88\u4e86\u89c4\u5219&#8230;&#8230;.\u7136\u540e\u8fc7\u4e86\u4e00\u4f1a&#xff0c;\u6211\u60f3\u4e0a\u5395\u6240&#xff0c;\u6211\u5c31\u62ff\u8d77\u81ea\u4e60\u5ba4\u7684\u94a5\u5319&#xff0c;\u7136\u540e\u6302\u56de\u5230\u539f\u6765\u7684\u5730\u65b9&#xff0c;\u8fd9\u65f6\u5019&#xff0c;\u522b\u4eba\u5c31\u53ef\u4ee5\u7ade\u4e89\u8fd9\u628a\u9501&#xff0c;\u8fdb\u53bb\u81ea\u4e60\u5ba4\u81ea\u4e60\u4e86&#8230;&#8230;\u4f46\u662f&#xff01;\u6211\u6bd4\u8f83\u8d2a\u5fc3&#xff0c;\u6211\u60f3\u7740\u6211\u4e00\u65e6\u628a\u8fd9\u4e2a\u9501\u91ca\u653e\u6389&#xff0c;\u522b\u4eba\u4f1a\u4e0d\u4f1a\u8fdb\u53bb&#xff1f;\u6240\u4ee5\u6211\u91ca\u653e\u5b8c\u9501\u540e&#xff0c;\u6211\u8d76\u7d27\u53c8\u53bb\u7533\u8bf7\u9501&#xff0c;\u6211\u521a\u51fa\u6765&#xff0c;\u8c01\u6709\u6211\u79bb\u9501\u66f4\u8fd1\u5462&#xff1f;\u6240\u4ee5\u663e\u7136&#xff0c;\u6211\u53c8\u4f1a\u62a2\u593a\u5230\u9501&#xff1b;\u6211\u5faa\u73af\u5f80\u590d&#xff0c;\u6211\u62a2\u4e86\u4e00\u767e\u6b21\u9501&#xff0c;\u5728\u8fd9\u671f\u95f4&#xff0c;\u6211\u4ec0\u4e48\u90fd\u6ca1\u5e72&#xff0c;\u522b\u4eba\u4e5f\u8fdb\u4e0d\u53bb\u81ea\u4e60\u5ba4&#8230;&#8230;\u4f46\u4ed6\u4eec\u80fd\u62ff\u6211\u600e\u4e48\u6837\u5462&#xff0c;\u6211\u5e76\u6ca1\u6709\u574f\u89c4\u77e9&#xff0c;\u89c4\u77e9\u53ea\u89c4\u5b9a\u4e86&#xff0c;\u4e00\u6b21\u53ea\u6709\u4e00\u4e2a\u4eba\u53ef\u4ee5\u8fdb\u53bb&#xff0c;\u53c8\u6ca1\u8bf4\u6211\u4e0d\u53ef\u4ee5\u91cd\u590d\u7ade\u4e89\u3002\u6240\u4ee5\u554a&#xff0c;\u4e92\u65a5\u5b83\u7684\u786e\u662f\u53ef\u4ee5\u7684&#xff0c;\u4f46\u662f\u5b83\u4e0d\u4e00\u5b9a\u6b63\u786e&#xff1b;\u8fd9\u65f6\u5019&#xff0c;\u6211\u4eec\u5c31\u8981\u5f15\u5165\u540c\u6b65\u4e86<\/p>\n<p>\u540c\u6b65\u7684\u6982\u5ff5\u662f\u4ec0\u4e48\u6765\u7740&#xff1f;<\/p>\n<p><span style=\"color:#646a73\">\u540c\u6b65&#xff1a;\u5728\u4fdd\u8bc1\u6570\u636e\u5b89\u5168\u7684\u524d\u63d0\u4e0b&#xff0c;\u8ba9\u7ebf\u7a0b\u80fd\u591f\u6309\u7167\u67d0\u79cd\u7279\u5b9a\u7684\u987a\u5e8f\u8bbf\u95ee\u4e34\u754c\u8d44\u6e90&#xff0c;\u4ece\u2f7d\u6709\u6548\u907f\u514d <\/span><\/p>\n<p><span style=\"color:#646a73\">\u9965\u997f\u95ee\u9898&#xff0c;\u53eb\u505a\u540c\u6b65<\/span><\/p>\n<h4>\u6761\u4ef6\u53d8\u91cf pthread_cond_t<\/h4>\n<p>\/\/ \u6761\u4ef6\u53d8\u91cf\u7c7b\u578b<br \/>\npthread_cond_t cond;<\/p>\n<p>pthread_cond_init<\/p>\n<p>int pthread_cond_init(pthread_cond_t *restrict cond,<br \/>\n    const pthread_condattr_t *restrict attr);<\/p>\n<p>\u521d\u59cb\u5316\u6761\u4ef6\u53d8\u91cf&#xff1b;attr \u4f20 NULL \u4e3a\u9ed8\u8ba4\u5c5e\u6027\u3002 \u9759\u6001\u7b80\u5199&#xff1a;pthread_cond_t cond &#061; PTHREAD_COND_INITIALIZER;<\/p>\n<p>pthread_cond_wait\u3010\u91cd\u70b9\u3011<\/p>\n<p>int pthread_cond_wait(pthread_cond_t *restrict cond,<br \/>\n    pthread_mutex_t *restrict mutex);<\/p>\n<ul>\n<li>\u5fc5\u987b\u5e26\u7740\u4e92\u65a5\u9501\u8fdb\u53bb\u8c03\u7528<\/li>\n<li>\u52a8\u4f5c&#xff1a;\u5148\u89e3\u9501 mutex&#xff0c;\u7136\u540e\u963b\u585e\u7b49\u5f85\u4fe1\u53f7&#xff1b;\u88ab\u5524\u9192\u540e&#xff0c;\u81ea\u52a8\u91cd\u65b0\u52a0\u9501<\/li>\n<li>\u5751&#xff1a;\u5b58\u5728\u865a\u5047\u5524\u9192&#xff0c;\u9192\u6765\u4e00\u5b9a\u8981\u91cd\u65b0\u5224\u65ad\u6761\u4ef6&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u8ba4\u4e3a\u6761\u4ef6\u6ee1\u8db3<\/li>\n<\/ul>\n<p>\u6240\u4ee5\u554a&#xff0c;\u6211\u4eec\u5728\u8fd9\u91cc\u4e00\u822c\u5728\u5916\u9762\u5957\u4e00\u4e2awhile&#xff08;&#xff09;<\/p>\n<p>\u4ece\u800c\u5b9e\u73b0\u91cd\u65b0\u5224\u65ad\u7684\u76ee\u7684<\/p>\n<p>pthread_cond_signal<\/p>\n<p>int pthread_cond_signal(pthread_cond_t *cond);<\/p>\n<p>\u5524\u9192\u4e00\u4e2a\u6b63\u5728\u8be5 cond \u4e0a\u7b49\u5f85\u7684\u7ebf\u7a0b<\/p>\n<p>pthread_cond_broadcast<\/p>\n<p>int pthread_cond_broadcast(pthread_cond_t *cond);<\/p>\n<p>\u5524\u9192\u6240\u6709\u5728\u8be5 cond \u4e0a\u7b49\u5f85\u7684\u7ebf\u7a0b<\/p>\n<p>pthread_cond_destroy<\/p>\n<p>int pthread_cond_destroy(pthread_cond_t *cond);<\/p>\n<p>\u9500\u6bc1\u6761\u4ef6\u53d8\u91cf&#xff0c;\u91ca\u653e\u8d44\u6e90&#xff1b;\u9759\u6001\u521d\u59cb\u5316\u7684\u4e00\u822c\u53ef\u4e0d\u8c03\u7528<\/p>\n<h4>\u5c0f\u4f8b\u5b50&#xff1a;<\/h4>\n<p>pthread_mutex_lock(&amp;mutex);<br \/>\nwhile(\u6761\u4ef6\u4e0d\u6ee1\u8db3)   \/\/ while &#xff01;\u4e0d\u662fif&#xff0c;\u9632\u865a\u5047\u5524\u9192<br \/>\n{<br \/>\n    pthread_cond_wait(&amp;cond, &amp;mutex);<br \/>\n}<br \/>\n\/\/ \u6761\u4ef6\u6ee1\u8db3&#xff0c;\u6267\u884c\u4e34\u754c\u533a<br \/>\npthread_mutex_unlock(&amp;mutex);<\/p>\n<p>pthread_mutex_lock(&amp;mutex);<br \/>\n\/\/ \u4fee\u6539\u5171\u4eab\u6570\u636e&#xff0c;\u8ba9\u6761\u4ef6\u53d8\u4e3a\u6210\u7acb<br \/>\npthread_cond_signal(&amp;cond);<br \/>\npthread_mutex_unlock(&amp;mutex);<\/p>\n<p>\u4e3a\u4ec0\u4e48\u6211\u7b49\u5f85\u6761\u4ef6\u53d8\u91cf\u8981\u5728\u9501\u91cc&#xff1f;\u4e3a\u4ec0\u4e48\u8981\u4f20\u5165\u4e00\u628a\u9501&#xff1f;<\/p>\n<p>\u76f8\u4fe1\u5927\u5bb6\u4f1a\u6709\u8fd9\u6837\u7684\u7591\u95ee&#xff1a;<\/p>\n<p>\u90a3\u4e48\u8fd9\u91cc\u7ed9\u51fa\u7684\u89e3\u91ca\u662f&#xff1a;<\/p>\n<p>\u2460&#xff1a;\u9632\u6b62\u4fe1\u53f7\u4e22\u5931<\/p>\n<p>\u5982\u679c\u6211\u521a\u5224\u65ad\u6761\u4ef6\u4e0d\u6ee1\u8db3&#xff0c;\u8fdb\u5165\u5faa\u73af\u4e4b\u4e2d&#xff0c;\u6b63\u8981\u6267\u884cpthread_cond_wait\u7684\u65f6\u5019&#xff0c;\u6211\u88ab\u5207\u8d70\u4e86&#xff0c;\u6b64\u65f6\u6211\u5207\u5230\u4e86\u53e6\u4e00\u4e2a\u8fdb\u7a0b&#xff0c;\u53e6\u4e00\u4e2a\u8fdb\u7a0b\u4fee\u6539\u6761\u4ef6&#xff0c;\u6267\u884cpthread _cond_signal\u5524\u9192\u539f\u7ebf\u7a0b&#xff0c;\u4f46\u662f\u6211\u539f\u7ebf\u7a0b\u8fd8\u6ca1wait\u5462&#xff0c;\u6240\u4ee5\u6b64\u65f6\u6211\u7684\u8fd9\u4e2a\u4fe1\u53f7\u5c31\u76f4\u63a5\u4e22\u5931\u6389\u4e86&#xff0c;\u4f1a\u9677\u5165\u6c38\u4e45\u7684\u963b\u585e<\/p>\n<p>\u2461: pthread_cond_wait\u51fd\u6570\u9700\u8981\u7528\u5230\u9501<\/p>\n<p>\u6211\u4eec\u8fd9\u4e2a\u51fd\u6570\u5185\u90e8\u5206\u4e3a\u51e0\u6b65&#xff1a;<\/p>\n<p>\u9996\u5148\u6211\u62ff\u5230\u8fd9\u4e2a\u9501&#xff0c;\u5c06\u5176\u91ca\u653e\u6389&#xff0c;\u8ba9\u522b\u7684\u7ebf\u7a0b\u53ef\u4ee5\u7ade\u4e89\u8fd9\u628a\u9501&#xff0c;\u4ece\u800c\u4fee\u6539\u6761\u4ef6&#xff0c;\u53d1signal<\/p>\n<p>\u7136\u540e\u963b\u585e\u4f11\u7720&#xff0c;\u7b49\u5f85\u5524\u9192<\/p>\n<p>\u6700\u540e\u6211\u88ab\u5524\u9192\u4e4b\u540e&#xff0c;\u6700\u540e\u91cd\u65b0\u83b7\u5f97\u8fd9\u628a\u9501&#xff0c;\u624d\u4f1a\u8fd4\u56de<\/p>\n<p>\u540c\u65f6&#xff1a;\u6211\u4eec\u8981\u77e5\u9053&#xff0c;\u6211\u4eec\u8c03\u7528pthread_cond_wait\u548c\u8c03\u7528pthread_cond_signal\u51fd\u6570\u7684\u7ebf\u7a0b&#xff0c;\u4ed6\u4eec\u6240\u8981\u8fdb\u884c\u4fee\u6539\u5224\u65ad\u7684\u6761\u4ef6&#xff0c;\u5fc5\u987b\u662f\u540c\u4e00\u4e2a\u9501\u6765\u4fdd\u62a4\u7684&#xff1b;<\/p>\n<p>\u6b63\u56e0\u4e3a\u662f\u540c\u4e00\u628a\u9501&#xff0c;\u6240\u4ee5\u624d\u6709pthread_cond_wait\u5185\u90e8\u8981\u91ca\u653e\u9501&#xff0c;\u4ea4\u7ed9\u522b\u7684\u7ebf\u7a0b\u6765\u8ba9\u4ed6\u4eec\u4fee\u6539\u5224\u65ad\u6761\u4ef6&#xff1b;<\/p>\n<h4>\u5927\u4f8b\u5b50&#xff1a;<\/h4>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\npthread_mutex_t mutex &#061; PTHREAD_MUTEX_INITIALIZER;<br \/>\npthread_cond_t con &#061; PTHREAD_COND_INITIALIZER;<br \/>\nint apple &#061; 0;<br \/>\n\/\/ \u751f\u4ea7\u8005\u653e\u82f9\u679c<br \/>\nvoid *putapple(void *arg)<br \/>\n{<br \/>\n    while(1)<br \/>\n    {<br \/>\n        pthread_mutex_lock(&amp;mutex);<br \/>\n        apple&#043;&#043;;<br \/>\n        printf(&#034;%s\u653e\u4e86\u4e00\u4e2a\u82f9\u679c\\\\n&#034;,(char*)arg);<br \/>\n        pthread_cond_signal(&amp;con);<br \/>\n        pthread_mutex_unlock(&amp;mutex);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<br \/>\n\/\/ \u6d88\u8d39\u8005\u7b49\u82f9\u679c<br \/>\nvoid *getapple(void *arg)<br \/>\n{<br \/>\n    while (1)<br \/>\n    {<br \/>\n        pthread_mutex_lock(&amp;mutex);<br \/>\n        while(apple&lt;&#061;0)<br \/>\n        {<br \/>\n            pthread_cond_wait(&amp;con,&amp;mutex);<br \/>\n        }<br \/>\n        apple&#8211;;<br \/>\n        printf(&#034;%s\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c\\\\n&#034;,(char*)arg);<br \/>\n        pthread_mutex_unlock(&amp;mutex);<br \/>\n    }<br \/>\n    return nullptr;<br \/>\n}<br \/>\nint main()<br \/>\n{<br \/>\n    pthread_t t1,t2;<br \/>\n    pthread_create(&amp;t1,nullptr,getapple,(void*)&#034;consumer&#034;);<br \/>\n    pthread_create(&amp;t2,nullptr,putapple,(void*)&#034;productor&#034;);<br \/>\n    sleep(100);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p>\u7ed3\u679c\u4e5f\u662f\u975e\u5e38\u7684\u548c\u8c10\u554a&#xff1a;<\/p>\n<p>productor\u653e\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nconsumer\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nproductor\u653e\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nconsumer\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nproductor\u653e\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nconsumer\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nproductor\u653e\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nconsumer\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nproductor\u653e\u4e86\u4e00\u4e2a\u82f9\u679c<br \/>\nconsumer\u62ff\u8d70\u4e86\u4e00\u4e2a\u82f9\u679c<\/p>\n<p>\u90a3\u4e48\u5230\u8fd9\u91cc&#xff0c;\u6211\u4eec\u7684\u7ebf\u7a0b\u540c\u6b65\u4e5f\u7ed3\u675f\u4e86&#xff1b;\u63a5\u4e0b\u6765\u5c31\u662f\u4e00\u4e9b\u96f6\u96f6\u6563\u6563\u7684\u5c0f\u95ee\u9898\u4e86&#xff1b;<\/p>\n<\/p>\n<h3>\u7ebf\u7a0b\u5b89\u5168<\/h3>\n<h4>\u6982\u5ff5&#xff1a;<\/h4>\n<p><span style=\"color:#1f2329\">\u7ebf\u7a0b\u5b89\u5168&#xff1a;\u5c31\u662f\u591a\u4e2a\u7ebf\u7a0b\u5728\u8bbf\u95ee\u5171\u4eab\u8d44\u6e90\u65f6&#xff0c;\u80fd\u591f\u6b63\u786e\u5730\u6267\u2f8f&#xff0c;\u4e0d\u4f1a\u76f8\u4e92\u2f32\u6270\u6216\u7834\u574f\u5f7c\u6b64\u7684\u6267\u2f8f\u7ed3 <\/span><\/p>\n<p><span style=\"color:#1f2329\">\u679c\u3002\u2f00\u822c\u2f7d\u2f94&#xff0c;\u591a\u4e2a\u7ebf\u7a0b\u5e76\u53d1\u540c\u2f00\u6bb5\u53ea\u6709\u5c40\u90e8\u53d8\u91cf\u7684\u4ee3\u7801\u65f6&#xff0c;\u4e0d\u4f1a\u51fa\u73b0\u4e0d\u540c\u7684\u7ed3\u679c\u3002\u4f46\u662f\u5bf9\u5168\u5c40\u53d8\u91cf\u6216\u8005\u9759\u6001\u53d8\u91cf\u8fdb\u2f8f\u64cd\u4f5c&#xff0c;\u5e76\u4e14\u6ca1\u6709\u9501\u4fdd\u62a4\u7684\u60c5\u51b5\u4e0b&#xff0c;\u5bb9\u6613\u51fa\u73b0\u8be5\u95ee\u9898\u3002 <\/span><\/p>\n<p><span style=\"color:#1f2329\">\u91cd\u2f0a&#xff1a;\u540c\u2f00\u4e2a\u51fd\u6570\u88ab\u4e0d\u540c\u7684\u6267\u2f8f\u6d41\u8c03\u2f64&#xff0c;\u5f53\u524d\u2f00\u4e2a\u6d41\u7a0b\u8fd8\u6ca1\u6709\u6267\u2f8f\u5b8c&#xff0c;\u5c31\u6709\u5176\u4ed6\u7684\u6267\u2f8f\u6d41\u518d\u6b21\u8fdb\u2f0a&#xff0c;\u6211\u4eec\u79f0\u4e4b\u4e3a\u91cd\u2f0a\u3002\u2f00\u4e2a\u51fd\u6570\u5728\u91cd\u2f0a\u7684\u60c5\u51b5\u4e0b&#xff0c;\u8fd0\u2f8f\u7ed3\u679c\u4e0d\u4f1a\u51fa\u73b0\u4efb\u4f55\u4e0d\u540c\u6216\u8005\u4efb\u4f55\u95ee\u9898&#xff0c;\u5219\u8be5\u51fd\u6570\u88ab\u79f0\u4e3a\u53ef\u91cd\u2f0a\u51fd\u6570&#xff0c;\u5426\u5219&#xff0c;\u662f\u4e0d\u53ef\u91cd\u2f0a\u51fd\u6570\u3002<\/span><\/p>\n<p>\u90a3\u4e48\u4e8c\u8005\u7684\u5173\u7cfb\u662f&#xff1a;<\/p>\n<p>\u51fd\u6570\u5982\u679c\u662f\u53ef\u91cd\u5165\u7684&#xff0c;\u90a3\u5c31\u662f\u7ebf\u7a0b\u5b89\u5168\u7684<\/p>\n<p><span style=\"color:#0d0016\">\u7ebf\u7a0b\u5b89\u5168\u4e0d\u2f00\u5b9a\u662f\u53ef\u91cd\u2f0a\u7684&#xff0c;\u2f7d\u53ef\u91cd\u2f0a\u51fd\u6570\u5219\u2f00\u5b9a\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u3002<\/span><\/p>\n<h3>\u6b7b\u9501&#xff1a;<\/h3>\n<h4>\u56db\u4e2a\u5fc5\u8981\u6761\u4ef6&#xff0c;\u7f3a\u4e00\u4e0d\u53ef<\/h4>\n<li>\u4e92\u65a5\u6761\u4ef6 \u8d44\u6e90\u662f\u72ec\u5360\u7684&#xff0c;\u4e00\u4e2a\u8d44\u6e90\u540c\u4e00\u65f6\u95f4\u53ea\u80fd\u88ab\u4e00\u4e2a\u7ebf\u7a0b\u6301\u6709\u3002\u6bd4\u5982\u4e92\u65a5\u9501&#xff0c;\u62ff\u5230\u7684\u4eba\u624d\u80fd\u8bbf\u95ee\u3002<\/li>\n<li>\u8bf7\u6c42\u4e0e\u4fdd\u6301&#xff08;\u5360\u6709\u4e14\u7b49\u5f85&#xff09; \u7ebf\u7a0b\u5df2\u7ecf\u62ff\u7740\u4e00\u90e8\u5206\u8d44\u6e90&#xff0c;\u540c\u65f6\u53c8\u53bb\u7533\u8bf7\u522b\u7684\u65b0\u8d44\u6e90&#xff0c;\u4e0d\u91ca\u653e\u624b\u91cc\u5df2\u7ecf\u62ff\u5230\u7684\u3002<\/li>\n<li>\u4e0d\u53ef\u5265\u593a \u522b\u4eba\u4e0d\u80fd\u5f3a\u884c\u62a2\u8d70\u7ebf\u7a0b\u5df2\u7ecf\u5360\u6709\u7684\u8d44\u6e90&#xff1b;\u53ea\u80fd\u7ebf\u7a0b\u81ea\u5df1\u4e3b\u52a8 unlock \u91ca\u653e\u9501\u3002<\/li>\n<li>\u5faa\u73af\u7b49\u5f85 \u7ebf\u7a0b\u4e4b\u95f4\u5f62\u6210\u8d44\u6e90\u7b49\u5f85\u73af\u8def&#xff1a;T1 \u7b49 T2 \u7684\u8d44\u6e90&#xff0c;T2 \u7b49 T1 \u7684\u8d44\u6e90&#xff0c;\u73af\u95ed\u5408\u3002<\/li>\n<p>\u6240\u4ee5&#xff0c;\u56db\u4e2a\u6761\u4ef6\u5206\u522b\u662f&#xff1a;\u4e92\u65a5\u3001\u5360\u6709\u7b49\u5f85\u3001\u4e0d\u53ef\u5265\u593a\u3001\u5faa\u73af\u7b49\u5f85<\/p>\n<p>\u90a3\u4e48\u663e\u7136&#xff0c;\u53ea\u8981\u7834\u574f\u8fd9\u56db\u4e2a\u6761\u4ef6\u4e0d\u5c31\u7834\u574f\u4e86\u6b7b\u9501\u4e86&#xff1f;\u968f\u4fbf\u7834\u574f\u4e00\u4e2a\u6b7b\u9501\u5c31\u4e0d\u6210\u7acb\u4e86<\/p>\n<h4>\u5982\u4f55\u7834\u574f&#xff1a;<\/h4>\n<\/p>\n<li><span style=\"color:#0d0016\">\u7834\u574f\u4e92\u65a5&#xff1a;\u5c3d\u91cf\u4f7f\u7528\u5171\u4eab\u8d44\u6e90&#xff1b;\u6bd4\u5982\u8bfb\u5199\u9501\u8bfb\u6a21\u5f0f\u53ef\u4ee5\u5171\u4eab\u3002\u5f88\u591a\u9501\u573a\u666f\u8fd9\u4e2a\u5f88\u96be\u7834\u574f&#xff0c;\u4e00\u822c\u4e0d\u4f18\u5148\u9009\u3002<\/span><\/li>\n<li><span style=\"color:#0d0016\">\u7834\u574f\u8bf7\u6c42\u4e0e\u4fdd\u6301&#xff1a;\u4e00\u6b21\u6027\u7533\u8bf7\u6240\u6709\u9700\u8981\u7684\u8d44\u6e90\u3002\u8981\u62ff\u9501 A &#043; \u9501 B&#xff0c;\u5c31\u4e00\u6b21\u6027\u7533\u8bf7\u5230\u4e24\u4e2a\u624d\u5f80\u4e0b\u8dd1&#xff0c;\u4e0d\u62ff\u5230 A \u4e4b\u540e\u518d\u53bb\u7533\u8bf7 B\u3002<\/span><\/li>\n<li><span style=\"color:#0d0016\">\u7834\u574f\u4e0d\u53ef\u5265\u593a&#xff1a;\u652f\u6301\u62a2\u5360\u3002\u6bd4\u5982 pthread_mutex_trylock&#xff0c;\u62ff\u4e0d\u5230\u76f4\u63a5\u8fd4\u56de&#xff0c;\u4e3b\u52a8\u91ca\u653e\u81ea\u5df1\u5df2\u7ecf\u6301\u6709\u7684\u9501&#xff0c;\u4e0d\u5361\u6b7b\u7b49\u5f85\u3002<\/span><\/li>\n<li><span style=\"color:#0d0016\">\u7834\u574f\u5faa\u73af\u7b49\u5f85&#xff1a;\u7edf\u4e00\u9501\u7684\u83b7\u53d6\u987a\u5e8f&#xff0c;\u6240\u6709\u7ebf\u7a0b\u6c38\u8fdc\u6309\u7167\u56fa\u5b9a\u987a\u5e8f\u7533\u8bf7\u9501&#xff08;\u5148 A \u540e B&#xff09;&#xff0c;\u73af\u8def\u5f62\u6210\u4e0d\u4e86\u3002<\/span><\/li>\n<h2>\u5c3e&#xff1a;<\/h2>\n<p>\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8\u54c8&#xff0c;\u5176\u5b9e\u73b0\u5728\u5df2\u7ecf\u795e\u5fd7\u4e0d\u6e05\u4e86&#xff0c;\u8fd9\u7bc7\u5e94\u8be5\u662f\u5199\u4e86\u516d\u4e2a\u5c0f\u65f6\u591a\u4e00\u70b9&#xff0c;\u672c\u6765\u8981\u5206\u4e3a\u4e24\u7bc7\u5199\u6765\u7740&#xff0c;\u540e\u6765\u56e0\u4e3a\u592a\u61d2\u5fd8\u8bb0\u4e86&#xff0c;\u6240\u4ee5\u4eca\u5929\u53ea\u80fd\u4e00\u7bc7\u5168\u5199\u4e0a\u4e86&#xff0c;\u660e\u5929\u5e94\u8be5\u4f1a\u624b\u6413\u7ebf\u7a0b\u6c60\u4e86&#xff0c;\u4f1a\u628a\u8fc7\u7a0b\u4e5f\u53d1\u51fa\u6765&#xff0c;\u4f5c\u4e3a\u8fd9\u4e00\u5757\u7684\u5927\u603b\u7ed3\u7684&#xff1b;\u6700\u8fd1\u5929\u6c14\u8f6c\u51c9&#xff0c;\u5927\u5bb6\u591a\u7a7f\u8863\u670d\u5440~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00&#xff1a;\u9996\u5148\u5462&#xff0c;\u7ebf\u7a0b\u5c06\u4f1a\u662f\u6211\u4eeclinux\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u7ae0\u8282&#xff0c;\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u540e&#xff0c;\u6211\u4eec\u8fd8\u8981\u5199\u4e00\u4e2a\u7ebf\u7a0b\u6c60&#xff0c;\u90a3\u4e48\u6211\u4eec\u7684linux\u7cfb\u7edf\u5c31\u7ed3\u675f\u4e86&#xff1b;\u5728\u90a3\u4e4b\u540e&#xff0c;\u4f1a\u5f00\u59cb\u5199\u8ba1\u7b97\u673a\u7f51\u7edc\u76f8\u5173\u7684\u5185\u5bb9&#xff0c;\u5f53\u7136&#xff0c;\u4e5f\u4f1a\u5199\u4e00\u4e9bc,\u6216\u8005leetcode\u5237\u9898\u7684\u6587\u7ae0&#xff0c;\u4ee5\u524d\u503e\u5411\u4e8e\u505a\u7b14\u8bb0&#xff0c;\u73b0\u5728\u5f00\u59cb\u7528\u535a\u5ba2\u8bb0\u5f55&#xff0c;\u611f\u89c9\u6548\u679c\u4e5f\u4e0d\u9519&#xff08;\u5176\u5b9e\u662f\u5199\u5b57\u592a\u4e11\u81ea\u5df1\u4e5f<\/p>\n","protected":false},"author":2,"featured_media":120210,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,43,44],"topic":[],"class_list":["post-120218","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>linux(12) \u7ebf\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\/120218.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"linux(12) \u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00&#xff1a;\u9996\u5148\u5462&#xff0c;\u7ebf\u7a0b\u5c06\u4f1a\u662f\u6211\u4eeclinux\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u7ae0\u8282&#xff0c;\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u540e&#xff0c;\u6211\u4eec\u8fd8\u8981\u5199\u4e00\u4e2a\u7ebf\u7a0b\u6c60&#xff0c;\u90a3\u4e48\u6211\u4eec\u7684linux\u7cfb\u7edf\u5c31\u7ed3\u675f\u4e86&#xff1b;\u5728\u90a3\u4e4b\u540e&#xff0c;\u4f1a\u5f00\u59cb\u5199\u8ba1\u7b97\u673a\u7f51\u7edc\u76f8\u5173\u7684\u5185\u5bb9&#xff0c;\u5f53\u7136&#xff0c;\u4e5f\u4f1a\u5199\u4e00\u4e9bc,\u6216\u8005leetcode\u5237\u9898\u7684\u6587\u7ae0&#xff0c;\u4ee5\u524d\u503e\u5411\u4e8e\u505a\u7b14\u8bb0&#xff0c;\u73b0\u5728\u5f00\u59cb\u7528\u535a\u5ba2\u8bb0\u5f55&#xff0c;\u611f\u89c9\u6548\u679c\u4e5f\u4e0d\u9519&#xff08;\u5176\u5b9e\u662f\u5199\u5b57\u592a\u4e11\u81ea\u5df1\u4e5f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/120218.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-30T23:57:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235656-6ae52ec8a4df9.png\" \/>\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=\"17 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120218.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/120218.html\",\"name\":\"linux(12) \u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-30T23:57:00+00:00\",\"dateModified\":\"2026-10-30T23:57:00+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/120218.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/120218.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120218.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"linux(12) \u7ebf\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":"linux(12) \u7ebf\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\/120218.html","og_locale":"zh_CN","og_type":"article","og_title":"linux(12) \u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00&#xff1a;\u9996\u5148\u5462&#xff0c;\u7ebf\u7a0b\u5c06\u4f1a\u662f\u6211\u4eeclinux\u7cfb\u7edf\u4e2d\u7684\u6700\u540e\u4e00\u4e2a\u7ae0\u8282&#xff0c;\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e4b\u540e&#xff0c;\u6211\u4eec\u8fd8\u8981\u5199\u4e00\u4e2a\u7ebf\u7a0b\u6c60&#xff0c;\u90a3\u4e48\u6211\u4eec\u7684linux\u7cfb\u7edf\u5c31\u7ed3\u675f\u4e86&#xff1b;\u5728\u90a3\u4e4b\u540e&#xff0c;\u4f1a\u5f00\u59cb\u5199\u8ba1\u7b97\u673a\u7f51\u7edc\u76f8\u5173\u7684\u5185\u5bb9&#xff0c;\u5f53\u7136&#xff0c;\u4e5f\u4f1a\u5199\u4e00\u4e9bc,\u6216\u8005leetcode\u5237\u9898\u7684\u6587\u7ae0&#xff0c;\u4ee5\u524d\u503e\u5411\u4e8e\u505a\u7b14\u8bb0&#xff0c;\u73b0\u5728\u5f00\u59cb\u7528\u535a\u5ba2\u8bb0\u5f55&#xff0c;\u611f\u89c9\u6548\u679c\u4e5f\u4e0d\u9519&#xff08;\u5176\u5b9e\u662f\u5199\u5b57\u592a\u4e11\u81ea\u5df1\u4e5f","og_url":"https:\/\/www.wsisp.com\/helps\/120218.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-30T23:57:00+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261030235656-6ae52ec8a4df9.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"17 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/120218.html","url":"https:\/\/www.wsisp.com\/helps\/120218.html","name":"linux(12) \u7ebf\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-30T23:57:00+00:00","dateModified":"2026-10-30T23:57:00+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/120218.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/120218.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/120218.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"linux(12) \u7ebf\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\/120218","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=120218"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/120218\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/120210"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=120218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=120218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=120218"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=120218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}