{"id":78344,"date":"2026-02-27T07:49:28","date_gmt":"2026-02-26T23:49:28","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78344.html"},"modified":"2026-02-27T07:49:28","modified_gmt":"2026-02-26T23:49:28","slug":"linux-%e7%bd%91%e7%bb%9c-7","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78344.html","title":{"rendered":"Linux \u7f51\u7edc (7)"},"content":{"rendered":"<h2><span style=\"color:#000000\">netstat <\/span><\/h2>\n<p><span style=\"color:#000000\">netstat <\/span><span style=\"color:#000000\">\u662f\u4e00\u4e2a\u7528\u6765\u67e5\u770b\u7f51\u7edc\u72b6\u6001\u7684\u91cd\u8981\u5de5\u5177<\/span><span style=\"color:#000000\">. <\/span><\/p>\n<p><span style=\"color:#000000\">\u8bed\u6cd5<\/span><span style=\"color:#000000\">&#xff1a;<\/span><span style=\"color:#000000\">netstat [<\/span><span style=\"color:#000000\">\u9009\u9879<\/span><span style=\"color:#000000\">] <\/span><\/p>\n<p><span style=\"color:#000000\">\u529f\u80fd<\/span><span style=\"color:#000000\">&#xff1a;\u67e5\u770b\u7f51\u7edc\u72b6\u6001 <\/span><\/p>\n<p><span style=\"color:#000000\">\u5e38\u7528\u9009\u9879<\/span><span style=\"color:#000000\">&#xff1a; <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">n <\/span><span style=\"color:#646a73\">\u62d2\u7edd\u663e\u793a\u522b\u540d&#xff0c;\u80fd\u663e\u793a\u6570\u5b57\u7684\u5168\u90e8\u8f6c\u5316\u6210\u6570\u5b57 <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">l <\/span><span style=\"color:#646a73\">\u4ec5\u5217\u51fa\u6709\u5728 <\/span><span style=\"color:#646a73\">Listen (<\/span><span style=\"color:#646a73\">\u76d1\u542c<\/span><span style=\"color:#646a73\">) <\/span><span style=\"color:#646a73\">\u7684\u670d\u52d9\u72b6\u6001 <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">p <\/span><span style=\"color:#646a73\">\u663e\u793a\u5efa\u7acb\u76f8\u5173\u94fe\u63a5\u7684\u7a0b\u5e8f\u540d <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">t (tcp)<\/span><span style=\"color:#646a73\">\u4ec5\u663e\u793a <\/span><span style=\"color:#646a73\">tcp <\/span><span style=\"color:#646a73\">\u76f8\u5173\u9009\u9879 <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">u (udp)<\/span><span style=\"color:#646a73\">\u4ec5\u663e\u793a <\/span><span style=\"color:#646a73\">udp <\/span><span style=\"color:#646a73\">\u76f8\u5173\u9009\u9879 <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#646a73\">a (all)<\/span><span style=\"color:#646a73\">\u663e\u793a\u6240\u6709\u9009\u9879&#xff0c;\u9ed8\u8ba4\u4e0d\u663e\u793a <\/span><span style=\"color:#646a73\">LISTEN <\/span><span style=\"color:#646a73\">\u76f8\u5173<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"600\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234924-69a0dc04b39fb.png\" width=\"2024\" \/><\/p>\n<h2><span style=\"color:#000000\">pidof <\/span><\/h2>\n<p><span style=\"color:#000000\">\u5728\u67e5\u770b\u670d\u52a1\u5668\u7684\u8fdb\u7a0b <\/span><span style=\"color:#000000\">id <\/span><span style=\"color:#000000\">\u65f6\u975e\u5e38\u65b9\u4fbf<\/span><span style=\"color:#000000\">. <\/span><\/p>\n<p><span style=\"color:#000000\">\u8bed\u6cd5<\/span><span style=\"color:#000000\">&#xff1a;<\/span><span style=\"color:#000000\">pidof [<\/span><span style=\"color:#000000\">\u8fdb\u7a0b\u540d<\/span><span style=\"color:#000000\">] <\/span><\/p>\n<p><span style=\"color:#000000\">\u529f\u80fd<\/span><span style=\"color:#000000\">&#xff1a;\u901a\u8fc7\u8fdb\u7a0b\u540d<\/span><span style=\"color:#000000\">, <\/span><span style=\"color:#000000\">\u67e5\u770b\u8fdb\u7a0b <\/span><span style=\"color:#000000\">id<\/span><\/p>\n<\/p>\n<h2>TCP\u6293\u5305<\/h2>\n<\/p>\n<p>sudo tcpdump -i any tcp<\/p>\n<p><span style=\"color:#000000\">\u6ce8\u610f&#xff1a;<\/span><span style=\"color:#000000\">-i any <\/span><span style=\"color:#000000\">\u6307\u5b9a\u6355\u83b7\u6240\u6709\u7f51\u7edc\u63a5\u53e3\u4e0a\u7684\u6570\u636e\u5305&#xff0c;<\/span><span style=\"color:#000000\">tcp <\/span><span style=\"color:#000000\">\u6307\u5b9a\u6355\u83b7 <\/span><span style=\"color:#000000\">TCP <\/span><span style=\"color:#000000\">\u534f\u8bae\u7684\u6570\u636e <\/span><\/p>\n<p><span style=\"color:#000000\">\u5305\u3002<\/span><span style=\"color:#000000\">i <\/span><span style=\"color:#000000\">\u53ef\u4ee5\u7406\u89e3\u6210\u4e3a <\/span><span style=\"color:#000000\">interface <\/span><span style=\"color:#000000\">\u7684\u610f\u601d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"718\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234925-69a0dc0567ff6.png\" width=\"1086\" \/><\/p>\n<p><span style=\"color:#000000\">\u5982\u679c\u4f60\u53ea\u60f3\u6355\u83b7\u67d0\u4e2a\u7279\u5b9a\u7f51\u7edc\u63a5\u53e3&#xff08;\u5982 <\/span><span style=\"color:#000000\">eth0<\/span><span style=\"color:#000000\">&#xff09;\u4e0a\u7684 <\/span><span style=\"color:#000000\">TCP <\/span><span style=\"color:#000000\">\u62a5\u6587&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/span><\/p>\n<p>sudo tcpdump -i eth0 tcp<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"496\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234925-69a0dc05d0a9b.png\" width=\"1084\" \/><\/p>\n<p><span style=\"color:#000000\">\u4f7f\u7528 <\/span><span style=\"color:#000000\">host <\/span><span style=\"color:#000000\">\u5173\u952e\u5b57\u53ef\u4ee5\u6307\u5b9a\u6e90\u6216\u76ee\u7684 <\/span><span style=\"color:#000000\">IP <\/span><span style=\"color:#000000\">\u5730\u5740\u3002\u4f8b\u5982&#xff0c;\u8981\u6355\u83b7\u6e90 <\/span><span style=\"color:#000000\">IP <\/span><span style=\"color:#000000\">\u5730\u5740\u4e3a <\/span><\/p>\n<p><span style=\"color:#000000\">192.168.1.100 <\/span><span style=\"color:#000000\">\u7684 <\/span><span style=\"color:#000000\">TCP <\/span><span style=\"color:#000000\">\u62a5\u6587&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/span><\/p>\n<p>$ sudo tcpdump src host 192.168.1.100 and tcp<\/p>\n<p><span style=\"color:#000000\">\u540c\u65f6\u6307\u5b9a\u6e90\u548c\u76ee\u7684 <\/span><span style=\"color:#000000\">IP <\/span><span style=\"color:#000000\">\u5730\u5740&#xff0c;\u53ef\u4ee5\u4f7f\u7528 <\/span><span style=\"color:#000000\">and <\/span><span style=\"color:#000000\">\u5173\u952e\u5b57\u8fde\u63a5\u4e24\u4e2a\u6761\u4ef6&#xff1a;<\/span><\/p>\n<p>sudo tcpdump src host 192.168.1.100 and dst host 192.168.1.200<br \/>\nand tcp<\/p>\n<p><span style=\"color:#000000\">\u6355\u83b7\u7279\u5b9a\u7aef\u53e3\u7684 <\/span><span style=\"color:#000000\">TCP <\/span><span style=\"color:#000000\">\u62a5\u6587 <\/span><\/p>\n<p><span style=\"color:#000000\">\u4f7f\u7528 <\/span><span style=\"color:#000000\">port <\/span><span style=\"color:#000000\">\u5173\u952e\u5b57\u53ef\u4ee5\u6307\u5b9a\u7aef\u53e3\u53f7\u3002<\/span><\/p>\n<p><span style=\"color:#000000\">\u4f8b\u5982&#xff0c;\u8981\u6355\u83b7\u7aef\u53e3\u53f7\u4e3a <\/span><span style=\"color:#000000\">80 <\/span><span style=\"color:#000000\">\u7684 <\/span><span style=\"color:#000000\">TCP <\/span><span style=\"color:#000000\">\u62a5\u6587&#xff08;\u901a\u5e38\u662f HTTP \u8bf7\u6c42&#xff09;&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/span><\/p>\n<p>sudo tcpdump port 80 and tcp<\/p>\n<p><span style=\"color:#000000\">\u4fdd\u5b58\u6355\u83b7\u7684\u6570\u636e\u5305\u5230\u6587\u4ef6 <\/span><\/p>\n<p><span style=\"color:#000000\">\u4f7f\u7528 <\/span><span style=\"color:#000000\">-w <\/span><span style=\"color:#000000\">\u9009\u9879\u53ef\u4ee5\u5c06\u6355\u83b7\u7684\u6570\u636e\u5305\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d&#xff0c;\u4ee5\u4fbf\u540e\u7eed\u5206\u6790\u3002<\/span><\/p>\n<p>sudo tcpdump -i eth0 port 80 -w data.pcap<\/p>\n<p><span style=\"color:#000000\">\u8fd9\u5c06\u628a\u6355\u83b7\u5230\u7684 <\/span><span style=\"color:#000000\">HTTP <\/span><span style=\"color:#000000\">\u6d41\u91cf\u4fdd\u5b58\u5230\u540d\u4e3a <\/span><span style=\"color:#000000\">data.pcap <\/span><span style=\"color:#000000\">\u7684\u6587\u4ef6\u4e2d\u3002 <\/span><\/p>\n<p><span style=\"color:#3370ff\">\u2022 <\/span><\/p>\n<p><span style=\"color:#000000\">\u4e86\u89e3&#xff1a;<\/span><span style=\"color:#000000\">pcap <\/span><span style=\"color:#000000\">\u540e\u7f00\u7684\u6587\u4ef6\u901a\u5e38\u4e0e <\/span><span style=\"color:#000000\">PCAP<\/span><span style=\"color:#000000\">&#xff08;<\/span><span style=\"color:#000000\">Packet Capture<\/span><span style=\"color:#000000\">&#xff09;\u6587\u4ef6\u683c\u5f0f\u76f8\u5173&#xff0c;\u8fd9\u662f\u4e00 <\/span><\/p>\n<p><span style=\"color:#000000\">\u79cd\u7528\u4e8e\u6355\u83b7\u7f51\u7edc\u6570\u636e\u5305\u7684\u6587\u4ef6\u683c\u5f0f<\/span><\/p>\n<p><span style=\"color:#000000\">\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5305\u8fdb\u884c\u5206\u6790 <\/span><\/p>\n<p><span style=\"color:#000000\">\u4f7f\u7528 <\/span><span style=\"color:#000000\">-r <\/span><span style=\"color:#000000\">\u9009\u9879\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5305\u8fdb\u884c\u5206\u6790<\/span><\/p>\n<p>tcpdump -r data.pcap<\/p>\n<p>\u8fd9\u5c06\u8bfb\u53d6 data.pcap \u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5305\u5e76\u8fdb\u884c\u5206\u6790\u3002<br \/>\n\u6ce8\u610f\u4e8b\u9879<br \/>\n\u2022 \u4f7f\u7528 tcpdump \u65f6&#xff0c;\u8bf7\u786e\u4fdd\u4f60\u6709\u8db3\u591f\u7684\u6743\u9650\u6765\u6355\u83b7\u7f51\u7edc\u63a5\u53e3\u4e0a\u7684\u6570\u636e\u5305\u3002\u901a\u5e38&#xff0c;\u4f60<br \/>\n\u9700\u8981\u4ee5 root \u7528\u6237\u8eab\u4efd\u8fd0\u884c tcpdump\u3002<br \/>\n\u2022 \u4f7f\u7528 tcpdump \u7684\u65f6\u5019&#xff0c;\u6709\u4e9b\u4e3b\u673a\u540d\u4f1a\u88ab\u4e91\u670d\u52a1\u5668\u89e3\u91ca\u6210\u4e3a\u968f\u673a\u7684\u4e3b\u673a\u540d&#xff0c;\u5982\u679c\u4e0d<br \/>\n\u60f3\u8981&#xff0c;\u5c31\u7528-n \u9009\u9879<\/p>\n<\/p>\n<p>\u2022 \u4e3b\u673a\u89c2\u5bdf\u4e09\u6b21\u63e1\u624b\u7684\u7b2c\u4e09\u6b21\u63e1\u624b&#xff0c;\u4e0d\u5360\u5e8f\u53f7<\/p>\n<\/p>\n<h2>\u81ea\u65cb\u9501<\/h2>\n<h5>1. \u6982\u8ff0<\/h5>\n<p>\u81ea\u65cb\u9501\u662f\u4e00\u79cd\u591a\u7ebf\u7a0b\u540c\u6b65\u673a\u5236&#xff0c;\u7528\u4e8e\u4fdd\u62a4\u5171\u4eab\u8d44\u6e90\u3002\u7ebf\u7a0b\u83b7\u53d6\u9501\u5931\u8d25\u65f6&#xff0c;\u4f1a ** \u5faa\u73af\u81ea\u65cb&#xff08;\u4e0d\u65ad\u68c0\u67e5\u9501\u72b6\u6001&#xff09;** \u800c\u975e\u8fdb\u5165\u4f11\u7720&#xff0c;\u4ee5\u6b64\u51cf\u5c11\u7ebf\u7a0b\u5207\u6362\u5f00\u9500&#xff0c;\u9002\u7528\u4e8e\u77ed\u65f6\u95f4\u9501\u7ade\u4e89&#xff1b;\u4f46\u4e0d\u5408\u7406\u4f7f\u7528\u4f1a\u9020\u6210 CPU \u8d44\u6e90\u6d6a\u8d39\u3002<\/p>\n<h5>2. \u539f\u7406<\/h5>\n<ul>\n<li>\u7528\u5171\u4eab\u6807\u5fd7\u4f4d\u8868\u793a\u9501\u72b6\u6001&#xff1a;true\u8868\u793a\u9501\u88ab\u5360\u7528&#xff0c;false\u8868\u793a\u9501\u53ef\u7528\u3002<\/li>\n<li>\u7ebf\u7a0b\u5c1d\u8bd5\u83b7\u53d6\u9501\u65f6&#xff1a;\n<ul>\n<li>\u82e5\u6807\u5fd7\u4f4d\u4e3afalse&#xff0c;\u5219\u5c06\u5176\u8bbe\u4e3atrue&#xff0c;\u5360\u7528\u9501\u5e76\u8fdb\u5165\u4e34\u754c\u533a\u3002<\/li>\n<li>\u82e5\u6807\u5fd7\u4f4d\u4e3atrue&#xff0c;\u5219\u5728\u5faa\u73af\u4e2d\u6301\u7eed\u81ea\u65cb\u7b49\u5f85&#xff0c;\u76f4\u5230\u9501\u88ab\u91ca\u653e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>3. \u4f18\u7f3a\u70b9<\/h5>\n<ul>\n<li>\u4f18\u70b9&#xff1a;\n<ul>\n<li>\u4f4e\u5ef6\u8fdf&#xff1a;\u907f\u514d\u7ebf\u7a0b\u4f11\u7720\u4e0e\u5524\u9192&#xff0c;\u63d0\u5347\u9501\u64cd\u4f5c\u6548\u7387\u3002<\/li>\n<li>\u51cf\u5c11\u7cfb\u7edf\u8c03\u5ea6\u5f00\u9500&#xff1a;\u7b49\u5f85\u7ebf\u7a0b\u4e0d\u963b\u585e&#xff0c;\u65e0\u9700\u4e0a\u4e0b\u6587\u5207\u6362\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u7f3a\u70b9&#xff1a;\n<ul>\n<li>CPU \u8d44\u6e90\u6d6a\u8d39&#xff1a;\u9501\u6301\u6709\u65f6\u95f4\u8f83\u957f\u65f6&#xff0c;\u81ea\u65cb\u7ebf\u7a0b\u4f1a\u6301\u7eed\u5360\u7528 CPU\u3002<\/li>\n<li>\u53ef\u80fd\u5f15\u53d1\u6d3b\u9501&#xff1a;\u591a\u7ebf\u7a0b\u540c\u65f6\u81ea\u65cb\u4e14\u65e0\u9000\u907f\u7b56\u7565\u65f6&#xff0c;\u53ef\u80fd\u90fd\u65e0\u6cd5\u83b7\u53d6\u9501\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>4. \u4f7f\u7528\u573a\u666f<\/h5>\n<ul>\n<li>\u9501\u5360\u7528\u65f6\u95f4\u6781\u77ed\u7684\u573a\u666f&#xff08;\u5982\u591a\u7ebf\u7a0b\u5bf9\u5171\u4eab\u6570\u636e\u8fdb\u884c\u7b80\u5355\u8bfb\u5199&#xff09;\u3002<\/li>\n<li>\u7cfb\u7edf\u5e95\u5c42&#xff0c;\u7528\u4e8e\u540c\u6b65\u591a\u4e2a CPU \u5bf9\u5171\u4eab\u8d44\u6e90\u7684\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n<h5>5. \u5b9e\u73b0\u539f\u7406<\/h5>\n<p>\u4f9d\u8d56\u539f\u5b50\u64cd\u4f5c&#xff08;\u5982 CAS \u6307\u4ee4&#xff09;\u4fdd\u8bc1\u9501\u72b6\u6001\u4fee\u6539\u7684\u539f\u5b50\u6027&#xff0c;\u907f\u514d\u5e76\u53d1\u51b2\u7a81<\/p>\n<\/p>\n<h4>\u6ce8\u610f\u4e8b\u9879<\/h4>\n<li>\u9501\u6301\u6709\u65f6\u95f4\u8981\u77ed&#xff1a;\u4f7f\u7528\u81ea\u65cb\u9501\u65f6&#xff0c;\u5fc5\u987b\u786e\u4fdd\u9501\u88ab\u91ca\u653e\u7684\u65f6\u95f4\u5c3d\u53ef\u80fd\u77ed&#xff0c;\u5426\u5219\u7b49\u5f85\u7ebf\u7a0b\u4f1a\u6301\u7eed\u81ea\u65cb&#xff0c;\u9020\u6210\u5927\u91cf CPU \u8d44\u6e90\u6d6a\u8d39\u3002<\/li>\n<li>\u591a CPU \u73af\u5883\u4e0b\u7684\u6548\u7387\u95ee\u9898&#xff1a;\u5728\u591a CPU \u73af\u5883\u4e2d&#xff0c;\u81ea\u65cb\u9501\u53ef\u80fd\u4e0d\u5982\u5176\u4ed6\u9501\u673a\u5236\u9ad8\u6548&#xff0c;\u56e0\u4e3a\u7b49\u5f85\u7ebf\u7a0b\u53ef\u80fd\u5728\u4e0d\u540c\u7684 CPU \u6838\u5fc3\u4e0a\u6301\u7eed\u81ea\u65cb\u7b49\u5f85&#xff0c;\u65e0\u6cd5\u91ca\u653e\u8ba1\u7b97\u8d44\u6e90\u3002<\/li>\n<hr \/>\n<h4>\u7ed3\u8bba<\/h4>\n<p>\u81ea\u65cb\u9501\u662f\u4e00\u79cd\u9002\u7528\u4e8e\u77ed\u65f6\u95f4\u9501\u7ade\u4e89\u7684\u540c\u6b65\u673a\u5236&#xff0c;\u5b83\u901a\u8fc7\u907f\u514d\u7ebf\u7a0b\u4f11\u7720\u548c\u4e0a\u4e0b\u6587\u5207\u6362&#xff0c;\u663e\u8457\u964d\u4f4e\u4e86\u9501\u64cd\u4f5c\u7684\u5f00\u9500&#xff0c;\u63d0\u5347\u4e86\u6548\u7387\u3002\u4f46\u5b83\u4e5f\u5b58\u5728\u660e\u663e\u7f3a\u70b9&#xff1a;\u957f\u65f6\u95f4\u6301\u6709\u9501\u4f1a\u5bfc\u81f4 CPU \u8d44\u6e90\u6d6a\u8d39&#xff0c;\u4e14\u5728\u65e0\u9000\u907f\u7b56\u7565\u7684<\/p>\n<\/p>\n<h3>1. pthread_spin_init() \u2014\u2014 \u521d\u59cb\u5316\u81ea\u65cb\u9501<\/h3>\n<p>int pthread_spin_init(pthread_spinlock_t *lock, int pshared);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u521d\u59cb\u5316\u4e00\u4e2a\u81ea\u65cb\u9501&#xff0c;\u5fc5\u987b\u5728\u4f7f\u7528\u524d\u8c03\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 1 lock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411pthread_spinlock_t\u53d8\u91cf\u7684\u6307\u9488&#xff0c;\u7528\u4e8e\u5b58\u50a8\u521d\u59cb\u5316\u540e\u7684\u9501\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 2 pshared<\/td>\n<td>\u8f93\u5165\u53c2\u6570&#xff1a;\u9501\u7684\u5171\u4eab\u8303\u56f4- PTHREAD_PROCESS_PRIVATE&#xff1a;\u4ec5\u5f53\u524d\u8fdb\u7a0b\u5185\u7ebf\u7a0b\u5171\u4eab&#xff08;\u6700\u5e38\u7528&#xff09;- PTHREAD_PROCESS_SHARED&#xff1a;\u53ef\u8de8\u8fdb\u7a0b\u5171\u4eab&#xff08;\u9700\u914d\u5408\u5171\u4eab\u5185\u5b58&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982EINVAL\u3001ENOMEM&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u672a\u521d\u59cb\u5316\u7684\u9501\u4e0d\u80fd\u4f7f\u7528&#xff1b;\u540c\u4e00\u9501\u4e0d\u80fd\u91cd\u590d\u521d\u59cb\u5316<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>2. pthread_spin_destroy() \u2014\u2014 \u9500\u6bc1\u81ea\u65cb\u9501<\/h4>\n<p>int pthread_spin_destroy(pthread_spinlock_t *lock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u9500\u6bc1\u5df2\u521d\u59cb\u5316\u7684\u81ea\u65cb\u9501&#xff0c;\u91ca\u653e\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 lock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u9500\u6bc1\u7684pthread_spinlock_t\u53d8\u91cf\u7684\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982EINVAL\u8868\u793a\u9501\u65e0\u6548&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u4e0d\u80fd\u9500\u6bc1\u6b63\u5728\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6301\u6709\u7684\u9501&#xff1b;\u9500\u6bc1\u540e\u4e0d\u80fd\u518d\u4f7f\u7528\u8be5\u9501&#xff0c;\u9664\u975e\u91cd\u65b0\u521d\u59cb\u5316<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>3. pthread_spin_lock() \u2014\u2014 \u963b\u585e\u5f0f\u52a0\u9501<\/h4>\n<h4><\/h4>\n<\/p>\n<p>int pthread_spin_lock(pthread_spinlock_t *lock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u963b\u585e\u5f0f\u83b7\u53d6\u9501&#xff1a;\u83b7\u53d6\u4e0d\u5230\u5219\u6301\u7eed\u81ea\u65cb\u7b49\u5f85&#xff0c;\u76f4\u5230\u9501\u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 lock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u83b7\u53d6\u7684\u81ea\u65cb\u9501\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982EDEADLK\u68c0\u6d4b\u5230\u6b7b\u9501&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u81ea\u65cb\u9501\u4e0d\u652f\u6301\u91cd\u5165&#xff0c;\u540c\u4e00\u7ebf\u7a0b\u591a\u6b21\u52a0\u9501\u4f1a\u5bfc\u81f4\u6b7b\u9501&#xff1b;\u6301\u6709\u9501\u7684\u65f6\u95f4\u5fc5\u987b\u6781\u77ed<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>4. pthread_spin_trylock() \u2014\u2014 \u975e\u963b\u585e\u5f0f\u5c1d\u8bd5\u52a0\u9501<\/h4>\n<\/p>\n<p>int pthread_spin_trylock(pthread_spinlock_t *lock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u975e\u963b\u585e\u5f0f\u5c1d\u8bd5\u52a0\u9501&#xff1a;\u83b7\u53d6\u4e0d\u5230\u5219\u7acb\u5373\u8fd4\u56de&#xff0c;\u4e0d\u4f1a\u81ea\u65cb\u7b49\u5f85<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 lock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u5c1d\u8bd5\u83b7\u53d6\u7684\u81ea\u65cb\u9501\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>&#8211; \u6210\u529f\u83b7\u53d6\u9501&#xff1a;\u8fd4\u56de0- \u9501\u88ab\u5360\u7528&#xff1a;\u8fd4\u56deEBUSY- \u5176\u4ed6\u9519\u8bef&#xff1a;\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u9002\u5408 \u201c\u4e0d\u60f3\u7b49\u5f85&#xff0c;\u5931\u8d25\u5219\u505a\u5176\u4ed6\u4e8b\u201d \u7684\u573a\u666f&#xff1b;\u540c\u6837\u4e0d\u652f\u6301\u91cd\u5165<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>5. pthread_spin_unlock() \u2014\u2014 \u89e3\u9501<\/h4>\n<\/p>\n<p>int pthread_spin_unlock(pthread_spinlock_t *lock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u91ca\u653e\u81ea\u65cb\u9501&#xff0c;\u5fc5\u987b\u7531\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u8c03\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 lock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u91ca\u653e\u7684\u81ea\u65cb\u9501\u6307\u9488<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982EPERM\u8868\u793a\u8c03\u7528\u7ebf\u7a0b\u4e0d\u6301\u6709\u8be5\u9501&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u672a\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u8c03\u7528\u89e3\u9501&#xff0c;\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a&#xff08;\u5982\u7a0b\u5e8f\u5d29\u6e83&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;stdlib.h&gt;<br \/>\n#include &lt;string.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;pthread.h&gt;<\/p>\n<p>int ticket &#061; 20;<br \/>\n\/\/ 1. \u53d6\u6d88\u81ea\u65cb\u9501\u53d8\u91cf\u6ce8\u91ca<br \/>\npthread_spinlock_t lock;<\/p>\n<p>void *route(void *arg)<br \/>\n{<br \/>\n    char *id &#061; (char *)arg;<br \/>\n    while (1)<br \/>\n    {<br \/>\n        \/\/ 2. \u52a0\u9501&#xff1a;\u83b7\u53d6\u81ea\u65cb\u9501&#xff0c;\u4fdd\u62a4\u4e34\u754c\u533a<br \/>\n        pthread_spin_lock(&amp;lock);<br \/>\n        if (ticket &gt; 0)<br \/>\n        {<br \/>\n            usleep(1000); \/\/ \u6a21\u62df\u552e\u7968\u8017\u65f6&#xff08;\u77ed\u65f6\u95f4&#xff0c;\u7b26\u5408\u81ea\u65cb\u9501\u4f7f\u7528\u539f\u5219&#xff09;<br \/>\n            printf(&#034;%s sells ticket:%d\\\\n&#034;, id, ticket);<br \/>\n            ticket&#8211;;<br \/>\n            \/\/ 3. \u89e3\u9501&#xff1a;\u91ca\u653e\u81ea\u65cb\u9501<br \/>\n            pthread_spin_unlock(&amp;lock);<br \/>\n        }<br \/>\n        else<br \/>\n        {<br \/>\n            \/\/ 4. \u65e0\u7968\u65f6\u4e5f\u8981\u89e3\u9501&#xff0c;\u907f\u514d\u6b7b\u9501<br \/>\n            pthread_spin_unlock(&amp;lock);<br \/>\n            break;<br \/>\n        }<br \/>\n    }<br \/>\n    \/\/ 5. C\u8bed\u8a00\u4e2d\u7528NULL\u800c\u975enullptr<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main(void)<br \/>\n{<br \/>\n    \/\/ 6. \u521d\u59cb\u5316\u81ea\u65cb\u9501<br \/>\n    pthread_spin_init(&amp;lock, PTHREAD_PROCESS_PRIVATE);<br \/>\n    pthread_t t1, t2, t3;<\/p>\n<p>    \/\/ \u521b\u5efa3\u4e2a\u552e\u7968\u7ebf\u7a0b<br \/>\n    pthread_create(&amp;t1, NULL, route, (void *)&#034;thread 1&#034;);<br \/>\n    pthread_create(&amp;t2, NULL, route, (void *)&#034;thread 2&#034;);<br \/>\n    pthread_create(&amp;t3, NULL, route, (void *)&#034;thread 3&#034;);<\/p>\n<p>    \/\/ 7. \u7b49\u5f85\u6240\u6709\u5b50\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210&#xff08;\u6838\u5fc3\u4fee\u590d\u70b9&#xff09;<br \/>\n    pthread_join(t1, NULL);<br \/>\n    pthread_join(t2, NULL);<br \/>\n    pthread_join(t3, NULL);<\/p>\n<p>    \/\/ 8. \u9500\u6bc1\u81ea\u65cb\u9501&#xff0c;\u91ca\u653e\u8d44\u6e90<br \/>\n    pthread_spin_destroy(&amp;lock);<br \/>\n    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"798\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234926-69a0dc0637cef.png\" width=\"1218\" \/><\/p>\n<\/p>\n<h2><span style=\"color:#000000\">\u8bfb\u5199\u9501<\/span><\/h2>\n<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"328\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234926-69a0dc06ac0b1.png\" width=\"1376\" \/><\/p>\n<p><span style=\"color:#000000\">\u5728\u7f16\u5199\u591a\u7ebf\u7a0b\u7684\u65f6\u5019&#xff0c;\u6709\u4e00\u79cd\u60c5\u51b5\u662f\u5341\u5206\u5e38\u89c1\u7684\u3002\u90a3\u5c31\u662f&#xff0c;\u6709\u4e9b\u516c\u5171\u6570\u636e\u4fee\u6539\u7684\u673a\u4f1a <\/span><\/p>\n<p><span style=\"color:#000000\">\u6bd4\u8f83\u5c11\u3002\u76f8\u6bd4\u8f83\u6539\u5199&#xff0c;\u5b83\u4eec\u8bfb\u7684\u673a\u4f1a\u53cd\u800c\u9ad8\u7684\u591a\u3002\u901a\u5e38\u800c\u8a00&#xff0c;\u5728\u8bfb\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u5f80\u5f80\u4f34 <\/span><\/p>\n<p><span style=\"color:#000000\">\u968f\u7740\u67e5\u627e\u7684\u64cd\u4f5c&#xff0c;\u4e2d\u95f4\u8017\u65f6\u5f88\u957f\u3002\u7ed9\u8fd9\u79cd\u4ee3\u7801\u6bb5\u52a0\u9501&#xff0c;\u4f1a\u6781\u5927\u5730\u964d\u4f4e\u6211\u4eec\u7a0b\u5e8f\u7684\u6548 <\/span><\/p>\n<p><span style=\"color:#000000\">\u7387\u3002\u90a3\u4e48\u6709\u6ca1\u6709\u4e00\u79cd\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u4e13\u95e8\u5904\u7406\u8fd9\u79cd\u591a\u8bfb\u5c11\u5199\u7684\u60c5\u51b5\u5462&#xff1f; <\/span><\/p>\n<p><span style=\"color:#000000\">\u6709&#xff0c;\u90a3\u5c31\u662f\u8bfb\u5199\u9501\u3002 <\/span><\/p>\n<h5>1.pthread_rwlockattr_setkind_np() \u2014\u2014 \u8bbe\u7f6e\u8bfb\u5199\u9501\u4f18\u5148\u7ea7<\/h5>\n<p>int pthread_rwlockattr_setkind_np(pthread_rwlockattr_t *attr, int pref);<\/p>\n<ul>\n<li><\/li>\n<li>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u8bbe\u7f6e\u8bfb\u5199\u9501\u7684\u4f18\u5148\u7ea7\u7b56\u7565&#xff08;\u8bfb\u8005\u4f18\u5148 \/ \u5199\u8005\u4f18\u5148&#xff09;&#xff0c;\u5c5e\u4e8e\u975e\u6807\u51c6\u6269\u5c55&#xff08;_np \u8868\u793a non-portable&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 attr<\/td>\n<td>\u8f93\u5165\u53c2\u6570&#xff1a;\u6307\u5411 pthread_rwlockattr_t \u7c7b\u578b\u7684\u5c5e\u6027\u5bf9\u8c61\u6307\u9488&#xff0c;\u7528\u4e8e\u5b58\u50a8\u4f18\u5148\u7ea7\u8bbe\u7f6e\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 pref<\/td>\n<td>\u8f93\u5165\u53c2\u6570&#xff1a;\u4f18\u5148\u7ea7\u9009\u9879&#xff0c;\u5171 3 \u79cd&#xff1a;- PTHREAD_RWLOCK_PREFER_READER_NP&#xff1a;\u9ed8\u8ba4&#xff0c;\u8bfb\u8005\u4f18\u5148&#xff0c;\u53ef\u80fd\u5bfc\u81f4\u5199\u8005\u9965\u997f- PTHREAD_RWLOCK_PREFER_WRITER_NP&#xff1a;\u5199\u8005\u4f18\u5148&#xff08;\u5b58\u5728 BUG&#xff0c;\u5b9e\u9645\u8868\u73b0\u4e0e\u8bfb\u8005\u4f18\u5148\u4e00\u81f4&#xff09;- PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP&#xff1a;\u5199\u8005\u4f18\u5148&#xff0c;\u4e14\u5199\u8005\u4e0d\u80fd\u9012\u5f52\u52a0\u9501<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 EINVAL \u8868\u793a\u53c2\u6570\u65e0\u6548&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u8be5\u63a5\u53e3\u4e3a\u975e\u6807\u51c6\u6269\u5c55&#xff0c;\u4e0d\u540c\u7cfb\u7edf\u5b9e\u73b0\u53ef\u80fd\u5b58\u5728\u5dee\u5f02&#xff1b;\u4f18\u5148\u7ea7\u7b56\u7565\u4f1a\u5f71\u54cd\u8bfb\u5199\u9501\u7684\u7ade\u4e89\u884c\u4e3a&#xff0c;\u9700\u8c28\u614e\u9009\u62e9\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/li>\n<\/ul>\n<h5>2. pthread_rwlock_init() \u2014\u2014 \u521d\u59cb\u5316\u8bfb\u5199\u9501<\/h5>\n<p>c<\/p>\n<p>\u8fd0\u884c<\/p>\n<p>int pthread_rwlock_init(pthread_rwlock_t *restrict rwlock, const pthread_rwlockattr_t *restrict attr);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u521d\u59cb\u5316\u8bfb\u5199\u9501&#xff0c;\u5fc5\u987b\u5728\u4f7f\u7528\u524d\u8c03\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 rwlock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411 pthread_rwlock_t \u7c7b\u578b\u7684\u8bfb\u5199\u9501\u6307\u9488&#xff0c;\u7528\u4e8e\u5b58\u50a8\u521d\u59cb\u5316\u540e\u7684\u9501\u72b6\u6001\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 attr<\/td>\n<td>\u8f93\u5165\u53c2\u6570&#xff1a;\u6307\u5411\u8bfb\u5199\u9501\u5c5e\u6027\u5bf9\u8c61\u7684\u6307\u9488&#xff1b;\u82e5\u4e3a NULL&#xff0c;\u5219\u4f7f\u7528\u9ed8\u8ba4\u5c5e\u6027&#xff08;\u8bfb\u8005\u4f18\u5148&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 ENOMEM \u8868\u793a\u5185\u5b58\u4e0d\u8db3&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u672a\u521d\u59cb\u5316\u7684\u8bfb\u5199\u9501\u4e0d\u80fd\u4f7f\u7528&#xff1b;\u540c\u4e00\u9501\u4e0d\u80fd\u91cd\u590d\u521d\u59cb\u5316\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h5>3. pthread_rwlock_destroy() \u2014\u2014 \u9500\u6bc1\u8bfb\u5199\u9501<\/h5>\n<p>int pthread_rwlock_destroy(pthread_rwlock_t *rwlock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u9500\u6bc1\u5df2\u521d\u59cb\u5316\u7684\u8bfb\u5199\u9501&#xff0c;\u91ca\u653e\u7cfb\u7edf\u8d44\u6e90\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 rwlock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u9500\u6bc1\u7684 pthread_rwlock_t \u7c7b\u578b\u7684\u8bfb\u5199\u9501\u6307\u9488\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 EBUSY \u8868\u793a\u9501\u4ecd\u88ab\u7ebf\u7a0b\u6301\u6709&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u4e0d\u80fd\u9500\u6bc1\u6b63\u5728\u88ab\u5176\u4ed6\u7ebf\u7a0b\u6301\u6709\u7684\u9501&#xff1b;\u9500\u6bc1\u540e\u4e0d\u80fd\u518d\u4f7f\u7528\u8be5\u9501&#xff0c;\u9664\u975e\u91cd\u65b0\u521d\u59cb\u5316\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h5>4. pthread_rwlock_rdlock() \u2014\u2014 \u83b7\u53d6\u8bfb\u9501&#xff08;\u5171\u4eab\u9501&#xff09;<\/h5>\n<p>int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u83b7\u53d6\u8bfb\u9501&#xff08;\u5171\u4eab\u9501&#xff09;&#xff0c;\u591a\u4e2a\u7ebf\u7a0b\u53ef\u540c\u65f6\u6301\u6709\u8bfb\u9501&#xff0c;\u5199\u9501\u4f1a\u88ab\u963b\u585e\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 rwlock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u83b7\u53d6\u8bfb\u9501\u7684 pthread_rwlock_t \u7c7b\u578b\u7684\u8bfb\u5199\u9501\u6307\u9488\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 EDEADLK \u68c0\u6d4b\u5230\u6b7b\u9501&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u8bfb\u9501\u662f\u5171\u4eab\u7684&#xff0c;\u9002\u5408\u8bfb\u591a\u5199\u5c11\u7684\u573a\u666f&#xff1b;\u6301\u6709\u8bfb\u9501\u65f6\u4e0d\u80fd\u518d\u83b7\u53d6\u5199\u9501&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u6b7b\u9501\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h5>5. pthread_rwlock_wrlock() \u2014\u2014 \u83b7\u53d6\u5199\u9501&#xff08;\u72ec\u5360\u9501&#xff09;<\/h5>\n<p>int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u83b7\u53d6\u5199\u9501&#xff08;\u72ec\u5360\u9501&#xff09;&#xff0c;\u5199\u9501\u6301\u6709\u671f\u95f4&#xff0c;\u6240\u6709\u8bfb\u9501\u548c\u5199\u9501\u8bf7\u6c42\u90fd\u4f1a\u88ab\u963b\u585e\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 rwlock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u83b7\u53d6\u5199\u9501\u7684 pthread_rwlock_t \u7c7b\u578b\u7684\u8bfb\u5199\u9501\u6307\u9488\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 EDEADLK \u68c0\u6d4b\u5230\u6b7b\u9501&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u5199\u9501\u662f\u72ec\u5360\u7684&#xff0c;\u6301\u6709\u5199\u9501\u65f6\u4e0d\u80fd\u518d\u83b7\u53d6\u8bfb\u9501\u6216\u5199\u9501&#xff0c;\u5426\u5219\u4f1a\u5bfc\u81f4\u6b7b\u9501&#xff1b;\u5199\u9501\u6301\u6709\u65f6\u95f4\u5e94\u5c3d\u91cf\u77ed\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h5 style=\"background-color:transparent\">6. pthread_rwlock_unlock() \u2014\u2014 \u91ca\u653e\u8bfb\u5199\u9501<\/h5>\n<\/p>\n<p>int pthread_rwlock_unlock(pthread_rwlock_t *rwlock);<\/p>\n<table>\n<tr>\u9879\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u529f\u80fd<\/td>\n<td>\u91ca\u653e\u8bfb\u9501\u6216\u5199\u9501&#xff0c;\u5fc5\u987b\u7531\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u8c03\u7528\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u53c2\u6570 rwlock<\/td>\n<td>\u8f93\u5165\u8f93\u51fa\u53c2\u6570&#xff1a;\u6307\u5411\u8981\u89e3\u9501\u7684 pthread_rwlock_t \u7c7b\u578b\u7684\u8bfb\u5199\u9501\u6307\u9488\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u8fd4\u56de\u503c<\/td>\n<td>\u6210\u529f\u8fd4\u56de 0&#xff1b;\u5931\u8d25\u8fd4\u56de\u975e 0 \u9519\u8bef\u7801&#xff08;\u5982 EPERM \u8868\u793a\u8c03\u7528\u7ebf\u7a0b\u4e0d\u6301\u6709\u8be5\u9501&#xff09;\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u6ce8\u610f<\/td>\n<td>\u672a\u6301\u6709\u9501\u7684\u7ebf\u7a0b\u8c03\u7528\u89e3\u9501\u4f1a\u5bfc\u81f4\u672a\u5b9a\u4e49\u884c\u4e3a&#xff08;\u5982\u7a0b\u5e8f\u5d29\u6e83&#xff09;&#xff1b;\u89e3\u9501\u540e\u5176\u4ed6\u7ebf\u7a0b\u53ef\u7ade\u4e89\u83b7\u53d6\u9501\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<p>#include &lt;iostream&gt;<br \/>\n#include &lt;pthread.h&gt;<br \/>\n#include &lt;unistd.h&gt;<br \/>\n#include &lt;vector&gt;<br \/>\n#include &lt;cstdlib&gt;<br \/>\n#include &lt;ctime&gt;<\/p>\n<p>\/\/ \u5171\u4eab\u8d44\u6e90<br \/>\nint shared_data &#061; 0;<\/p>\n<p>\/\/ \u8bfb\u5199\u9501<br \/>\npthread_rwlock_t rwlock;<\/p>\n<p>\/\/ \u8bfb\u8005\u7ebf\u7a0b\u51fd\u6570<br \/>\nvoid *Reader(void *arg)<br \/>\n{<br \/>\n    \/\/sleep(1); \/\/\u8bfb\u8005\u4f18\u5148&#xff0c;\u4e00\u65e6\u8bfb\u8005\u8fdb\u5165&amp;&amp;\u8bfb\u8005\u5f88\u591a&#xff0c;\u5199\u8005\u57fa\u672c\u5c31\u5f88\u96be\u8fdb\u5165\u4e86<br \/>\n    int number &#061; *(int *)arg;<br \/>\n    while (true)<br \/>\n    {<br \/>\n        pthread_rwlock_rdlock(&amp;rwlock); \/\/ \u8bfb\u8005\u52a0\u9501<br \/>\n        std::cout &lt;&lt; &#034;\u8bfb\u8005-&#034; &lt;&lt; number &lt;&lt; &#034; \u6b63\u5728\u8bfb\u53d6\u6570\u636e&#xff0c;\u6570\u636e\u662f: &#034; &lt;&lt; shared_data &lt;&lt; std::endl;<br \/>\n        sleep(1);                         \/\/ \u6a21\u62df\u8bfb\u53d6\u64cd\u4f5c<br \/>\n        pthread_rwlock_unlock(&amp;rwlock);   \/\/ \u89e3\u9501<br \/>\n    }<br \/>\n    delete (int*)arg;<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>\/\/ \u5199\u8005\u7ebf\u7a0b\u51fd\u6570<br \/>\nvoid *Writer(void *arg)<br \/>\n{<br \/>\n    int number &#061; *(int *)arg;<br \/>\n    while (true)<br \/>\n    {<br \/>\n        pthread_rwlock_wrlock(&amp;rwlock); \/\/ \u5199\u8005\u52a0\u9501<br \/>\n        shared_data &#061; rand() % 100;     \/\/ \u4fee\u6539\u5171\u4eab\u6570\u636e<br \/>\n        std::cout &lt;&lt; &#034;\u5199\u8005- &#034; &lt;&lt; number &lt;&lt; &#034; \u6b63\u5728\u5199\u5165\u3002\u65b0\u7684\u6570\u636e\u662f: &#034; &lt;&lt; shared_data &lt;&lt; std::endl;<br \/>\n        sleep(2);                         \/\/ \u6a21\u62df\u5199\u5165\u64cd\u4f5c<br \/>\n        pthread_rwlock_unlock(&amp;rwlock);   \/\/ \u89e3\u9501<br \/>\n    }<br \/>\n    delete (int*)arg;<br \/>\n    return NULL;<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n    srand(time(nullptr)^getpid());<br \/>\n    pthread_rwlock_init(&amp;rwlock, NULL); \/\/ \u521d\u59cb\u5316\u8bfb\u5199\u9501<\/p>\n<p>    \/\/ \u53ef\u4ee5\u66f4\u9ad8\u8bfb\u5199\u6570\u91cf\u914d\u6bd4&#xff0c;\u89c2\u5bdf\u73b0\u8c61<br \/>\n    const int reader_num &#061; 2;<br \/>\n    const int writer_num &#061; 2;<br \/>\n    const int total &#061; reader_num &#043; writer_num;<br \/>\n    pthread_t threads[total]; \/\/ \u5047\u8bbe\u8bfb\u8005\u548c\u5199\u8005\u6570\u91cf\u76f8\u7b49<\/p>\n<p>    \/\/ \u521b\u5efa\u8bfb\u8005\u7ebf\u7a0b<br \/>\n    for (int i &#061; 0; i &lt; reader_num; &#043;&#043;i)<br \/>\n    {<br \/>\n        int *id &#061; new int(i);<br \/>\n        pthread_create(&amp;threads[i], NULL, Reader, id);<br \/>\n    }<\/p>\n<p>    \/\/ \u521b\u5efa\u5199\u8005\u7ebf\u7a0b<br \/>\n    for (int i &#061; reader_num; i &lt; total; &#043;&#043;i)<br \/>\n    {<br \/>\n        int *id &#061; new int(i &#8211; reader_num);<br \/>\n        pthread_create(&amp;threads[i], NULL, Writer, id);<br \/>\n    }<\/p>\n<p>    \/\/ \u7b49\u5f85\u6240\u6709\u7ebf\u7a0b\u5b8c\u6210<br \/>\n    for (int i &#061; 0; i &lt; total; &#043;&#043;i)<br \/>\n    {<br \/>\n        pthread_join(threads[i], NULL);<br \/>\n    }<\/p>\n<p>    pthread_rwlock_destroy(&amp;rwlock); \/\/ \u9500\u6bc1\u8bfb\u5199\u9501<\/p>\n<p>    return 0;<br \/>\n}<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"652\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234926-69a0dc06e9442.png\" width=\"1106\" \/><\/p>\n<p><span style=\"color:#000000\">\u8bfb\u8005\u4f18\u5148&#xff08;<\/span><span style=\"color:#000000\">Reader-Preference<\/span><span style=\"color:#000000\">&#xff09; <\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u8fd9\u79cd\u7b56\u7565\u4e2d&#xff0c;\u7cfb\u7edf\u4f1a\u5c3d\u53ef\u80fd\u591a\u5730\u5141\u8bb8\u591a\u4e2a\u8bfb\u8005\u540c\u65f6\u8bbf\u95ee\u8d44\u6e90&#xff08;\u6bd4\u5982\u5171\u4eab\u6587\u4ef6\u6216\u6570 <\/span><\/p>\n<p><span style=\"color:#000000\">\u636e&#xff09;&#xff0c;\u800c\u4e0d\u4f1a\u4f18\u5148\u8003\u8651\u5199\u8005\u3002\u8fd9\u610f\u5473\u7740\u5f53\u6709\u8bfb\u8005\u6b63\u5728\u8bfb\u53d6\u65f6&#xff0c;\u65b0\u5230\u8fbe\u7684\u8bfb\u8005\u4f1a\u7acb\u5373\u88ab <\/span><\/p>\n<p><span style=\"color:#000000\">\u5141\u8bb8\u8fdb\u5165\u8bfb\u53d6\u533a&#xff0c;\u800c\u5199\u8005\u5219\u4f1a\u88ab\u963b\u585e&#xff0c;\u76f4\u5230\u6240\u6709\u8bfb\u8005\u90fd\u79bb\u5f00\u8bfb\u53d6\u533a\u3002\u8bfb\u8005\u4f18\u5148\u7b56\u7565\u53ef <\/span><\/p>\n<p><span style=\"color:#000000\">\u80fd\u4f1a\u5bfc\u81f4\u5199\u8005\u9965\u997f&#xff08;\u5373\u5199\u8005\u957f\u65f6\u95f4\u65e0\u6cd5\u83b7\u5f97\u5199\u5165\u6743\u9650&#xff09;&#xff0c;\u7279\u522b\u662f\u5f53\u8bfb\u8005\u9891\u7e41\u5230\u8fbe\u65f6\u3002 <\/span><\/p>\n<p><span style=\"color:#000000\">\u5199\u8005\u4f18\u5148&#xff08;<\/span><span style=\"color:#000000\">Writer-Preference<\/span><span style=\"color:#000000\">&#xff09; <\/span><\/p>\n<p><span style=\"color:#000000\">\u5728\u8fd9\u79cd\u7b56\u7565\u4e2d&#xff0c;\u7cfb\u7edf\u4f1a\u4f18\u5148\u8003\u8651\u5199\u8005\u3002\u5f53\u5199\u8005\u8bf7\u6c42\u5199\u5165\u6743\u9650\u65f6&#xff0c;\u7cfb\u7edf\u4f1a\u5c3d\u5feb\u5730\u8ba9\u5199\u8005 <\/span><\/p>\n<p><span style=\"color:#000000\">\u8fdb\u5165\u5199\u5165\u533a&#xff0c;\u5373\u4f7f\u6b64\u65f6\u6709\u8bfb\u8005\u6b63\u5728\u8bfb\u53d6\u3002\u8fd9\u901a\u5e38\u610f\u5473\u7740\u4e00\u65e6\u6709\u5199\u8005\u5230\u8fbe&#xff0c;\u6240\u6709\u540e\u7eed\u7684 <\/span><\/p>\n<p><span style=\"color:#000000\">\u8bfb\u8005\u90fd\u4f1a\u88ab\u963b\u585e&#xff0c;\u76f4\u5230\u5199\u8005\u5b8c\u6210\u5199\u5165\u5e76\u79bb\u5f00\u5199\u5165\u533a\u3002\u5199\u8005\u4f18\u5148\u7b56\u7565\u53ef\u4ee5\u51cf\u5c11\u5199\u8005\u7b49\u5f85 <\/span><\/p>\n<p><span style=\"color:#000000\">\u7684\u65f6\u95f4&#xff0c;\u4f46\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8bfb\u8005\u9965\u997f&#xff08;\u5373\u8bfb\u8005\u957f\u65f6\u95f4\u65e0\u6cd5\u83b7\u5f97\u8bfb\u53d6\u6743\u9650&#xff09;&#xff0c;\u7279\u522b\u662f\u5f53\u5199\u8005 <\/span><\/p>\n<p><span style=\"color:#000000\">\u9891\u7e41\u5230\u8fbe\u65f6\u3002 <\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>netstat netstat \u662f\u4e00\u4e2a\u7528\u6765\u67e5\u770b\u7f51\u7edc\u72b6\u6001\u7684\u91cd\u8981\u5de5\u5177. \u8bed\u6cd5&#xff1a;netstat [\u9009\u9879] \u529f\u80fd&#xff1a;\u67e5\u770b\u7f51\u7edc\u72b6\u6001 \u5e38\u7528\u9009\u9879&#xff1a; \u2022 n \u62d2\u7edd\u663e\u793a\u522b\u540d&#xff0c;\u80fd\u663e\u793a\u6570\u5b57\u7684\u5168\u90e8\u8f6c\u5316\u6210\u6570\u5b57 \u2022 l \u4ec5\u5217\u51fa\u6709\u5728 Listen (\u76d1\u542c) \u7684\u670d\u52d9\u72b6\u6001 \u2022 p \u663e\u793a\u5efa\u7acb\u76f8\u5173\u94fe\u63a5\u7684\u7a0b\u5e8f\u540d \u2022 t (tcp)\u4ec5\u663e\u793a tcp \u76f8\u5173\u9009\u9879 \u2022 u (udp)\u4ec5\u663e\u793a udp \u76f8\u5173\u9009\u9879 \u2022 a (all)\u663e\u793a\u6240\u6709\u9009\u9879&#xff0c;\u9ed8\u8ba4\u4e0d\u663e\u793a LIS<\/p>\n","protected":false},"author":2,"featured_media":78338,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[58,78],"topic":[],"class_list":["post-78344","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-linux","tag-78"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Linux \u7f51\u7edc (7) - \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\/78344.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Linux \u7f51\u7edc (7) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"netstat netstat \u662f\u4e00\u4e2a\u7528\u6765\u67e5\u770b\u7f51\u7edc\u72b6\u6001\u7684\u91cd\u8981\u5de5\u5177. \u8bed\u6cd5&#xff1a;netstat [\u9009\u9879] \u529f\u80fd&#xff1a;\u67e5\u770b\u7f51\u7edc\u72b6\u6001 \u5e38\u7528\u9009\u9879&#xff1a; \u2022 n \u62d2\u7edd\u663e\u793a\u522b\u540d&#xff0c;\u80fd\u663e\u793a\u6570\u5b57\u7684\u5168\u90e8\u8f6c\u5316\u6210\u6570\u5b57 \u2022 l \u4ec5\u5217\u51fa\u6709\u5728 Listen (\u76d1\u542c) \u7684\u670d\u52d9\u72b6\u6001 \u2022 p \u663e\u793a\u5efa\u7acb\u76f8\u5173\u94fe\u63a5\u7684\u7a0b\u5e8f\u540d \u2022 t (tcp)\u4ec5\u663e\u793a tcp \u76f8\u5173\u9009\u9879 \u2022 u (udp)\u4ec5\u663e\u793a udp \u76f8\u5173\u9009\u9879 \u2022 a (all)\u663e\u793a\u6240\u6709\u9009\u9879&#xff0c;\u9ed8\u8ba4\u4e0d\u663e\u793a LIS\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78344.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-26T23:49:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234924-69a0dc04b39fb.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=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78344.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78344.html\",\"name\":\"Linux \u7f51\u7edc (7) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-26T23:49:28+00:00\",\"dateModified\":\"2026-02-26T23:49:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78344.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78344.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78344.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux \u7f51\u7edc (7)\"}]},{\"@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 \u7f51\u7edc (7) - \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\/78344.html","og_locale":"zh_CN","og_type":"article","og_title":"Linux \u7f51\u7edc (7) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"netstat netstat \u662f\u4e00\u4e2a\u7528\u6765\u67e5\u770b\u7f51\u7edc\u72b6\u6001\u7684\u91cd\u8981\u5de5\u5177. \u8bed\u6cd5&#xff1a;netstat [\u9009\u9879] \u529f\u80fd&#xff1a;\u67e5\u770b\u7f51\u7edc\u72b6\u6001 \u5e38\u7528\u9009\u9879&#xff1a; \u2022 n \u62d2\u7edd\u663e\u793a\u522b\u540d&#xff0c;\u80fd\u663e\u793a\u6570\u5b57\u7684\u5168\u90e8\u8f6c\u5316\u6210\u6570\u5b57 \u2022 l \u4ec5\u5217\u51fa\u6709\u5728 Listen (\u76d1\u542c) \u7684\u670d\u52d9\u72b6\u6001 \u2022 p \u663e\u793a\u5efa\u7acb\u76f8\u5173\u94fe\u63a5\u7684\u7a0b\u5e8f\u540d \u2022 t (tcp)\u4ec5\u663e\u793a tcp \u76f8\u5173\u9009\u9879 \u2022 u (udp)\u4ec5\u663e\u793a udp \u76f8\u5173\u9009\u9879 \u2022 a (all)\u663e\u793a\u6240\u6709\u9009\u9879&#xff0c;\u9ed8\u8ba4\u4e0d\u663e\u793a LIS","og_url":"https:\/\/www.wsisp.com\/helps\/78344.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-26T23:49:28+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/02\/20260226234924-69a0dc04b39fb.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78344.html","url":"https:\/\/www.wsisp.com\/helps\/78344.html","name":"Linux \u7f51\u7edc (7) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-26T23:49:28+00:00","dateModified":"2026-02-26T23:49:28+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78344.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78344.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78344.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Linux \u7f51\u7edc (7)"}]},{"@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\/78344","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=78344"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78344\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/78338"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78344"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}