{"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":"
<\/p>\n
<\/p>\n
<\/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 <\/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