{"id":118018,"date":"2026-10-26T03:48:18","date_gmt":"2026-10-25T19:48:18","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/118018.html"},"modified":"2026-10-26T03:48:18","modified_gmt":"2026-10-25T19:48:18","slug":"%e3%80%90linux-system%e3%80%91%e3%80%90system-v%e5%85%b1%e4%ba%ab%e5%86%85%e5%ad%98%ef%bc%9a%e4%bb%8e%e5%8e%9f%e7%90%86%e5%88%b0%e5%ae%9e%e6%88%98%e7%9a%84%e5%ae%8c%e6%95%b4%e8%a7%a3%e6%9e%90%e3%80%91","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/118018.html","title":{"rendered":"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582"},"content":{"rendered":"<h2>System V \u5171\u4eab\u5185\u5b58\u673a\u5236&#xff1a;\u4ece\u5185\u6838\u539f\u7406\u5230\u4ee3\u7801\u5b9e\u6218<\/h2>\n<p>\u8bfe\u7a0b\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u95f4\u901a\u4fe1&#xff08;IPC&#xff09;\u2014\u2014\u5171\u4eab\u5185\u5b58&#xff08;Shared Memory&#xff09;<br \/>\n\u6838\u5fc3\u76ee\u6807&#xff1a;\u7406\u89e3\u5171\u4eab\u5185\u5b58\u201c\u968f\u5185\u6838\u201d\u7684\u751f\u547d\u5468\u671f\u3001Key\/Shmid \u53cc\u6807\u8bc6\u4f53\u7cfb\u3001\u96f6\u62f7\u8d1d\u9ad8\u6027\u80fd\u80cc\u540e\u7684\u540c\u6b65\u4ee3\u4ef7&#xff0c;\u5e76\u624b\u5199\u4e00\u5957\u53ef\u8fd0\u884c\u7684 C\/S \u901a\u4fe1\u6846\u67b6\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6838\u5fc3\u539f\u7406&#xff1a;\u5171\u4eab\u5185\u5b58\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f;<\/h3>\n<h4>1.1 \u4e24\u5757\u62fc\u56fe&#xff1a;\u7269\u7406\u5185\u5b58 &#043; \u5185\u6838\u6570\u636e\u7ed3\u6784<\/h4>\n<p>\u5171\u4eab\u5185\u5b58\u5e76\u4e0d\u662f\u7b80\u7b80\u5355\u5355\u5730\u5728\u5185\u5b58\u4e2d\u201c\u62a0\u4e00\u5757\u5730\u201d\u51fa\u6765\u3002\u5982\u679c\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8\u540c\u65f6\u5b58\u5728\u591a\u7ec4\u8fdb\u7a0b\u901a\u4fe1&#xff0c;\u5185\u6838\u5fc5\u987b\u5148\u63cf\u8ff0&#xff0c;\u518d\u7ec4\u7ec7\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5171\u4eab\u5185\u5b58\u7531\u4e24\u90e8\u5206\u7ec4\u6210&#xff1a;<\/p>\n<ul>\n<li>\u7269\u7406\u5185\u5b58\u7a7a\u95f4&#xff1a;\u5b9e\u9645\u5b58\u653e\u6570\u636e\u7684\u9875\u6846&#xff1b;<\/li>\n<li>\u5185\u6838\u6570\u636e\u7ed3\u6784 shmid_ds&#xff1a;\u63cf\u8ff0\u8fd9\u5757\u5185\u5b58\u7684\u5c5e\u6027&#xff08;\u6743\u9650\u3001\u5927\u5c0f\u3001\u5173\u8054\u8fdb\u7a0b\u6570\u3001Key \u7b49&#xff09;\u3002<\/li>\n<\/ul>\n<h4>1.2 \u6620\u5c04\u673a\u5236&#xff1a;\u8ba9\u4e0d\u540c\u8fdb\u7a0b\u770b\u5230\u540c\u4e00\u4efd\u7269\u7406\u9875<\/h4>\n<p>\u64cd\u4f5c\u7cfb\u7edf\u5728\u7269\u7406\u5185\u5b58\u4e2d\u5f00\u8f9f\u7a7a\u95f4\u540e&#xff0c;\u901a\u8fc7\u9875\u8868\u6620\u5c04\u5c06\u5176\u6302\u63a5\u5230\u901a\u4fe1\u53cc\u65b9\u8fdb\u7a0b\u7684\u865a\u62df\u5730\u5740\u7a7a\u95f4&#xff08;\u901a\u5e38\u4f4d\u4e8e\u5806\u6808\u4e4b\u95f4\u7684\u5171\u4eab\u533a&#xff09;\u3002\u4e00\u65e6\u6620\u5c04\u5b8c\u6210&#xff1a;<\/p>\n<ul>\n<li>\u8fdb\u7a0b A \u901a\u8fc7\u81ea\u5df1\u7684\u865a\u62df\u5730\u5740\u8bfb\u5199&#xff1b;<\/li>\n<li>\u8fdb\u7a0b B \u901a\u8fc7\u81ea\u5df1\u7684\u865a\u62df\u5730\u5740\u8bfb\u5199&#xff1b;<\/li>\n<li>\u4e24\u8005\u6700\u7ec8\u8bbf\u95ee\u7684\u662f\u540c\u4e00\u5757\u7269\u7406\u5185\u5b58\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u548c\u4e4b\u524d\u5b66\u7684\u52a8\u6001\u5e93\u52a0\u8f7d\u539f\u7406\u5982\u51fa\u4e00\u8f99\u2014\u2014\u672c\u8d28\u4e0a\u90fd\u662f\u201c\u865a\u62df\u5730\u5740 \u2192 \u7269\u7406\u9875\u201d\u7684\u6620\u5c04\u3002\u540e\u7eed\u8bb2\u5230\u52a8\u6001\u5e93\u65f6&#xff0c;\u8fd8\u4f1a\u7528 mmap \u505a\u6587\u4ef6\u6620\u5c04&#xff0c;\u5176\u5e95\u5c42\u601d\u60f3\u4e0e\u5171\u4eab\u5185\u5b58\u5b8c\u5168\u4e00\u81f4\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u53cc\u6807\u8bc6\u4f53\u7cfb&#xff1a;Key vs Shmid<\/h3>\n<p>\u8fd9\u662f\u521d\u5b66\u5171\u4eab\u5185\u5b58\u65f6\u6700\u5bb9\u6613\u6df7\u6dc6\u7684\u6982\u5ff5&#xff0c;\u8bfe\u5802\u7528\u5927\u91cf\u7bc7\u5e45\u505a\u4e86\u8fa8\u6790\u3002<\/p>\n<h4>2.1 Key&#xff1a;\u5185\u6838\u5c42\u7684\u201c\u8eab\u4efd\u8bc1\u53f7\u201d<\/h4>\n<ul>\n<li>\u6765\u6e90&#xff1a;\u7528\u6237\u5c42\u901a\u8fc7 ftok(pathname, proj_id) \u751f\u6210&#xff1b;<\/li>\n<li>\u7528\u9014&#xff1a;\u5185\u6838\u7528\u5b83\u5728\u5168\u5c40 IPC \u8d44\u6e90\u4e2d\u8fa8\u522b\u552f\u4e00\u6027&#xff1b;<\/li>\n<li>\u7279\u70b9&#xff1a;A \u8fdb\u7a0b\u521b\u5efa\u65f6\u628a Key \u5199\u8fdb\u5185\u6838\u7ed3\u6784\u4f53&#xff0c;B \u8fdb\u7a0b\u62ff\u7740\u540c\u4e00\u4e2a Key \u6765\u201c\u5bf9\u6697\u53f7\u201d&#xff0c;\u624d\u80fd\u627e\u5230\u540c\u4e00\u5757\u5171\u4eab\u5185\u5b58\u3002<\/li>\n<\/ul>\n<p>\u2753 \u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7531\u64cd\u4f5c\u7cfb\u7edf\u751f\u6210 Key \u518d\u8fd4\u56de\u7ed9 A&#xff0c;\u7136\u540e A \u4f20\u7ed9 B&#xff1f;<br \/>\n\u7b54&#xff1a;\u8fd9\u5c31\u9677\u5165\u4e86\u201c\u9e21\u751f\u86cb\u3001\u86cb\u751f\u9e21\u201d\u7684\u6b7b\u9501\u2014\u2014A \u4e0e B \u8fd8\u6ca1\u5efa\u7acb\u901a\u4fe1\u4fe1\u9053&#xff0c;\u5982\u4f55\u628a Key \u4ea4\u7ed9\u5bf9\u65b9&#xff1f;\u56e0\u6b64\u5fc5\u987b\u7528\u6237\u5728\u5e94\u7528\u5c42\u7ea6\u5b9a Key\u3002<\/p>\n<h4>2.2 Shmid&#xff1a;\u7528\u6237\u5c42\u7684\u201c\u5de5\u724c\u53f7\u201d<\/h4>\n<ul>\n<li>\u6765\u6e90&#xff1a;shmget() \u6210\u529f\u65f6\u7cfb\u7edf\u8fd4\u56de\u7684\u6574\u6570&#xff1b;<\/li>\n<li>\u7528\u9014&#xff1a;\u7528\u6237\u5c42\u6240\u6709\u7ba1\u7406\u64cd\u4f5c&#xff08;\u6302\u63a5\u3001\u5220\u9664\u3001\u83b7\u53d6\u5c5e\u6027&#xff09;\u90fd\u4f7f\u7528 Shmid&#xff1b;<\/li>\n<li>\u6ce8\u610f&#xff1a;Shmid \u4e0e\u6587\u4ef6\u63cf\u8ff0\u7b26 fd \u4e0d\u662f\u4e00\u56de\u4e8b\u3002fd \u5173\u95ed\u540e\u4f1a\u56de\u6536\u590d\u7528&#xff08;0\u30011\u30012\u2026\u5faa\u73af\u4f7f\u7528&#xff09;&#xff0c;\u4f46 System V IPC \u7684 Shmid \u662f\u5355\u5411\u9012\u589e\u7684&#xff0c;\u8fd9\u4fa7\u9762\u8bf4\u660e\u5b83\u4e0e\u6587\u4ef6\u7cfb\u7edf\u5e76\u975e\u5f3a\u76f8\u5173&#xff0c;\u53ea\u662f\u201c\u626d\u626d\u634f\u634f\u201d\u5730\u501f\u7528\u4e86\u6587\u4ef6\u6743\u9650\u7684\u601d\u60f3\u3002<\/li>\n<\/ul>\n<h4>2.3 \u4e00\u4e2a\u8bfe\u5802\u5b9e\u9a8c&#xff1a;\u5220\u9664\u65f6\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7528 Key&#xff1f;<\/h4>\n<p>\u8001\u5e08\u5728\u7ec8\u7aef\u8fde\u7eed\u505a\u4e86\u4e09\u6b21\u64cd\u4f5c&#xff1a;<\/p>\n<p>ipcrm <span class=\"token parameter variable\">-m<\/span> 0x660135b2   <span class=\"token comment\"># \u274c \u62a5\u9519&#xff1a;\u975e\u6cd5\u53c2\u6570<\/span><br \/>\nipcrm <span class=\"token parameter variable\">-m<\/span> <span class=\"token number\">0<\/span>             <span class=\"token comment\"># \u274c \u540c\u6837\u5931\u8d25&#xff08;\u65e9\u671f Shmid \u4e3a 0 \u7684\u7279\u6b8a\u60c5\u51b5&#xff09;<\/span><br \/>\nipcrm <span class=\"token parameter variable\">-m<\/span> <span class=\"token number\">1<\/span>             <span class=\"token comment\"># \u2705 \u6210\u529f\u5220\u9664<\/span><\/p>\n<p>\u7ed3\u8bba&#xff1a;<\/p>\n<ul>\n<li>ipcrm \u672c\u8d28\u662f\u7528\u6237\u6001\u6307\u4ee4&#xff0c;\u5c01\u88c5\u4e86\u7cfb\u7edf\u8c03\u7528&#xff1b;<\/li>\n<li>\u7528\u6237\u5c42\u53ea\u80fd\u7528 Shmid \u7ba1\u7406\u5171\u4eab\u5185\u5b58&#xff1b;<\/li>\n<li>Key \u53ea\u7ed9\u5185\u6838\u505a\u552f\u4e00\u6027\u533a\u5206&#xff0c;\u7528\u6237\u5c42\u65e0\u6743\u76f4\u63a5\u7528 Key \u5220\u9664\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e09\u3001\u751f\u547d\u5468\u671f&#xff1a;\u968f\u5185\u6838&#xff0c;\u4e0d\u968f\u8fdb\u7a0b<\/h3>\n<p>\u8fd9\u662f\u672c\u8282\u8bfe\u7684\u7b2c\u4e00\u4e2a\u91cd\u78c5\u7ed3\u8bba\u3002<\/p>\n<h4>3.1 \u4e0e\u6587\u4ef6\u751f\u547d\u5468\u671f\u7684\u9c9c\u660e\u5bf9\u6bd4<\/h4>\n<ul>\n<li>\u6587\u4ef6&#xff1a;\u8fdb\u7a0b\u9000\u51fa \u2192 PCB \u9500\u6bc1 \u2192 \u6587\u4ef6\u63cf\u8ff0\u7b26\u8868\u91ca\u653e \u2192 \u5f15\u7528\u8ba1\u6570\u51cf\u4e3a 0 \u2192 \u6587\u4ef6\u81ea\u52a8\u5173\u95ed\u3002<br \/>\n\u5373&#xff1a;\u751f\u547d\u5468\u671f\u968f\u8fdb\u7a0b\u3002<\/li>\n<li>\u5171\u4eab\u5185\u5b58&#xff1a;\u5373\u4f7f\u521b\u5efa\u5b83\u7684 Server \u8fdb\u7a0b\u65e9\u5df2\u9000\u51fa&#xff0c;\u53ea\u8981\u6ca1\u6709\u663e\u5f0f\u5220\u9664&#xff0c;ipcs -m \u4f9d\u7136\u80fd\u770b\u5230\u5b83\u3002<br \/>\n\u5373&#xff1a;\u751f\u547d\u5468\u671f\u968f\u5185\u6838&#xff0c;\u76f4\u5230\u7cfb\u7edf\u91cd\u542f\u6216\u624b\u52a8\u5220\u9664\u3002<\/li>\n<\/ul>\n<p>\u8001\u5e08\u73b0\u573a\u590d\u73b0\u4e86\u4e0a\u8282\u8bfe\u7684\u201c\u5386\u53f2\u6b8b\u7559\u201d&#xff1a;<\/p>\n<p>ipcs <span class=\"token parameter variable\">-m<\/span><br \/>\n<span class=\"token comment\"># key&#061;0x660135b2 shmid&#061;0 owner&#061;whb perms&#061;0 bytes&#061;4096 nattch&#061;0<\/span><\/p>\n<p>\u867d\u7136\u521b\u5efa\u8fdb\u7a0b\u65e9\u5df2\u6d88\u5931&#xff0c;\u4f46\u8d44\u6e90\u4ecd\u5728\u3002\u8fd9\u4e5f\u662f\u5171\u4eab\u5185\u5b58\u7f16\u7a0b\u4e2d\u6700\u5371\u9669\u7684\u5751\u4e4b\u4e00&#xff1a;\u4e07\u4e00\u7a0b\u5e8f\u5f02\u5e38\u5d29\u6e83\u672a\u6267\u884c\u6e05\u7406&#xff0c;\u5185\u5b58\u5c31\u6cc4\u6f0f\u4e86\u3002<\/p>\n<h4>3.2 \u663e\u5f0f\u5220\u9664\u7684\u4e24\u6761\u8def\u5f84<\/h4>\n<li>\u6307\u4ee4\u7ea7&#xff1a;ipcrm -m &lt;shmid&gt;<\/li>\n<li>\u4ee3\u7801\u7ea7&#xff1a;shmctl(shmid, IPC_RMID, nullptr)<\/li>\n<p>\u8bfe\u5802\u5f3a\u8c03&#xff1a;\u5220\u9664\u65f6\u4e0d\u9700\u8981\u4e5f\u4e0d\u5e94\u8be5\u4f7f\u7528 Key&#xff1b;\u7b2c\u4e09\u4e2a\u5c5e\u6027\u53c2\u6570\u6682\u65f6\u4e0d\u5173\u5fc3&#xff0c;\u76f4\u63a5\u4f20 nullptr \u5373\u53ef\u3002<br \/>\nIPC_RMID \u662f\u4e00\u4e2a\u9884\u5b9a\u4e49\u7684\u5e38\u91cf&#xff0c;\u8868\u793a\u201c\u79fb\u9664\u5171\u4eab\u5185\u5b58\u6bb5\u201d\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001\u56db\u5927\u6838\u5fc3\u63a5\u53e3&#xff1a;\u521b\u5efa\u3001\u6302\u63a5\u3001\u5206\u79bb\u3001\u63a7\u5236<\/h3>\n<h4>4.1 shmget&#xff1a;\u521b\u5efa\u6216\u83b7\u53d6<\/h4>\n<p><span class=\"token keyword\">int<\/span> shmid <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">shmget<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">,<\/span> size<span class=\"token punctuation\">,<\/span> shmflg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6807\u5fd7\u4f4d\u7ec4\u5408&#xff1a;<\/p>\n<ul>\n<li>IPC_CREAT&#xff1a;\u4e0d\u5b58\u5728\u5219\u521b\u5efa&#xff0c;\u5b58\u5728\u5219\u83b7\u53d6&#xff08;\u4e3b\u83b7\u53d6&#xff09;&#xff1b;<\/li>\n<li>IPC_CREAT | IPC_EXCL&#xff1a;\u5b58\u5728\u5219\u62a5\u9519&#xff08;EEXIST&#xff09;&#xff0c;\u4e0d\u5b58\u5728\u5219\u521b\u5efa\u5168\u65b0\u5171\u4eab\u5185\u5b58&#xff08;\u4e3b\u521b\u5efa&#xff09;\u3002<\/li>\n<\/ul>\n<p>\u6743\u9650\u4f4d\u9677\u9631&#xff1a;<br \/>\nshmflg \u5fc5\u987b\u6309\u4f4d\u6216\u4e0a\u6743\u9650&#xff08;\u5982 0666&#xff09;&#xff0c;\u5426\u5219\u9ed8\u8ba4\u6743\u9650\u4e3a 0&#xff0c;\u5176\u4ed6\u8fdb\u7a0b\u6302\u63a5\u65f6\u4f1a\u76f4\u63a5 Permission denied\u3002<\/p>\n<p>\u8bfe\u5802\u73b0\u573a\u8e29\u5751&#xff1a;\u521b\u5efa\u540e ipcs -m \u770b\u5230 perms&#061;0&#xff0c;shmat \u7acb\u523b\u5931\u8d25\u3002\u4fee\u6b63\u540e&#xff1a;<\/p>\n<p><span class=\"token function\">shmget<\/span><span class=\"token punctuation\">(<\/span>_key<span class=\"token punctuation\">,<\/span> _size<span class=\"token punctuation\">,<\/span> IPC_CREAT <span class=\"token operator\">|<\/span> IPC_EXCL <span class=\"token operator\">|<\/span> <span class=\"token number\">0666<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u518d\u6b21\u67e5\u770b&#xff0c;perms&#061;666&#xff0c;\u6302\u63a5\u6210\u529f\u3002<\/p>\n<h4>4.2 shmat&#xff1a;\u6302\u63a5\u5230\u8fdb\u7a0b\u5730\u5740\u7a7a\u95f4<\/h4>\n<p><span class=\"token keyword\">void<\/span> <span class=\"token operator\">*<\/span>start <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">shmat<\/span><span class=\"token punctuation\">(<\/span>shmid<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<ul>\n<li>\u8fd4\u56de\u7684\u662f\u8d77\u59cb\u865a\u62df\u5730\u5740&#xff0c;\u4f4d\u4e8e\u8fdb\u7a0b\u865a\u62df\u7a7a\u95f4\u7684\u5171\u4eab\u533a&#xff1b;<\/li>\n<li>\u7528\u6237\u4f7f\u7528\u65b9\u5f0f\u4e0e malloc \u5b8c\u5168\u4e00\u81f4&#xff1a;\u62ff\u5230\u5730\u5740\u540e\u50cf\u64cd\u4f5c\u5927\u6570\u7ec4\u4e00\u6837\u76f4\u63a5\u8bfb\u5199&#xff0c;\u65e0\u9700\u7cfb\u7edf\u8c03\u7528&#xff1b;<\/li>\n<li>shmaddr \u7b2c\u4e8c\u4e2a\u53c2\u6570\u53ef\u8bbe\u4e3a\u56fa\u5b9a\u865a\u62df\u5730\u5740&#xff0c;\u4f46\u8001\u5e08\u63d0\u9192&#xff1a;\u8bbe\u4e3a nullptr&#xff0c;\u8ba9\u64cd\u4f5c\u7cfb\u7edf\u81ea\u5df1\u6311\u5730\u5740&#xff0c;\u7528\u6237\u4e0d\u8981\u76f2\u76ee\u6307\u5b9a&#xff0c;\u5426\u5219\u5bb9\u6613\u6620\u5c04\u5931\u8d25\u3002&#xff08;shmaddr \u662f shmat \u7cfb\u7edf\u8c03\u7528\u4e2d\u7684\u4e00\u4e2a\u53c2\u6570&#xff0c;\u7528\u4e8e\u6307\u5b9a\u5171\u4eab\u5185\u5b58\u6bb5\u5e94\u88ab\u6620\u5c04\u5230\u7684\u865a\u62df\u5730\u5740\u3002&#xff09;<\/li>\n<\/ul>\n<p>\u4e00\u4e2a\u9690\u853d\u7684 64 \u4f4d\u9677\u9631&#xff1a;<br \/>\n\u5982\u679c\u628a\u8fd4\u56de\u7684 void* \u5f3a\u8f6c\u4e3a int \u518d\u6bd4\u8f83\u662f\u5426\u5c0f\u4e8e 0&#xff0c;\u5728 64 \u4f4d\u7cfb\u7edf\u4e0b\u4f1a\u622a\u65ad 8 \u5b57\u8282\u6307\u9488&#xff0c;\u5bfc\u81f4\u8bef\u5224\u3002\u6b63\u786e\u505a\u6cd5\u662f\u4f7f\u7528 (long long) \u6216\u76f4\u63a5\u4e0e (void*)-1&#xff08;Linux \u4e0a shmat \u5931\u8d25\u786e\u5b9e\u8fd4\u56de (void *) &#8211; 1&#xff09; \u6bd4\u8f83\u3002<\/p>\n<h4>4.3 shmdt&#xff1a;\u5206\u79bb&#xff08;\u53bb\u5173\u8054&#xff09;<\/h4>\n<p><span class=\"token keyword\">int<\/span> n <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">shmdt<\/span><span class=\"token punctuation\">(<\/span>shmaddr<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<ul>\n<li>\u5c06\u5f53\u524d\u8fdb\u7a0b\u4e0e\u5171\u4eab\u5185\u5b58\u7684\u6620\u5c04\u5173\u7cfb\u65ad\u5f00&#xff0c;\u5f15\u7528\u8ba1\u6570 nattch \u51cf 1&#xff1b;<\/li>\n<li>\u6210\u529f\u8fd4\u56de 0&#xff1b;<\/li>\n<li>\u8fd9\u662f\u6b63\u786e\u5173\u95ed\u6d41\u7a0b\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u6b65&#xff1a;\u5148 shmdt&#xff0c;\u518d\u7531\u521b\u5efa\u8005 shmctl(&#8230;, IPC_RMID, &#8230;)\u3002<\/li>\n<li>shmaddr: \u6307\u5411\u5df2\u901a\u8fc7 shmat \u9644\u52a0\u7684\u5171\u4eab\u5185\u5b58\u6bb5\u7684\u8d77\u59cb\u5730\u5740(\u865a\u62df\u5730\u5740)\u3002<\/li>\n<\/ul>\n<h4>4.4 shmctl&#xff1a;\u63a7\u5236\u4e0e\u5220\u9664<\/h4>\n<p><span class=\"token comment\">\/\/ \u5220\u9664<\/span><br \/>\n<span class=\"token function\">shmctl<\/span><span class=\"token punctuation\">(<\/span>shmid<span class=\"token punctuation\">,<\/span> IPC_RMID<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">nullptr<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">\/\/ \u83b7\u53d6\u5c5e\u6027&#xff08;\u8f93\u51fa\u578b\u53c2\u6570&#xff09;<\/span><br \/>\n<span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">shmid_ds<\/span> ds<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">shmctl<\/span><span class=\"token punctuation\">(<\/span>shmid<span class=\"token punctuation\">,<\/span> IPC_STAT<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>ds<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4ece\u63a5\u53e3\u5230\u5de5\u7a0b&#xff1a;\u5c01\u88c5 C\/S \u901a\u4fe1\u6846\u67b6<\/h3>\n<p>\u4e3a\u4e86\u9690\u85cf\u5e95\u5c42\u7ec6\u8282&#xff0c;\u8bfe\u5802\u4e0a\u5c06\u5171\u4eab\u5185\u5b58\u5c01\u88c5\u4e3a Shm \u7c7b&#xff0c;\u5e76\u5f15\u5165 Creator \/ User \u4e24\u79cd\u89d2\u8272&#xff1a;<\/p>\n<table>\n<tr>\u89d2\u8272\u884c\u4e3a<\/tr>\n<tbody>\n<tr>\n<td>Creator&#xff08;Server&#xff09;<\/td>\n<td>ftok \u2192 shmget(IPC_CREAT | IPC_EXCL | 0666) \u2192 shmat \u2192 \u4f7f\u7528 \u2192 shmdt \u2192 shmctl(IPC_RMID)<\/td>\n<\/tr>\n<tr>\n<td>User&#xff08;Client&#xff09;<\/td>\n<td>ftok \u2192 shmget(IPC_CREAT)&#xff08;\u4ec5\u83b7\u53d6&#xff0c;\u4e0d\u5f3a\u5236\u521b\u5efa&#xff09; \u2192 shmat \u2192 \u4f7f\u7528 \u2192 shmdt<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8089\u773c\u53ef\u9a8c\u8bc1\u7684\u73b0\u8c61&#xff1a;<\/p>\n<li>Server \u4e0e Client \u6253\u5370\u51fa\u7684 Key\u3001Shmid \u5b8c\u5168\u76f8\u540c&#xff1b;<\/li>\n<li>\u865a\u62df\u5730\u5740\u53ef\u4ee5\u4e0d\u540c&#xff08;\u5982 0x7f84&#8230; vs 0x7fab&#8230;&#xff09;&#xff0c;\u8fd9\u4e0d\u5f71\u54cd\u901a\u4fe1&#xff0c;\u56e0\u4e3a\u6620\u5c04\u7684\u662f\u540c\u4e00\u5757\u7269\u7406\u9875&#xff1b;<\/li>\n<li>\u901a\u8fc7 ipcs -m \u89c2\u5bdf nattch \u53d8\u5316&#xff1a;0 \u2192 1&#xff08;Server \u6302\u63a5&#xff09;\u2192 2&#xff08;Client \u6302\u63a5&#xff09;\u2192 1 \u2192 0&#xff0c;\u6700\u7ec8\u5220\u9664\u3002<\/li>\n<hr \/>\n<h3>\u516d\u3001\u4e3a\u4ec0\u4e48\u5171\u4eab\u5185\u5b58\u662f\u201c\u6700\u5feb\u7684 IPC\u201d&#xff1f;<\/h3>\n<p>\u5efa\u7acb\u4fe1\u9053\u540e&#xff0c;\u901a\u4fe1\u8fdb\u5165\u201c\u5feb\u8f66\u9053\u201d&#xff1a;<\/p>\n<ul>\n<li>\u7ba1\u9053&#xff1a;write\/read \u90fd\u662f\u7cfb\u7edf\u8c03\u7528&#xff0c;\u6570\u636e\u5148\u5199\u5230\u5185\u6838\u6587\u4ef6\u7f13\u51b2\u533a&#xff0c;\u518d\u62f7\u8d1d\u5230\u7528\u6237\u7a7a\u95f4&#xff1b;<\/li>\n<li>\u5171\u4eab\u5185\u5b58&#xff1a;\u4e00\u65e6 shmat\u6302\u63a5\u5b8c\u6210&#xff0c;\u5185\u5b58\u4f4d\u4e8e\u7528\u6237\u7a7a\u95f4\u3002\u8fdb\u7a0b A \u5199\u5165\u865a\u62df\u5730\u5740&#xff0c;\u8fdb\u7a0b B \u7acb\u523b\u901a\u8fc7\u81ea\u8eab\u9875\u8868\u770b\u5230\u540c\u4e00\u7269\u7406\u9875\u7684\u53d8\u5316\u3002<\/li>\n<\/ul>\n<p>\u7ed3\u8bba&#xff1a;\u5171\u4eab\u5185\u5b58\u901a\u4fe1\u6ca1\u6709\u6570\u636e\u62f7\u8d1d\u3001\u6ca1\u6709\u7cfb\u7edf\u8c03\u7528\u5f00\u9500&#xff0c;\u901f\u5ea6\u662f\u6240\u6709 IPC \u4e2d\u6700\u5feb\u7684\u3002<\/p>\n<p>\u4f46\u6b63\u5982\u8001\u5e08\u90a3\u53e5\u751f\u52a8\u7684\u611f\u6168&#xff1a;<\/p>\n<p>\u201c\u6027\u683c\u5f00\u6717\u5728\u9700\u8981\u5e84\u91cd\u7684\u573a\u5408\u53cd\u800c\u662f\u7f3a\u70b9\u3002\u201d<\/p>\n<p>\u5171\u4eab\u5185\u5b58\u5728\u8ffd\u6c42\u6781\u81f4\u901f\u5ea6\u7684\u540c\u65f6&#xff0c;\u727a\u7272\u4e86\u540c\u6b65\u4e0e\u4fdd\u62a4\u673a\u5236\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u4ee3\u4ef7&#xff1a;\u6ca1\u6709\u540c\u6b65\u673a\u5236 &#061; \u6570\u636e\u4e0d\u4e00\u81f4<\/h3>\n<h4>7.1 \u73b0\u8c61&#xff1a;\u8bfb\u7aef\u201c\u65ad\u7ae0\u53d6\u4e49\u201d<\/h4>\n<p>\u5f53 Client \u60f3\u6210\u5bf9\u5199\u5165 AA BB CC DD&#xff0c;Server \u5374\u5728\u65e0\u8111\u5faa\u73af\u8bfb\u53d6\u3002\u7531\u4e8e\u53cc\u65b9\u6ca1\u6709\u4efb\u4f55\u534f\u540c&#xff0c;Server \u5f88\u53ef\u80fd\u8bfb\u5230&#xff1a;<\/p>\n<p>A<br \/>\nAB<br \/>\nABB<br \/>\n&#8230;<\/p>\n<p>\u539f\u672c\u5e94\u8be5\u6210\u5bf9\u51fa\u73b0\u7684 AA \u88ab\u62c6\u6210\u4e86 A\u3001AB&#xff0c;\u8fd9\u5c31\u662f\u5178\u578b\u7684\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>\u8001\u5e08\u4e3e\u4e86\u51e0\u4e2a\u63a5\u5730\u6c14\u7684\u4f8b\u5b50&#xff1a;<\/p>\n<ul>\n<li>\u5206\u624b\u77ed\u4fe1&#xff1a;\u5148\u53d1\u201c\u6211\u4eec\u5206\u624b\u5427\u201d&#xff0c;\u518d\u53d1\u201c\u62b1\u6b49\u53d1\u9519\u4e86\u201d\u3002\u5982\u679c\u8bfb\u7aef\u53ea\u8bfb\u4e86\u524d\u534a\u53e5&#xff0c;\u5c31\u4ea7\u751f\u4e86\u81f4\u547d\u8bef\u4f1a&#xff1b;<\/li>\n<li>ATM \u53d6\u94b1&#xff1a;\u4f60\u5fc5\u987b\u8fdb\u5c0f\u623f\u95f4\u3001\u53cd\u9501\u95e8&#xff0c;\u64cd\u4f5c\u671f\u95f4\u4e0d\u80fd\u8ba9\u522b\u4eba\u6253\u6270&#xff1b;<\/li>\n<li>\u4e0a\u5395\u6240&#xff1a;\u8981\u5173\u95e8&#xff0c;\u5426\u5219\u4f1a\u88ab\u6253\u6270\u3002<\/li>\n<\/ul>\n<p>\u5171\u4eab\u5185\u5b58\u672c\u8eab\u4e0d\u63d0\u4f9b\u8fd9\u6247\u201c\u95e8\u201d\u3002<\/p>\n<h4>7.2 \u8bfe\u5802\u65b9\u6848&#xff1a;\u7528\u547d\u540d\u7ba1\u9053\u6a21\u62df\u201c\u5524\u9192-\u7b49\u5f85\u201d\u540c\u6b65<\/h4>\n<p>\u5728\u8fd8\u6ca1\u5b66\u4fe1\u53f7\u91cf\u4e4b\u524d&#xff0c;\u8001\u5e08\u4e34\u65f6\u501f\u7528\u4e86\u4e0a\u8282\u8bfe\u7684 FIFO&#xff08;\u547d\u540d\u7ba1\u9053&#xff09; \u505a\u201c\u901a\u77e5\u7cfb\u7edf\u201d&#xff1a;<\/p>\n<table>\n<tr>\u6b65\u9aa4Client&#xff08;\u5199\u7aef&#xff09;Server&#xff08;\u8bfb\u7aef&#xff09;<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u6253\u5f00\u7ba1\u9053&#xff08;\u5199&#xff09;<\/td>\n<td>\u6253\u5f00\u7ba1\u9053&#xff08;\u8bfb&#xff09;\u2192 \u963b\u585e\u5728 read<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u5411\u5171\u4eab\u5185\u5b58\u5199\u4e24\u4e2a\u5b57\u7b26<\/td>\n<td>\u2014<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u5411\u7ba1\u9053\u5199\u5165 1 \u5b57\u8282\u5524\u9192\u5b57\u7b26<\/td>\n<td>\u7ba1\u9053\u6709\u6570\u636e&#xff0c;read \u8fd4\u56de&#xff0c;\u5524\u9192<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u2014<\/td>\n<td>\u8bfb\u53d6\u5171\u4eab\u5185\u5b58&#xff0c;\u6253\u5370\u6210\u5bf9\u6570\u636e<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u5ef6\u65f6 \/ \u8c03\u6574\u8282\u594f<\/td>\n<td>\u518d\u6b21\u963b\u585e\u7b49\u5f85\u4e0b\u4e00\u6b21\u5524\u9192<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u672c\u8d28&#xff1a;\u5171\u4eab\u5185\u5b58\u8d1f\u8d23\u9ad8\u901f\u4f20\u8f93\u6570\u636e&#xff0c;\u547d\u540d\u7ba1\u9053\u8d1f\u8d23\u4f20\u9012\u63a7\u5236\u4fe1\u53f7\u3002\u4e24\u8005\u7ec4\u5408&#xff0c;\u5b9e\u73b0\u4e86\u201c\u5199\u5b8c\u4e86\u518d\u8bfb\u201d\u7684\u6734\u7d20\u540c\u6b65\u3002<\/p>\n<p>\u26a0\ufe0f \u8001\u5e08\u53cd\u590d\u5f3a\u8c03&#xff1a;\u8fd9\u53ea\u662f\u6559\u5b66\u6f14\u793a&#xff0c;\u8ba9\u540c\u5b66\u4eec\u5148\u770b\u5230\u201c\u4ec0\u4e48\u53eb\u534f\u540c\u201d\u3002\u751f\u4ea7\u73af\u5883\u5fc5\u987b\u4f7f\u7528\u4fe1\u53f7\u91cf\u6216\u66f4\u5b8c\u5907\u7684\u540c\u6b65\u539f\u8bed\u3002<\/p>\n<p>\u5e76\u53d1\u9677\u9631&#xff1a;\u7531\u4e8e\u4e24\u4e2a\u8fdb\u7a0b\u5b8c\u5168\u5e76\u53d1&#xff0c;Client \u5524\u9192 Server \u540e&#xff0c;\u7acb\u523b\u8fdb\u5165\u4e0b\u4e00\u8f6e\u5199\u64cd\u4f5c&#xff0c;Server \u53ef\u80fd\u8fd8\u6ca1\u8bfb\u5b8c Client \u53c8\u5199\u5165\u4e86&#xff0c;\u5bfc\u81f4\u8282\u594f\u9519\u4e71\u3002\u8bfe\u5802\u4e0a\u901a\u8fc7 sleep \u5f3a\u884c\u8c03\u6574\u65f6\u5e8f&#xff0c;\u4f46\u4e5f\u4fa7\u9762\u8bc1\u660e\u4e86\u201c\u7ba1\u9053\u6a21\u62df\u540c\u6b65\u201d\u5e76\u4e0d\u9c81\u68d2&#xff08;\u201crobust\u201d&#xff0c;\u201c\u5065\u58ee\u201d&#xff09;\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u5185\u6838\u89c6\u89d2&#xff1a;\u63cf\u8ff0\u7ed3\u6784\u4f53\u4e0e\u5c5e\u6027\u83b7\u53d6<\/h3>\n<h4>8.1 struct shmid_ds<\/h4>\n<p>\u5185\u6838\u4e2d\u4e3a\u6bcf\u4e2a\u5171\u4eab\u5185\u5b58\u7ef4\u62a4\u4e00\u4e2a shmid_ds&#xff1a;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">shmid_ds<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">ipc_perm<\/span> shm_perm<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ Key\u3001UID\u3001GID\u3001\u6743\u9650 mode<\/span><br \/>\n    size_t          shm_segsz<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6bb5\u5927\u5c0f&#xff08;\u5b57\u8282&#xff09;<\/span><br \/>\n    time_t          shm_atime<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6700\u540e\u6302\u63a5\u65f6\u95f4<\/span><br \/>\n    time_t          shm_dtime<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6700\u540e\u5206\u79bb\u65f6\u95f4<\/span><br \/>\n    time_t          shm_ctime<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6700\u540e\u6539\u53d8\u65f6\u95f4<\/span><br \/>\n    pid_t           shm_cpid<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u521b\u5efa\u8005 PID<\/span><br \/>\n    pid_t           shm_lpid<span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u6700\u540e\u64cd\u4f5c PID<\/span><br \/>\n    shmatt_t        shm_nattch<span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u5f53\u524d\u5173\u8054\u8fdb\u7a0b\u6570<\/span><br \/>\n    <span class=\"token comment\">\/\/ &#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5176\u4e2d struct ipc_perm \u91cc\u5b58\u50a8\u4e86\u6211\u4eec\u901a\u8fc7 ftok \u4f20\u5165\u7684 Key\u3002\u8fd9\u4e5f\u9a8c\u8bc1\u4e86&#xff1a;Key \u4e0d\u662f\u6d6e\u4e8e\u8868\u9762\u7684\u53c2\u6570&#xff0c;\u800c\u662f\u88ab\u5199\u8fdb\u4e86\u5185\u6838\u7ed3\u6784\u4f53&#xff0c;\u6210\u4e3a\u5185\u6838\u8fa8\u8bc6\u8d44\u6e90\u7684\u6839\u672c\u4f9d\u636e\u3002<\/p>\n<h4>8.2 \u7528 IPC_STAT \u8bfb\u51fa\u5185\u6838\u72b6\u6001<\/h4>\n<p>\u8bfe\u5802\u4e0a\u5199\u4e86\u4e00\u4e2a Attr() \u63a5\u53e3&#xff0c;\u73b0\u573a\u6253\u5370&#xff1a;<\/p>\n<p><span class=\"token keyword\">struct<\/span> <span class=\"token class-name\">shmid_ds<\/span> ds<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">shmctl<\/span><span class=\"token punctuation\">(<\/span>shmid<span class=\"token punctuation\">,<\/span> IPC_STAT<span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&amp;<\/span>ds<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;shm_segsz: %ld\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> ds<span class=\"token punctuation\">.<\/span>shm_segsz<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token function\">printf<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;key: 0x%x\\\\n&#034;<\/span><span class=\"token punctuation\">,<\/span> ds<span class=\"token punctuation\">.<\/span>shm_perm<span class=\"token punctuation\">.<\/span>__key<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8fd0\u884c\u540e\u8f93\u51fa&#xff1a;<\/p>\n<p>shm_segsz: 4096<br \/>\nkey: 0x660135b2<\/p>\n<p>\u8fd9\u76f4\u63a5\u8bc1\u660e\u4e86&#xff1a;\u5171\u4eab\u5185\u5b58\u7edd\u4e0d\u53ea\u662f\u201c\u4e00\u5757\u88f8\u5185\u5b58\u201d&#xff0c;\u5b83\u4e00\u5b9a\u5bf9\u5e94\u4e00\u4e2a\u5185\u6838\u5bf9\u8c61&#xff0c;\u53ef\u4ee5\u88ab\u7ba1\u7406\u3001\u67e5\u8be2\u3001\u63a7\u5236\u3002<\/p>\n<hr \/>\n<h3>\u4e5d\u3001\u5bb9\u6613\u5ffd\u7565\u7684\u201c\u8fb9\u89d2\u6599\u201d\u77e5\u8bc6\u70b9<\/h3>\n<h4>9.1 \u7533\u8bf7\u5927\u5c0f\u6309 4KB \u5411\u4e0a\u53d6\u6574<\/h4>\n<p>\u8001\u5e08\u6545\u610f\u628a\u7533\u8bf7\u5927\u5c0f\u6539\u6210 4097&#xff1a;<\/p>\n<p><span class=\"token function\">shmget<\/span><span class=\"token punctuation\">(<\/span>key<span class=\"token punctuation\">,<\/span> <span class=\"token number\">4097<\/span><span class=\"token punctuation\">,<\/span> IPC_CREAT <span class=\"token operator\">|<\/span> IPC_EXCL <span class=\"token operator\">|<\/span> <span class=\"token number\">0666<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>ipcs -m \u663e\u793a\u5927\u5c0f\u4ecd\u662f 4097&#xff0c;\u4f46\u5185\u6838\u5b9e\u9645\u5206\u914d\u4e86 8192&#xff08;4096\u00d72&#xff09;\u3002<\/p>\n<p>\u539f\u56e0&#xff1a;\u5185\u6838\u4ee5\u9875&#xff08;4KB&#xff09;\u4e3a\u5355\u4f4d\u5206\u914d\u7269\u7406\u5185\u5b58\u3002\u7533\u8bf7 4097 \u5b57\u8282&#xff0c;\u64cd\u4f5c\u7cfb\u7edf\u4f1a\u5411\u4e0a\u53d6\u6574\u5230 2 \u9875\u3002\u7528\u6237\u867d\u7136\u53ea\u80fd\u201c\u770b\u5230\u201d 4097&#xff0c;\u4f46\u5982\u679c\u8d8a\u754c\u8bbf\u95ee\u5230\u7b2c 4098 \u5b57\u8282&#xff0c;\u4e0d\u4f1a\u7acb\u5373\u62a5\u9519&#xff0c;\u56e0\u4e3a\u540e\u9762\u90a3\u9875\u771f\u5b9e\u5b58\u5728\u2014\u2014\u8fd9\u4f1a\u5bfc\u81f4\u9690\u853d\u7684 Bug\u3002<\/p>\n<h4>9.2 System V IPC \u4e0e\u6587\u4ef6\u7684\u201c\u66a7\u6627\u5173\u7cfb\u201d<\/h4>\n<p>\u8001\u5e08\u8bf4 System V \u5171\u4eab\u5185\u5b58\u201c\u4e0e\u6587\u4ef6\u6709\u5173&#xff0c;\u4f46\u53c8\u4e0d\u662f\u5f3a\u76f8\u5173\u201d&#xff1a;<\/p>\n<ul>\n<li>\u5b83\u501f\u7528\u4e86\u6587\u4ef6\u7684\u6743\u9650\u6a21\u578b&#xff08;owner\u3001group\u3001other\u3001\u8bfb\u3001\u5199&#xff09;&#xff0c;\u6240\u4ee5\u4e00\u5207\u7686\u6587\u4ef6\u7684\u601d\u60f3\u5728\u8fd9\u91cc\u52c9\u5f3a\u9002\u7528&#xff1b;<\/li>\n<li>\u4f46\u5b83\u4e0d\u662f\u6587\u4ef6&#xff0c;\u4e0d\u8d70\u6587\u4ef6\u63cf\u8ff0\u7b26\u8868&#xff0c;\u4e0d\u7528 fd&#xff0c;\u4e5f\u4e0d\u7528 write\/read&#xff1b;<\/li>\n<li>\u56e0\u6b64\u73b0\u4ee3\u5e94\u7528\u4e2d&#xff0c;System V \u5171\u4eab\u5185\u5b58\u7528\u5f97\u8d8a\u6765\u8d8a\u5c11&#xff0c;POSIX \u5171\u4eab\u5185\u5b58\u3001\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3001\u7f51\u7edc\u901a\u4fe1\u65b9\u6848\u9010\u6e10\u6210\u4e3a\u4e3b\u6d41\u3002<\/li>\n<\/ul>\n<h4>9.3 \u8bfe\u5802\u4e0a\u7684\u8fde\u73af\u8e29\u5751\u8bb0\u5f55&#xff08;\u6309\u65f6\u95f4\u7ebf&#xff09;<\/h4>\n<li>\u53cd\u659c\u6760 \\\\n \u6ca1\u52a0&#xff1a;\u65e5\u5fd7\u6253\u5370\u7c98\u5728\u4e00\u884c&#xff0c;\u770b\u4e0d\u6e05 Key \u548c Shmid&#xff1b;<\/li>\n<li>\u6743\u9650\u4e3a 0&#xff1a;shmget \u6ca1\u5199 0666&#xff0c;shmat \u62a5 Permission denied&#xff1b;<\/li>\n<li>\u7cbe\u5ea6\u635f\u5931&#xff1a;void* \u5f3a\u8f6c int \u5224\u65ad\u8fd4\u56de\u503c&#xff0c;64 \u4f4d\u4e0b\u51fa\u9519&#xff1b;<\/li>\n<li>\u8def\u5f84\u5199\u6b7b\u4e3a\u6839\u76ee\u5f55 \/&#xff1a;\u547d\u540d\u7ba1\u9053\u521b\u5efa\u5931\u8d25&#xff0c;\u6539\u6210\u5f53\u524d\u76ee\u5f55 .\/ \u89e3\u51b3&#xff1b;<\/li>\n<li>Client \u5148\u542f\u52a8&#xff1a;Client \u62a2\u5148\u4ee5\u9ed8\u8ba4\u6743\u9650 0 \u521b\u5efa\u4e86\u5171\u4eab\u5185\u5b58&#xff0c;\u5bfc\u81f4 Server \u521b\u5efa\u65f6\u867d\u7136\u62a5\u9519\u201c\u5df2\u5b58\u5728\u201d&#xff0c;\u4f46\u6302\u63a5\u65f6\u6743\u9650\u4e0d\u8db3&#xff1b;<\/li>\n<li>\u5b57\u7b26\u4e32\u672a\u7ec8\u6b62&#xff1a;\u5171\u4eab\u5185\u5b58\u5f53\u5b57\u7b26\u4e32\u6253\u5370\u65f6\u5fd8\u8bb0\u586b &#039;\\\\0&#039;&#xff0c;\u8f93\u51fa\u4e71\u7801&#xff1b;<\/li>\n<li>Server \u6790\u6784\u51fd\u6570\u672a\u88ab\u8c03\u7528&#xff1a;Client \u9000\u51fa\u540e&#xff0c;Server \u7684 while(true) \u6b63\u5e38 break&#xff0c;\u4f46\u6808\u4e0a Shm \u5bf9\u8c61\u7684\u6790\u6784\u51fd\u6570\u6ca1\u6709\u88ab\u8c03\u7528&#xff0c;IPC \u8d44\u6e90\u6b8b\u7559\u3002\u8fd9\u662f\u4e0b\u8282\u8bfe\u8981\u653b\u514b\u7684\u9057\u7559 Bug\u3002<\/li>\n<hr \/>\n<h3>\u5341\u3001\u603b\u7ed3&#xff1a;\u4e00\u5f20\u56fe\u7406\u6e05\u5171\u4eab\u5185\u5b58\u5168\u751f\u547d\u5468\u671f<\/h3>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510      ftok       \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  \u7ea6\u5b9a Key   \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2192\u2502  \u5185\u6838\u8fa8\u8bc6  \u2502<br \/>\n\u2502 (\u7528\u6237\u5c42)    \u2502                 \u2502  \u552f\u4e00\u6027    \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518                 \u2514\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                      \u2502<br \/>\n                              shmget(IPC_CREAT|0666)<br \/>\n                                      \u2502<br \/>\n                                      \u25bc<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510               \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  \u7528\u6237\u5c42\u7ba1\u7406  \u2502 \u2190\u2500\u2500 Shmid \u2500\u2500\u2500\u2502  \u521b\u5efa\/\u83b7\u53d6  \u2502<br \/>\n\u2502 (\u6302\u63a5\/\u5220\u9664)  \u2502               \u2502  \u5171\u4eab\u5185\u5b58   \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518               \u2514\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n       \u2502                            \u2502<br \/>\n       \u2502       shmat(nullptr, 0)    \u2502<br \/>\n       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524<br \/>\n                                    \u25bc<br \/>\n                          \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                          \u2502  \u6620\u5c04\u5230\u8fdb\u7a0b\u865a\u62df   \u2502<br \/>\n                          \u2502  \u5730\u5740\u7a7a\u95f4&#xff08;\u5171\u4eab\u533a&#xff09;\u2502<br \/>\n                          \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                   \u2502<br \/>\n              \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n              \u2502                    \u2502                    \u2502<br \/>\n              \u25bc                    \u25bc                    \u25bc<br \/>\n        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510        \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n        \u2502 \u8fdb\u7a0b A   \u2502\u25c4\u2500\u2500\u2500\u2500\u2500\u2500\u25ba\u2502 \u7269\u7406\u5185\u5b58\u9875\u2502\u25c4\u2500\u2500\u2500\u2500\u2500\u2500\u25ba\u2502 \u8fdb\u7a0b B   \u2502<br \/>\n        \u2502 \u76f4\u63a5\u8bfb\u5199  \u2502        \u2502 (\u540c\u4e00\u4efd)  \u2502        \u2502 \u76f4\u63a5\u8bfb\u5199  \u2502<br \/>\n        \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518        \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518        \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                   \u2502<br \/>\n                         \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                         \u2502   \u65e0\u5185\u7f6e\u540c\u6b65\u673a\u5236   \u2502<br \/>\n                         \u2502  \u9700FIFO\/\u4fe1\u53f7\u91cf\u8f85\u52a9 \u2502<br \/>\n                         \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                   \u2502<br \/>\n                     \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n                     \u2502                             \u2502<br \/>\n                     \u25bc                             \u25bc<br \/>\n                 shmdt(\u5206\u79bb)                   shmctl(IPC_RMID)<br \/>\n                 nattch \u51cf 1                   \u6807\u8bb0\u5220\u9664<br \/>\n                     \u2502                             \u2502<br \/>\n                     \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                                    \u2502<br \/>\n                          nattch &#061;&#061; 0 \u65f6\u771f\u6b63\u91ca\u653e<\/p>\n<hr \/>\n<h3>\u5341\u4e00\u3001\u4e0b\u8282\u9884\u544a<\/h3>\n<li>\u6d88\u606f\u961f\u5217\u4e0e\u4fe1\u53f7\u91cf&#xff1a;\u7ee7\u7eed\u5b8c\u5584 IPC \u77e5\u8bc6\u4f53\u7cfb&#xff1b;<\/li>\n<li>\u5185\u6838\u7ec4\u7ec7\u89c6\u89d2&#xff1a;\u64cd\u4f5c\u7cfb\u7edf\u5982\u4f55\u628a\u5171\u4eab\u5185\u5b58\u3001\u6d88\u606f\u961f\u5217\u3001\u4fe1\u53f7\u91cf\u7edf\u4e00\u7ba1\u7406&#xff1b;<\/li>\n<li>\u9057\u7559 Bug \u653b\u5173&#xff1a;\u4e3a\u4ec0\u4e48 Server \u6b63\u5e38\u9000\u51fa\u65f6\u6790\u6784\u51fd\u6570\u672a\u88ab\u8c03\u7528&#xff1f;\u662f\u4ee3\u7801\u903b\u8f91\u9057\u6f0f&#xff0c;\u8fd8\u662f\u4e0e\u8fdb\u7a0b\u7ec8\u6b62\u65b9\u5f0f\u6709\u5173&#xff0c;\u5c06\u5728\u4e0b\u8282\u8bfe\u63ed\u6653\u3002<\/li>\n<hr \/>\n<p>\u8bfe\u540e\u601d\u8003\u9898&#xff08;\u6765\u81ea\u8bfe\u5802\u5b9e\u5f55&#xff09;&#xff1a;<\/p>\n<p>\u5982\u679c\u4f60\u7533\u8bf7\u5171\u4eab\u5185\u5b58\u65f6\u6307\u5b9a\u4e86 4097 \u5b57\u8282&#xff0c;\u5185\u6838\u5b9e\u9645\u7ed9\u4e86 8192 \u5b57\u8282\u3002\u5f53\u4f60\u901a\u8fc7 shmat \u8fd4\u56de\u7684\u5730\u5740\u8bbf\u95ee\u5230\u7b2c 5000 \u5b57\u8282\u65f6&#xff0c;\u7a0b\u5e8f\u4e0d\u4f1a\u5d29\u6e83&#xff0c;\u4f46\u5df2\u7ecf\u8d8a\u754c\u3002\u8fd9\u79cd\u201c\u9759\u9ed8\u7684\u8d8a\u754c\u201d\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u4f1a\u5bfc\u81f4\u4ec0\u4e48\u540e\u679c&#xff1f;\u5982\u4f55\u624d\u80fd\u5728\u5e94\u7528\u5c42\u5b89\u5168\u5730\u7ea6\u675f\u81ea\u5df1\u7684\u8bfb\u5199\u8303\u56f4&#xff1f;<\/p>\n<p>\u7b80\u8981\u56de\u7b54&#xff1a;<\/p>\n<ul>\n<li>\u540e\u679c&#xff1a;\u8d8a\u754c\u5199\u5165\u4f1a\u6084\u6084\u6539\u6389\u540c\u4e00\u7269\u7406\u9875\u91cc\u201c\u672c\u4e0d\u5c5e\u4e8e\u4f60\u201d\u7684\u5b57\u8282\u3002\u7531\u4e8e\u5185\u6838\u6309\u9875\u5206\u914d\u3001\u9875\u5185\u6ca1\u6709\u8fb9\u754c\u4fdd\u62a4&#xff0c;\u8fd9\u7c7b\u9519\u8bef\u4e0d\u4f1a\u7acb\u523b\u5d29\u6e83&#xff0c;\u800c\u662f\u8868\u73b0\u4e3a\u201c\u6570\u636e\u83ab\u540d\u5176\u5999\u88ab\u6539\u201d\u201c\u5bf9\u7aef\u8bfb\u5230\u810f\u6570\u636e\u201d\u201c\u5076\u53d1\u3001\u96be\u590d\u73b0\u201d\u7684\u8be1\u5f02 Bug&#xff1b;\u66f4\u7cdf\u7684\u662f&#xff0c;\u5982\u679c\u8d8a\u754c\u5199\u5230\u4e86\u76f8\u90bb\u5171\u4eab\u5185\u5b58\u6bb5\u6216\u5185\u6838\u5143\u6570\u636e\u6240\u5728\u9875&#xff0c;\u53ef\u80fd\u5f15\u53d1\u8fdb\u7a0b\u5d29\u6e83\u751a\u81f3\u8d44\u6e90\u72b6\u6001\u9519\u4e71&#xff0c;\u6392\u67e5\u6210\u672c\u6781\u9ad8\u3002<\/li>\n<li>\u7ea6\u675f\u529e\u6cd5&#xff1a;\u2460 \u7533\u8bf7\u65f6\u6309\u9875\u5bf9\u9f50&#xff08;\u5982 (size &#043; 4095) &amp; ~4095&#xff09;&#xff0c;\u8ba9\u201c\u7533\u8bf7\u5927\u5c0f\u201d\u4e0e\u201c\u5b9e\u9645\u53ef\u7528\u5927\u5c0f\u201d\u4e00\u81f4&#xff0c;\u907f\u514d\u5fc3\u7406\u4e0a\u7684\u9519\u89c9&#xff1b;\u2461 \u5728\u5171\u4eab\u5185\u5b58\u5934\u90e8\u653e\u4e00\u4e2a\u81ea\u63cf\u8ff0\u5934\u7ed3\u6784&#xff08;\u8bb0\u5f55 magic\u3001\u5bb9\u91cf\u3001\u8bfb\u5199\u504f\u79fb&#xff09;&#xff0c;\u6240\u6709\u8bfb\u5199\u90fd\u5148\u6821\u9a8c\u504f\u79fb\u4e0e\u957f\u5ea6&#xff1b;\u2462 \u5c01\u88c5 Shm \u7c7b\u65f6\u628a size \u4f5c\u4e3a\u6210\u5458\u4fdd\u5b58&#xff0c;\u5bf9\u5916\u53ea\u66b4\u9732\u5e26\u8fb9\u754c\u68c0\u67e5\u7684 read\/write \u63a5\u53e3&#xff0c;\u7981\u6b62\u88f8\u6307\u9488\u5916\u6cc4&#xff1b;\u2463 \u8c03\u8bd5\u671f\u7528 valgrind\u3001AddressSanitizer \u6216 mmap \u7684 PROT_NONE \u4fdd\u62a4\u9875\u505a\u54e8\u5175\u68c0\u6d4b&#xff1b;\u2464 \u751f\u4ea7\u73af\u5883\u914d\u5408\u4fe1\u53f7\u91cf\u505a\u540c\u6b65&#xff0c;\u4fdd\u8bc1\u201c\u5199\u591a\u5c11\u3001\u8bfb\u591a\u5c11\u201d\u4e25\u683c\u4e00\u81f4\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>System V \u5171\u4eab\u5185\u5b58\u673a\u5236&#xff1a;\u4ece\u5185\u6838\u539f\u7406\u5230\u4ee3\u7801\u5b9e\u6218\u8bfe\u7a0b\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u95f4\u901a\u4fe1&#xff08;IPC&#xff09;\u2014\u2014\u5171\u4eab\u5185\u5b58&#xff08;Shared Memory&#xff09;<br \/>\n\u6838\u5fc3\u76ee\u6807&#xff1a;\u7406\u89e3\u5171\u4eab\u5185\u5b58\u201c\u968f\u5185\u6838\u201d\u7684\u751f\u547d\u5468\u671f\u3001Key\/Shmid \u53cc\u6807\u8bc6\u4f53\u7cfb\u3001\u96f6\u62f7\u8d1d\u9ad8\u6027\u80fd\u80cc\u540e\u7684\u540c\u6b65\u4ee3\u4ef7&#xff0c;\u5e76\u624b\u5199\u4e00\u5957\u53ef\u8fd0\u884c\u7684 C\/S \u901a\u4fe1\u6846\u67b6\u3002\u4e00\u3001\u6838\u5fc3\u539f\u7406&#xff1a;\u5171\u4eab\u5185\u5b58\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f;<br \/>\n1.1 \u4e24\u5757\u62fc\u56fe&#xff1a;\u7269\u7406<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13178,868,58,43,305,442],"topic":[],"class_list":["post-118018","post","type-post","status-publish","format-standard","hentry","category-server","tag-1024---","tag-868","tag-linux","tag-43","tag-305","tag-442"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \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\/118018.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"System V \u5171\u4eab\u5185\u5b58\u673a\u5236&#xff1a;\u4ece\u5185\u6838\u539f\u7406\u5230\u4ee3\u7801\u5b9e\u6218\u8bfe\u7a0b\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u95f4\u901a\u4fe1&#xff08;IPC&#xff09;\u2014\u2014\u5171\u4eab\u5185\u5b58&#xff08;Shared Memory&#xff09; \u6838\u5fc3\u76ee\u6807&#xff1a;\u7406\u89e3\u5171\u4eab\u5185\u5b58\u201c\u968f\u5185\u6838\u201d\u7684\u751f\u547d\u5468\u671f\u3001Key\/Shmid \u53cc\u6807\u8bc6\u4f53\u7cfb\u3001\u96f6\u62f7\u8d1d\u9ad8\u6027\u80fd\u80cc\u540e\u7684\u540c\u6b65\u4ee3\u4ef7&#xff0c;\u5e76\u624b\u5199\u4e00\u5957\u53ef\u8fd0\u884c\u7684 C\/S \u901a\u4fe1\u6846\u67b6\u3002\u4e00\u3001\u6838\u5fc3\u539f\u7406&#xff1a;\u5171\u4eab\u5185\u5b58\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f; 1.1 \u4e24\u5757\u62fc\u56fe&#xff1a;\u7269\u7406\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/118018.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-25T19:48:18+00:00\" \/>\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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118018.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/118018.html\",\"name\":\"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-25T19:48:18+00:00\",\"dateModified\":\"2026-10-25T19:48:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/118018.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/118018.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/118018.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582\"}]},{\"@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-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \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\/118018.html","og_locale":"zh_CN","og_type":"article","og_title":"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"System V \u5171\u4eab\u5185\u5b58\u673a\u5236&#xff1a;\u4ece\u5185\u6838\u539f\u7406\u5230\u4ee3\u7801\u5b9e\u6218\u8bfe\u7a0b\u5b9a\u4f4d&#xff1a;\u8fdb\u7a0b\u95f4\u901a\u4fe1&#xff08;IPC&#xff09;\u2014\u2014\u5171\u4eab\u5185\u5b58&#xff08;Shared Memory&#xff09; \u6838\u5fc3\u76ee\u6807&#xff1a;\u7406\u89e3\u5171\u4eab\u5185\u5b58\u201c\u968f\u5185\u6838\u201d\u7684\u751f\u547d\u5468\u671f\u3001Key\/Shmid \u53cc\u6807\u8bc6\u4f53\u7cfb\u3001\u96f6\u62f7\u8d1d\u9ad8\u6027\u80fd\u80cc\u540e\u7684\u540c\u6b65\u4ee3\u4ef7&#xff0c;\u5e76\u624b\u5199\u4e00\u5957\u53ef\u8fd0\u884c\u7684 C\/S \u901a\u4fe1\u6846\u67b6\u3002\u4e00\u3001\u6838\u5fc3\u539f\u7406&#xff1a;\u5171\u4eab\u5185\u5b58\u5230\u5e95\u662f\u4ec0\u4e48&#xff1f; 1.1 \u4e24\u5757\u62fc\u56fe&#xff1a;\u7269\u7406","og_url":"https:\/\/www.wsisp.com\/helps\/118018.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-25T19:48:18+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/118018.html","url":"https:\/\/www.wsisp.com\/helps\/118018.html","name":"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-25T19:48:18+00:00","dateModified":"2026-10-25T19:48:18+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/118018.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/118018.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/118018.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u3010Linux-System\u3011\u3010System V\u5171\u4eab\u5185\u5b58\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u5b8c\u6574\u89e3\u6790\u3011\u6d41\u98df\u822c\u6295\u5582"}]},{"@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\/118018","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=118018"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/118018\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=118018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=118018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=118018"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=118018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}