资源描述:
《BSD进程间通信编程入门,主要讲socket编程.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Introductory4.4BSDIPCPSD:20-1AnIntroductory4.4BSDInterprocessCommunicationTutorialStuartSechrestComputerScienceResearchGroupComputerScienceDivisionDepartmentofElectricalEngineeringandComputerScienceUniversityofCalifornia,BerkeleyABSTRACTBerkeleyUNIX†4.4BSDoffersseveralchoicesfor
2、interprocesscommunication.Toaidthepro-grammerindevelopingprogramswhicharecomprisedofcooperatingprocesses,thedifferentchoicesarediscussedandaseriesofexampleprogramsarepresented.Theseprogramsdemonstrateinasimplewaytheuseofpipes,socketpairs,socketsandtheuseofdatagramandstreamcommun
3、ication.Theintentofthisdocumentistopresentafewsimpleexampleprograms,nottodescribethenetworkingsysteminfull.1.GoalsFacilitiesforinterprocesscommunication(IPC)andnetworkingwereamajoradditiontoUNIXintheBerkeleyUNIX4.2BSDrelease.Thesefacilitiesrequiredmajoradditionsandsomechangestot
4、hesys-teminterface.ThebasicideaofthisinterfaceistomakeIPCsimilartofileI/O.InUNIXaprocesshasasetofI/Odescriptors,fromwhichonereadsandtowhichonewrites.Descriptorsmayrefertonormalfiles,todevices(includingterminals),ortocommunicationchannels.Theuseofadescriptorhasthreephases:itscreati
5、on,itsuseforreadingandwriting,anditsdestruction.Byusingdescriptorstowritefiles,ratherthansimplynamingthetargetfileinthewritecall,onegainsasurprisingamountofflexibility.Often,theprogramthatcreatesadescriptorwillbedifferentfromtheprogramthatusesthedescriptor.Forexampletheshellcancrea
6、teadescriptorfortheoutputofthe`ls'commandthatwillcausethelistingtoappearinafileratherthanonaterminal.PipesareanotherformofdescriptorthathavebeenusedinUNIXforsometime.Pipesallowone-waydatatransmissionfromoneprocesstoanother;thetwoprocessesandthepipemustbesetupbyacommonancestor.The
7、useofdescriptorsisnottheonlycommunicationinterfaceprovidedbyUNIX.Thesignalmech-anismsendsatinyamountofinformationfromoneprocesstoanother.Thesignaledprocessreceivesonlythesignaltype,nottheidentityofthesender,andthenumberofpossiblesignalsissmall.Thesignalsemanticslimittheflexibilit
8、yofthesignalingmechanismasameansofinterprocessc