{"id":282861,"date":"2023-09-18T04:03:39","date_gmt":"2023-09-17T20:03:39","guid":{"rendered":"https:\/\/lrxjmw.cn\/lnhsjysxjcgl.html"},"modified":"2023-09-18T04:03:39","modified_gmt":"2023-09-17T20:03:39","slug":"lnhsjysxjcgl","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lnhsjysxjcgl.html","title":{"rendered":"Linux\u5185\u6838\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u8fdb\u7a0b\u7ba1\u7406\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u548c\u4efb\u52a1"},"content":{"rendered":"

linux\u5185\u6838\u4fe1\u53f7\u91cf\u662f\u4ec0\u4e48_linux\u4fe1\u53f7\u548c\u4fe1\u53f7\u91cf\u533a\u522b_linux\u5185\u6838\u4fe1\u53f7\u91cf<\/p>\n

linux\u5185\u6838\u4fe1\u53f7\u91cf\u662f\u4ec0\u4e48_linux\u4fe1\u53f7\u548c\u4fe1\u53f7\u91cf\u533a\u522b_linux\u5185\u6838\u4fe1\u53f7\u91cf<\/p>\n

linux\u5185\u6838\u4fe1\u53f7\u91cf\u662f\u4ec0\u4e48_linux\u4fe1\u53f7\u548c\u4fe1\u53f7\u91cf\u533a\u522b_linux\u5185\u6838\u4fe1\u53f7\u91cf<\/p>\n

Linux<\/a>\u5185\u6838\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u2014>\u8fdb\u7a0b\u7ba1\u7406<\/p>\n

\u8fdb\u7a0b\u63cf\u8ff0\u7b26\u548c\u4efb\u52a1\u7ed3\u6784<\/p>\n

\u8fdb\u7a0b\u95f4\u901a\u8baf<\/p>\n

1.\u7ba1\u7ebf\uff1a<\/p>\n

1.\u6709\u540d\u7ba1\u7ebf<\/p>\n

\u7279\u70b9<\/p>\n

\u7279\u6027\uff1a1\u3001\u53ef\u4ee5\u7528\u4e8e\u4e0d\u540c\u8fdb\u7a0b\u95f4\u901a\u8baf\uff0c\u4e0d\u9650\u4e8e\u5fc5\u987b\u6709\u4eb2\u7f18\u5173\u7cfb\u3002<\/p>\n

\u6709\u540d\u7ba1\u7ebf\u7684\u4f7f\u7528<\/p>\n

1\u3001\u7ba1\u9053\u7684\u521b\u5efa=====\u300bmkfifo<\/p>\n

intmkfifo(constchar*filename,mode_tmode);<\/p>\n

\u529f\u80fd\uff1a\u901a\u8fc7\u8be5\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6709\u540d\u7ba1\u7ebf\u7684\u8bbe\u5907\u6587\u4ef6\u4e0b\u6765\u3002<\/p>\n

\u53c2\u6570\uff1afilename\u8981\u521b\u5efa\u7684\u7ba1\u7ebf\u540d\u79f0+\u8def\u5f84mode\u521b\u5efa\u7684\u7ba1\u7ebf\u7684\u6587\u4ef6\u6743\u9650\u3002<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\uff1b<\/p>\n

2\u3001\u7ba1\u9053\u7684\u6253\u5f00=====\u300bopen<\/p>\n

intopen(constchar*filename,intflag);<\/p>\n

\u53c2\u6570\uff1afilename\u8981\u6253\u5f00\u7684\u6709\u540d\u7ba1\u7ebf\u6587\u4ef6\u540d\u79f0<\/p>\n

flag==\u300bO_RDONLY\u53ea\u8bfbO_WRONLY\u53ea\u5199O_RDWR\u4e0d\u80fd\u7528\u3002<\/p>\n

3\u3001\u7ba1\u9053\u7684\u8bfb\u5199====>readwrite<\/p>\n

\u8bfb\uff1assize_tread(intfd,void*buff,size_tcount);<\/p>\n

\u4ecefd\u4e2d\u8bfbcount\u4e2a\u5b57\u8282\u7684\u6570\u636e\u5230buff\u4e2d\u3002<\/p>\n

\u5199\uff1assize_twrite(intfd,constvoid*buff,size_tcount)<\/p>\n

\u4ecebuff\u4e2d\u53d6count\u4e2a\u5b57\u8282\u7684\u6570\u636e\u5199\u5165\u5230fd\u6587\u4ef6\u4e2d\u3002<\/p>\n

4\u3001\u7ba1\u9053\u7684\u5173\u6389====>close<\/p>\n

close\uff08fd\uff09\uff1b<\/p>\n

5\u3001\u7ba1\u9053\u7684\u5378\u8f7d====>unlinkintunlink(constchar*pathname);<\/p>\n

\u529f\u80fd\uff1a\u5378\u8f7d\u6216\u5219\u5220\u6389\u65e9\u5df2\u521b\u5efa\u7684\u6709\u540d\u7ba1\u7ebf\u6587\u4ef6<\/p>\n

\u53c2\u6570\uff1apathname\u8981\u5378\u8f7d\u7684\u7ba1\u7ebf\u6587\u4ef6\u540d\u79f0+\u8def\u5f84<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\uff1b<\/p>\n

2.\u65e0\u540d\u7ba1\u7ebf<\/p>\n

\u7279\u70b9<\/p>\n

1\u3001\u53ea\u80fd\u7528\u4e8e\u5177\u6709\u4eb2\u7f18\u5173\u7cfb\u7684\u8fdb\u7a0b\u95f4\u4f7f\u7528\u3002<\/p>\n

2\u3001\u534a\u53cc\u5de5\u901a\u8bafqq linux\uff0c\u6709\u56fa\u5b9a\u7684\u8bfb\u7aef\u548c\u5199\u7aef\u3002<\/p>\n

3\u3001\u7279\u6b8a\u7684\u7cfb\u7edf<\/a>\u6587\u4ef6\uff0c\u53ef\u4ee5\u652f\u6301\u6587\u4ef6IO\u3002<\/p>\n

4\u3001\u7ba1\u9053\u7684\u6570\u636e\u50a8\u5b58\u65b9\u6cd5\u7c7b\u4f3c\u961f\u5217linux\u5185\u6838\u4fe1\u53f7\u91cf<\/strong>\uff0c\u5148\u8fdb\u5148\u51fa\u3002<\/p>\n

5\u3001\u7ba1\u9053\u7684\u9ed8\u8ba4\u5bb9\u91cf\u5927\u5c0f\u662f64k\u5b57\u8282===\u300bulimit-a====>4k\u521d\u671f\u7684\u5927\u5c0f<\/p>\n

6\u3001\u7ba1\u9053\u9ed8\u8ba4\u7684\u8bfb\u64cd\u4f5c\u4f1a\u963b\u585e\u7b49\u5f85\uff0c\u5047\u5982\u5199\u64cd\u4f5c\u6ee1\u4e86\u7684\u65f6\u4faf\u4e5f\u4f1a\u963b\u585e\u7b49\u5f85\u3002<\/p>\n

7\u3001\u7ba1\u9053\u7684\u8bfb\u7aef\u5b58\u5728\u65f6\u4faf\uff0c\u5199\u7ba1\u7ebf\u624d\u6709\u610f\u4e49\uff0c\u5426\u5219\u7a0b\u5e8f\u4f1a\u9000\u51fa.<\/p>\n

\u65e0\u540d\u7ba1\u7ebf\u7684\u4f7f\u7528<\/p>\n

1\u3001\u7ba1\u9053\u7684\u521b\u5efa\u4e0e\u6253\u5f00intpipe(intfd[2]);<\/p>\n

\u529f\u80fd\uff1a\u901a\u8fc7\u8be5\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u65e0\u540d\u7ba1\u7ebf\uff0c\u540c\u65f6\u6253\u5f00\u8be5\u7ba1\u7ebf\u3002<\/p>\n

\u53c2\u6570\uff1afd[2]\u8981\u64cd\u4f5c\u7684\u7ba1\u7ebf\u540d\u79f0\uff0c\u6709\u4e24\u4e2a\u5143\u7d20fd[0]\u7ba1\u7ebf\u7684\u56fa\u5b9a\u7684\u8bfb\u7aeffd[1]\u7ba1\u7ebf\u7684\u56fa\u5b9a\u7684\u5199\u7aef<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\u6ce8\u610f\uff1a\u5728\u521b\u5efa\u65b0\u7684\u8fdb\u7a0b\u4e4b\u524d\u5c31\u5e94\u5f53\u5148\u521b\u5efa\u7ba1\u7ebf\uff0c\u7136\u540e\u4e4b\u95f4\u7684\u8d44\u6e90\u53ef\u4ee5\u901a\u8fc7\u7ba1\u7ebf\u4f20\u9012\u3002<\/p>\n

2\u3001\u7ba1\u9053\u7684\u8bfb\u5199<\/p>\n

\u8bfb\uff1assize_tread(intfd,void*buff,size_tcount);<\/p>\n

\u4ecefd\u4e2d\u8bfbcount\u4e2a\u5b57\u8282\u7684\u6570\u636e\u5230buff\u4e2d\u3002<\/p>\n

\u5199\uff1assize_twrite(intfd,constvoid*buff,size_tcount)<\/p>\n

\u4ecebuff\u4e2d\u53d6count\u4e2a\u5b57\u8282\u7684\u6570\u636e\u5199\u5165\u5230fd\u6587\u4ef6\u4e2d\u3002<\/p>\n

3\u3001\u7ba1\u9053\u7684\u5173\u6389<\/p>\n

close\uff08fd[0]\uff09\uff1b<\/p>\n

close(fd[1]);<\/p>\n

2.\u8baf\u53f7\uff1a<\/p>\n

1.\u8baf\u53f7\u7684\u53d1\u9001<\/p>\n

kill\u51fd\u6570=====\u300b\u652f\u6301\u7684\u8baf\u53f7\u5217\u8868kill-l====>\u6240\u6709\u5f53\u524d\u7cfb\u7edf\u652f\u6301\u7684\u9ed8\u8ba4\u8baf\u53f7<\/p>\n

\u5934\u6587\u4ef6\uff1asignal.hsys\/types.h<\/p>\n

intkill(pid_tpid,intsig);<\/p>\n

\u529f\u80fd\uff1a\u7ed9\u6307\u5b9a\u7684pid\u8fdb\u7a0b\u53d1\u9001sig\u8baf\u53f7\u3002<\/p>\n

\u53c2\u6570\uff1apid\u8981\u63a5\u6536\u8baf\u53f7\u7684\u8fdb\u7a0bidsig\u8981\u53d1\u9001\u7684\u8baf\u53f7\u7f16\u53f7====\u300bkill-l\u4e2d\u7684\u8baf\u53f7kill-l\u4e2d\u524d32\u5c5e\u4e8e\u7cfb\u7edf\u539f\u59cb\u8baf\u53f7\uff0c\u4e5f\u53eb\u4e0d\u7a33\u5b9a\u8baf\u53f7\u540e32\u4e2a\u5c5e\u4e8e\u7a33\u5b9a\u8baf\u53f7\u3002<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\uff1b<\/p>\n

intraise(intsig);<\/p>\n

\u529f\u80fd\uff1a\u8fdb\u7a0b\u53ef\u4ee5\u81ea\u5df1\u901a\u8fc7\u8be5\u51fd\u6570\u7ed9\u81ea\u5df1\u53d1\u9001\u8baf\u53f7\u3002<\/p>\n

\u53c2\u6570\uff1asig\u8981\u53d1\u7684\u8baf\u53f7\u7684\u7f16\u53f7<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\uff1b<\/p>\n

\u95f9\u94c3\u51fd\u6570\u548c\u6682\u505c\u51fd\u6570<\/p>\n

\u6682\u505c\u51fd\u6570<\/p>\n

intpause(void)====>while(1){sleep(1);}<\/p>\n

\u6267\u884c\u8be5\u51fd\u6570\u540e\u7a0b\u5e8f\u6682\u505c\u3002<\/p>\n

\u95f9\u94c3\u51fd\u6570<\/p>\n

\u5b9a\u65f6\u65f6\u95f4\u5230\u4e86\u53d1\u9001SIGALRM\u8baf\u53f7\u7ed9\u81ea\u5df1\u3002<\/p>\n

unsignedintalarm(unisgnedintsec);<\/p>\n

\u6307\u5b9a\u95f4\u9694sec\u79d2\u4ee5\u540e\u7ed9\u81ea\u5df1\u53d1\u9001\u8baf\u53f7\u3002<\/p>\n

\u9ed8\u8ba4\u7684SIGALRM\u8baf\u53f7\u4f1a\u4f7f\u7a0b\u5e8f\u4e2d\u6b62\u8fd0\u884c\u3002<\/p>\n

2.\u8baf\u53f7\u7684\u63a5\u6536<\/p>\n

\u4e09\u79cd\u5f62\u5f0f\uff1a\u9ed8\u8ba4\u5904\u7406\u5ffd\u89c6\u5904\u7406\u81ea\u5b9a\u4e49\u5904\u7406<\/p>\n

1\u3001\u6355\u83b7\u8baf\u53f7\u548c\u5904\u7406<\/p>\n

void()(int);======>voidfun(intarg);<\/p>\n

void(signal(intsignum,void(handler)(int)))(int);<\/p>\n

signal(intsignum,test);===>test==void(handler)(int);typedefvoid(SIGNAL)(int);===>void(signal(intsignum,void(handler)(int)))(int);==SIGNALsignal(intsingnum,SIGNALhandler);<\/p>\n

\u7b80\u5316\u6210\uff1a<\/p>\n

#include<\/p>\n

typedefvoid(*sighandler_t)(int);<\/p>\n

sighandler_tsignal(intsignum,sighandler_thandler);<\/p>\n

\u53c2\u6570\uff1a<\/p>\n

sig\u8981\u5904\u7406\u7684\u8baf\u53f7<\/p>\n

fun\u8baf\u53f7\u7684\u5904\u7406\u51fd\u6570\u3002<\/p>\n

\u5047\u5982\u5176\u662f\uff1a<\/p>\n

\u200bSIG_IGN\u8868\u793a\u8be5\u7a0b\u5e8f\u5bf9\u6240\u6709\u7684\u8baf\u53f7\u505a\u5ffd\u89c6\u5904\u7406\u3002<\/p>\n

\u200bSIG_DFL\u8868\u793a\u8be5\u7a0b\u5e8f\u5bf9\u6240\u6709\u7684\u8baf\u53f7\u505a\u9ed8\u8ba4\u5904\u7406,\u7cfb\u7edf\u5bf9\u8fd9\u79cd\u8baf\u53f7\u662f\u5982\u4f55\u5904\u7406\u7684linux\u5185\u6838\u4fe1\u53f7\u91cf<\/strong>\uff0c\u7a0b\u5e8f\u90fd\u4f1a\u5bf9\u8be5\u8baf\u53f7\u5982\u4f55\u5904\u7406\u3002<\/p>\n

\u200bfun\u8868\u793a\u6539\u7a0b\u5e8f\u6709\u4e00\u4e2a\u53cd\u5f39\u51fd\u6570\u7528\u6765\u81ea\u5b9a\u4e49\u5904\u7406\u3002<\/p>\n

\u51fd\u6570\u53ef\u4ee5\u63a5\u6536\u8baf\u53f7\uff0c\u5e76\u5bf9\u8baf\u53f7\u4f5c\u51fa\u5904\u7406\uff0c\u4e09\u79cd\u5904\u7406\u65b9\u6cd5\u3002<\/p>\n

\u5ffd\u89c6\u3002<\/p>\n

\u9ed8\u8ba4\u5904\u7406\uff1a<\/p>\n

\u81ea\u5b9a\u4e49\u5904\u7406\uff1a\u63a5\u6536\u5230\u8be5\u8baf\u53f7\u4ee5\u540e\uff0c\u4f1a\u8c03\u7528\u81ea\u5b9a\u4e49\u7684\u53cd\u5f39\u51fd\u6570\u3002<\/p>\n

\u6ce8\u610f\uff1a\u5728\u6240\u6709\u7cfb\u7edf\u9884\u5236\u7684\u8baf\u53f7\u5217\u8868\u4e2dlinux\u7cfb\u7edf\u4ecb\u7ecd\uff0c9\u53f7SIGKILL\u548c19\u53f7\u7684SIGSTOP\u8baf\u53f7\u4e0d\u80fd\u88ab\u5ffd\u89c6\u5904\u7406\u3002<\/p>\n

\u4e8b\u4f8b\uff1a<\/p>\n

\/\/SIGABRT\u8fdb\u7a0b\u505c\u6b62\u8fd0\u884c6<\/p>\n

\/\/SIGINT\u7ec8\u7aef\u4e2d\u65ad2<\/p>\n

\/\/SIGKILL\u505c\u6b62\u8fdb\u7a0b(\u6b64\u8baf\u53f7\u4e0d\u80fd\u88ab\u5ffd\u89c6\u6216\u6355\u83b7)<\/p>\n

\/\/SIGQUIT\u7ec8\u7aef\u9000\u51fa3<\/p>\n

voidhandler(intnum)<\/p>\n

printf(\"recvnum:%dn\",num);<\/p>\n

linux\u5185\u6838\u4fe1\u53f7\u91cf\u662f\u4ec0\u4e48_linux\u5185\u6838\u4fe1\u53f7\u91cf_linux\u4fe1\u53f7\u548c\u4fe1\u53f7\u91cf\u533a\u522b<\/p>\n

if(num==SIGQUIT)<\/p>\n

\/\/exit(0);<\/p>\n

intmain()<\/p>\n

if(signal(SIGINT,handler)==SIG_ERR)<\/p>\n

perror(\"signalerr\");\/\/errno<\/p>\n

exit(0);<\/p>\n

3.\u8baf\u53f7\u5728\u8fdb\u7a0b\u95f4\u901a\u8baf\u4e2d\u7684\u7f3a\u9677\uff1a<\/p>\n

1\u3001\u4e0d\u80fd\u53d1\u9001\u5927\u91cf\u6570\u636e\uff0c\u5305\u62ec\u5b57\u7b26\u4e32\u3002<\/p>\n

2\u3001\u53d1\u9001\u7684\u8baf\u53f7\u5fc5\u987b\u662f\u53cc\u65b9\u7ea6\u5b9a\u597d\u7684\u3002<\/p>\n

3\u3001\u53d1\u9001\u7684\u8baf\u53f7\u5fc5\u987b\u662f\u7cfb\u7edf\u9884\u5236\u7684\u8303\u56f4\u5185\u7684\u3002<\/p>\n

4\u3001\u53d1\u9001\u7684\u8baf\u53f7\u5728\u63a5\u6536\u65b9\u5fc5\u987b\u6709\u81ea\u5b9a\u4e49\u5904\u7406\uff0c\u901a\u5e38\u7528SIGUSR1SIGUSER2.\u5176\u4ed6\u8baf\u53f7\u6709\u7cfb\u7edf\u6db5\u4e49\u5efa\u8bae\u4e0d\u8981\u4f7f\u7528\u3002<\/p>\n

4.\u8baf\u53f7\u548c\u4e2d\u65ad\u7684\u533a\u522b<\/p>\n

\u8baf\u53f7\u662f\u5728\u8f6f\u4ef6\u5c42\u6b21\u4e0a\u5bf9\u4e2d\u65ad\u7684\u4e00\u79cd\u6a21\u62df\uff0c\u6240\u4ee5\u4e00\u822c\u628a\u5b83\u79f0\u4e3a\u662f\u8f6f\u4e2d\u65ad<\/p>\n

\u8baf\u53f7\u4e0e\u4e2d\u65ad\u7684\u76f8\u50cf\u70b9\uff1a<\/p>\n

\uff081\uff09\u91c7\u7528\u4e86\u76f8\u540c\u7684\u5f02\u6b65\u901a\u8baf\u65b9\u6cd5\uff1b<\/p>\n

\uff082\uff09\u5f53\u68c0\u67e5\u51fa\u6709\u8baf\u53f7\u6216\u4e2d\u65ad\u6073\u6c42\u65f6\uff0c\u90fd\u6682\u505c\u6b63\u5728\u6267\u884c\u7684\u7a0b\u5e8f\u800c\u8f6c\u53bb\u6267\u884c\u76f8\u5e94\u7684\u5904\u7406\u7a0b\u5e8f\uff1b<\/p>\n

\uff083\uff09\u90fd\u5728\u5904\u7406\u5b8c\u6bd5\u540e\u8fd4\u56de\u5230\u539f\u5148\u7684\u65ad\u70b9\uff1b<\/p>\n

\uff084\uff09\u5bf9\u8baf\u53f7\u6216\u4e2d\u65ad\u90fd\u53ef\u8fdb\u884c\u5c4f\u853d\u3002<\/p>\n

\u8baf\u53f7\u4e0e\u4e2d\u65ad\u7684\u533a\u522b\uff1a<\/p>\n

\uff081\uff09\u4e2d\u65ad\u6709\u4f18\u5148\u7ea7\uff0c\u800c\u8baf\u53f7\u6ca1\u6709\u4f18\u5148\u7ea7\uff0c\u6240\u6709\u7684\u8baf\u53f7\u90fd\u662f\u5e73\u7b49\u7684\uff1b<\/p>\n

\uff082\uff09\u8baf\u53f7\u5904\u7406\u7a0b\u5e8f\u662f\u5728\u7528\u6237\u6001\u4e0b\u8fd0\u884c\u7684\uff0c\u800c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u5728\u6838\u6001\u5ea6\u4e0b\u8fd0\u884c\uff1b<\/p>\n

\uff083\uff09\u4e2d\u65ad\u54cd\u5e94\u662f\u53ca\u65f6\u7684\uff0c\u800c\u8baf\u53f7\u54cd\u5e94\u4e00\u822c\u90fd\u6709\u8f83\u5927\u7684\u65f6\u95f4\u5ef6\u540e\u3002<\/p>\n

3.IPC\u5bf9\u8c61<\/p>\n

0.\u57fa\u672c\u6982\u5ff5<\/p>\n

IPC\u5bf9\u8c61\u5305\u542b\u4e86\uff1a\u5171\u4eab\u663e\u5b58\u3001\u4fe1\u53f7\u91cf\u3001\u6d88\u606f\u961f\u5217<\/a><\/p>\n

1\u3001ipc\u5bf9\u8c61\u67e5\u770b\u547d\u4ee4<\/a><\/p>\n

ipcs-a====>\u67e5\u770b\u5bf9\u8c61\u4fe1\u606f<\/p>\n

\u200bipcs-q====>\u53ea\u67e5\u770b\u6d88\u606f\u961f\u5217\u7684\u5bf9\u8c61\u4fe1\u606f<\/p>\n

\u200bipcs-m====>\u53ea\u67e5\u770b\u5171\u4eab\u663e\u5b58\u7684\u5bf9\u8c61\u4fe1\u606f<\/p>\n

\u200bipcs-s====>\u53ea\u67e5\u770b\u8baf\u53f7\u91cf\u7684\u5bf9\u8c61\u4fe1\u606f<\/p>\n

2\u3001ipc\u5bf9\u8c61\u64cd\u4f5c\u547d\u4ee4<\/p>\n

\u200bipcs-lipcs-lqipcs-lmipcs-ls===>\u67e5\u770b\u5bf9\u8c61\u7684\u9ed8\u8ba4\u4e0a\u9650\u503c<\/p>\n

\u200bipcrm===>\u5220\u6389\u547d\u4ee4===\u300bipcrm-qmsgid====>\u5220\u6389\u6d88\u606f\u961f\u5217\u652f\u961f\u5217id\u662fmsgid\u7684\u5bf9\u8c61<\/p>\n

\u200bipcrm-mshmid====>\u5171\u4eab\u663e\u5b58\u5bf9\u8c61\u5220\u6389<\/p>\n

linux\u4fe1\u53f7\u548c\u4fe1\u53f7\u91cf\u533a\u522b_linux\u5185\u6838\u4fe1\u53f7\u91cf\u662f\u4ec0\u4e48_linux\u5185\u6838\u4fe1\u53f7\u91cf<\/p>\n

\u200bipcrm-ssemid====>\u8baf\u53f7\u91cf\u96c6\u5bf9\u8c61\u5220\u6389<\/p>\n

3\u3001\u57fa\u672c\u64cd\u4f5c\u6d41\u7a0b\uff1a<\/p>\n

\u200bkey>\u7533\u8bf7\u6216\u5219\u521b\u5efaIPC\u5bf9\u8c61>\u8bfb\u5199\u6570\u636e====>\u5378\u8f7d\u5bf9\u8c61<\/p>\n

1.key\u7684\u83b7\u53d6<\/p>\n

1\u3001\u79c1\u6709key=====>IPC_PRIVATE===0X00000000<\/p>\n

2\u3001\u6d4b\u8bd5key=====>ftok()====>\u6307\u5b9a\u8def\u5f84+\u5b57\u7b26<\/p>\n

3\u3001\u81ea\u5b9a\u4e49key====>0X12345678<\/p>\n

key_tftok(constchar*pathname,intpro_id);<\/p>\n

\u529f\u80fd\uff1a\u901a\u8fc7\u8be5\u51fd\u6570\u53ef\u4ee5\u4ee5\u6307\u5b9a\u7684\u8def\u5f84\u4e3a\u57fa\u672c\u751f\u6210\u4e00\u4e2a\u60df\u4e00\u901a\u914d\u7b26\u3002<\/p>\n

\u53c2\u6570\uff1apathname\u4efb\u610f\u6307\u5b9a\u4e00\u4e2a\u4e0d\u53ef\u5378\u8f7d\u7684\u76ee\u5f55\u540c\u65f6\u8981\u6c42\u6539\u76ee\u5f55\u4e0d\u80fd\u88ab\u5220\u6389\u91cd\u5efa\u3002<\/p>\n

pro_id\u4e00\u4e2a\u6570\u5b57\uff0c\u6216\u5219\u5b57\u7b26\uff0c\u8868\u793a\u5c06\u8be5\u503c\u4e0e\u53c2\u65701\u505a\u8fd0\u7b97\u4ee5\u540e\u7684\u503c\u4f5c\u4e3a\u901a\u914d\u7b26\u3002<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f\u8fd4\u56de\u60df\u4e00\u901a\u914d\u7b26\uff0c\u5931\u8d25-1\uff1b<\/p>\n

2.\u6d88\u606f\u961f\u5217<\/p>\n

0\u3001\u5934\u6587\u4ef6\uff1a<\/p>\n

#include<\/p>\n

#include<\/p>\n

#include<\/p>\n

1\u3001\u7533\u8bf7\u6d88\u606f\u961f\u5217;<\/p>\n

intmsgget(key_tkey,intflag);<\/p>\n

\/\/\u529f\u80fd\uff1a\u5411\u5185\u6838\u63d0\u51fa\u7533\u8bf7\u4e00\u4e2a\u6d88\u606f\u961f\u5217\u5bf9\u8c61\u3002<\/p>\n

\/\/\u53c2\u6570\uff1a<\/p>\n

\/\/key\u7528\u6237\u7a7a\u95f4\u7684\u901a\u914d\u7b26<\/p>\n

\/\/flag\u6d88\u606f\u5bf9\u8c61\u7684\u8bbf\u95ee\u6743\u9650\uff0c\u800c\u4e14\u5047\u5982\u662f\u7b2c\u4e00\u6b21\u5411\u5185\u6838\u63d0\u51fa\u7533\u8bf7\uff0c\u5219\u987b\u8981\u6dfb\u52a0IPC_CREAT\u548cIPC_EXCL<\/p>\n

\/\/\u8fd4\u56de\u503c\uff1a\u6210\u529f\u8fd4\u56de\u6d88\u606f\u5bf9\u8c61id\u5931\u8d25-1<\/p>\n

2\u3001\u6d88\u606f\u5bf9\u8c61\u7684\u64cd\u4f5c\uff1a<\/p>\n

1.\u53d1\u9001\u6d88\u606f\uff1a<\/p>\n

intmsgsnd(intmsgid,void*msgp,size_tsize,intflag);<\/p>\n

\u53c2\u6570\uff1amsgid\u8981\u53d1\u9001\u5230\u7684\u6d88\u606f\u5bf9\u8c61id<\/p>\n

msgp==>\u8981\u53d1\u9001\u7684\u6d88\u606f\u7ed3\u6784\u4f53=\u300b<\/p>\n

structmsgbuf{<\/p>\n

longmtype;\/\/\/\/\u6d88\u606f\u7684\u7c7b\u578b<\/p>\n

charmtext[N];\/\/\/\/\u6d88\u606f\u7684\u6b63\u6587\uff0cN\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5927\u5c0f<\/p>\n

}\uff1b<\/p>\n

size:\u8981\u53d1\u9001\u7684\u6d88\u606f\u6b63\u6587\u7684\u5bbd\u5ea6\uff0c\u5355\u4f4d\u662f\u5b57\u8282\u3002<\/p>\n

flag:=0\u8868\u793a\u963b\u585e\u53d1\u9001<\/p>\n

=IPC_NOWAIT\u975e\u963b\u585e\u65b9\u6cd5\u53d1\u9001<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0,\u5931\u8d25-1\uff1b<\/p>\n

2.\u63a5\u6536\u6d88\u606f\uff1a<\/p>\n

intmsgrcv(intmsgid,void*msgp,size_tsize,longtype,intflag);<\/p>\n

\u53c2\u6570\uff1amsgid\u8981\u63a5\u6536\u5230\u7684\u6d88\u606f\u5bf9\u8c61id<\/p>\n

msgp====>\u8981\u63a5\u6536\u7684\u6d88\u606f\u7ed3\u6784\u4f53\u53d8\u91cf\uff0c\u5fc5\u987b\u4e8b\u5148\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u53d8\u91cf\uff0c\u62ff\u6765\u50a8\u5b58\u6570\u636e\u3002<\/p>\n

size====\u300b\u8981\u63a5\u6536\u7684\u6570\u636e\u5bbd\u5ea6\uff0c\u901a\u5e38\u662fsizeof(msgp);<\/p>\n

type====>\u8981\u63a5\u6536\u7684\u6d88\u606f\u7c7b\u578b<\/p>\n

flag====\u300b\u63a5\u6536\u6d88\u606f\u7684\u5f62\u5f0f\uff0c0\u8868\u793a\u963b\u585e\u63a5\u6536IPC_NOWAIT\u975e\u963b\u585e\u63a5\u6536<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1\uff1b<\/p>\n

3.\u6d88\u606f\u961f\u5217\u5bf9\u8c61\u7684\u5378\u8f7d\uff1a<\/p>\n

intmsgctl(intmsgid,intcmd,structmsgid_ds*buff);<\/p>\n

\u529f\u80fd\uff1a\u8c03\u6574\u6d88\u606f\u961f\u5217\u7684\u5c5e\u6027\uff0c\u597d\u591a\u65f6\u4faf\u62ff\u6765\u5220\u6389\u6d88\u606f\u961f\u5217\u3002<\/p>\n

\u53c2\u6570\uff1amsgid\u8981\u64cd\u4f5c\u7684\u6d88\u606f\u961f\u5217\u5bf9\u8c61id<\/p>\n

cmd==>IPC_RMID====>\u5220\u6389\u6d88\u606f\u961f\u5217\u7684\u5b8f<\/p>\n

IPC_SET====>\u8bbe\u7f6e\u5c5e\u6027<\/p>\n

IPC_STAT====\u300b\u83b7\u53d6\u5c5e\u6027<\/p>\n

buff====\u300b\u5c5e\u6027\u7ed3\u6784\u4f53<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529f0\u5931\u8d25-1<\/p>\n

3.\u5171\u4eab\u663e\u5b58<\/p>\n

0\u3001\u5934\u6587\u4ef6<\/p>\n

#include<\/p>\n

1\u3001key\u503c\u5f97\u521b\u5efa<\/p>\n

\u540c\u4e0a\u3002<\/p>\n

2\u3001shmget\u5411\u5185\u6838\u7533\u8bf7\u5171\u4eab\u663e\u5b58\u5bf9\u8c61<\/p>\n

intshmget(key_tkey,intsize,intflag);<\/p>\n

\u53c2\u6570\uff1akey\u7528\u6237\u7a7a\u95f4\u7684\u60df\u4e00\u901a\u914d\u7b26<\/p>\n

size\u8981\u7533\u8bf7\u7684\u5171\u4eab\u663e\u5b58\u5927\u5c0f<\/p>\n

flag\u7533\u8bf7\u7684\u5171\u4eab\u663e\u5b58\u8bbf\u95ee\u6743\u9650\uff0c\u5018\u82e5\u662f\u7b2c\u4e00\u6b21\u7533\u8bf7\uff0c\u5219\u987b\u8981IPC_CREATIPC_EXCL;<\/p>\n

\u8fd4\u56de\u503c\uff1a\u6210\u529fshmid\u5931\u8d25-1\uff1b<\/p>\n

3\u3001shmat\u5c06\u5185\u6838\u7533\u8bf7\u6210\u529f\u7684\u5171\u4eab\u663e\u5b58\u6620\u5c04\u5230\u672c\u5730<\/p>\n

4.\u8baf\u53f7\u91cf<\/p>\n

\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n

\u7248\u6743\u7533\u660e\uff1a\u672c\u6587\u4e3aCSDN\u535a\u4e3b\u300c\u5218\u4ed5\u8c6a\u300d\u7684\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5b88CC4.0BY-SA\u7248\u6743\u5408\u540c\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u53ca\u672c\u7533\u660e\u3002<\/p>\n

\u539f\u6587\u94fe\u63a5\uff1a<\/p>\n","protected":false},"excerpt":{"rendered":"

Linux\u5185\u6838\u8bbe\u8ba1\u4e0e\u5b9e\u73b0\u2014>\u8fdb\u7a0b\u7ba1\u7406\u529f\u80fd\uff1a\u901a\u8fc7\u8be5\u51fd\u6570\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u6709\u540d\u7ba1\u9053\u7684\u8bbe\u5907\u6587\u4ef6\u51fa\u6765\u3002\u529f\u80fd\uff1a\u8fdb\u7a0b\u53ef\u4ee5\u81ea\u5df1\u901a\u8fc7\u8be5\u51fd\u6570\u7ed9\u81ea\u5df1\u53d1\u9001\u4fe1\u53f7\u3002\u4fe1\u53f7\u4f1a\u4f7f\u7a0b\u5e8f\u7ec8\u6b62\u8fd0\u884c\u3002,\u7cfb\u7edf\u5bf9\u8fd9\u4e9b\u4fe1\u53f7\u662f\u600e\u4e48\u5904\u7406\u7684\uff0c\u7a0b\u5e8f\u5c31\u4f1a\u5bf9\u8be5\u4fe1\u53f7\u600e\u4e48\u5904\u7406\u3002\uff082\uff09\u4fe1\u53f7\u5904\u7406\u7a0b\u5e8f\u662f\u5728\u7528\u6237\u6001\u4e0b\u8fd0\u884c\u7684\uff0c\u800c\u4e2d\u65ad\u5904\u7406\u7a0b\u5e8f\u662f\u5728\u6838\u5fc3\u6001\u4e0b\u8fd0\u884c\uff1bIPC\u5bf9\u8c61\u5305\u542b\u4e86\uff1a\u5171\u4eab\u5185\u5b58\u3001\u4fe1\u53f7\u91cf\u3001\u6d88\u606f\u961f\u5217\u5c06\u5185\u6838\u7533\u8bf7\u6210\u529f\u7684\u5171\u4eab\u5185\u5b58\u6620\u5c04\u5230\u672c\u5730<\/p>\n","protected":false},"author":1,"featured_media":282862,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-282861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=282861"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282861\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/282862"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=282861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=282861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=282861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}