當前位置:編程學習大全網 - 編程語言 - linux.poll

linux.poll

epoll實現原理?

Epoll是LinuxIO的多路復用的機制,是select/poll的增強版本,在Linux內核fs/eventpoll.c中可以查看epoll的具體的實現。

學習任何組件,首先得知道它有什麽數據結構或者數據類型,epoll主要有兩個結構體:eventpoll和epitem。epitem是每壹個IO對應的事件,比如EPOLL_CTL_ADD操作時,就需要創建壹個epitem;eventpoll是每壹個epoll所對應的,比如epoll_create就是創建壹個eventpoll。

libevent詳解?

libevent是壹個輕量級的開源的高性能的事件觸發的網絡庫,適用於windows、linux、bsd等多種平臺,內部使用select、epoll、kqueue等系統調用管理事件機制。

libevent支持多種I/O多路復用技術(epoll、poll、dev/poll、select和kqueue等),在不同的操作系統下,做了多路復用模型的抽象,可以選擇使用不同的模型,通過事件函數提供服務。

如何在linuxsuse中配置NTP服務器?

在suse上配置ntp

$vim/etc/ntp.conf

#增加時間源

server192.168.56.1

$chkconfigntpon#在系統重啟時啟動服務

$servicentpstart#啟動ntp

$servicentpstatus#查看ntp狀態

問題:

1)為什麽在故意改了壹個錯誤的時間,ntpd沒有更新時間?

如果差異很大,需要重新doinganInitialSynchronization,IfthetimeonthelocalserverisverydifferentfromthatofitsprimarytimeserveryourNTPdaemonwilleventuallyterminateitselfleavinganerrormessageinthe/var/log/messagesfile.Youshouldrunthentpdate-ucommandtoforceyourservertobecomeinstantlysynchronizedwithitsNTPserversbeforestartingtheNTPdaemonforthefirsttime.Thentpdatecommanddoesn'truncontinuouslyinthebackground,youwillstillhavetorunthentpddaemontogetcontinuousNTPupdates.

2)/etc/ntp.conf中選擇主NTPServer

選擇了哪個server做為主server是按stratum的大小決定的?應該不是,由ntp的算法決定,如在virtualbox中的suse怎麽樣都無法選擇外部時鐘源,ntpd在幾次polltime後算法就決定使用local源,郁悶啊。由於是虛擬機中運行,時鐘和cpu的頻率有關系,跳得比真實的硬件快,在virtaulbox中ntp的算法認為local源比外部源更準確就使用了local的,解決的方法可以去掉local源,只使用外部源或者在crontab中每分鐘執行壹次ntpdate了。

即使把本機的stratum設置為比外部源更高的,過了壹段時間以後,virtualbox中的suse還是選擇了local,郁悶again

fudge127.127.1.0stratum12#notdisciplined

remoterefidsttwhenpollreachdelayoffsetjitter

==============================================================================

LOCAL(0).LOCL.15l96410.0000.0000.002

192.168.56.1139.114.32.13414u86413.739-53.0450.002

註意最開始的時候,ip地址前面是沒有符號的,poll幾次以後ntp就會選擇壹個主時間源,前面帶*號標識。

3)windows上的ntpserver配置

官方ntp.org推薦的win上的ntpserver,mandlineutilityntpqcanbeusedtocheckthestatusofaNTPdaemononeitherthelocalmachineoronaremotehost.

ntpqcanberuninaninteractivemodeorinbatchmode.Inbatchmode,ntpqexecutesacommandandreturnstothecommandprompt.Theparameter-p('peers')letsntpqprintthestatusofaNTPdaemon.Enter

ntpq-p

todisplaythestatusofthedaemononthelocalmachine,or

ntpq-pntp_server

todisplaythestatusofthedaemonontheremotehostntp_server.ThecommandshouldprintatablewithonestatuslineforeachreferencetimesourcewhichhasbeenconfiguredfortheNTPdaemononthespecifiedhost:

remoterefidsttwhenpollreachdelayoffsetjitter

=======================================================================

LOCAL(0)LOCAL(0)12l30643770.0000.0000.000

*GENERIC(0).DCFa.0-24643770.0000.0500.003

+172.16.3.103.PPS.1u36643771.306-0.0190.043

ThetableaboveshowstheoutputforaNTPdaemonwhichhas3referencetimesources:itsownlocalclock,aDCF77radioclockasrefclock-0,plusanNTPdaemononthenetwork,withIPaddress172.16.3.103.

Ifthefirstcharacterofalineisnotblankthenitcontainsaqualifierforthecorrespondingreferencetimesource.Immediatelyafterthedaemonhasbeenstartedallqualifiersareblank.TheNTPdaemonneedsseveralpollingcyclestochecktheavailabletimesourcesanddeclareoneofthemasthereferenceitsynchronizesto.

Anasterisk*inthefirstcolumnmarksthereferencetimesourcewhichiscurrentlypreferredbytheNTPdaemon,the+charactermarkshighqualitycandidatesforthereferencetimewhichcouldbeusedifthecurrentlyselectedreferencetimesourceshouldbecomeunavailable.

ThecolumnremotedisplaystheIPaddressorthehostnameofthereferencetimesource,whereLOCALreferstothelocalclock.Therefidshowsthetypeofthereferenceclock,wheree.g.LOCALorLCLreferstothelocalclockagain,.DCFa.referstoastandardDCF77timesource,and.PPS.indicatesthatthereferenceclockisdisciplinedbyahardwarepulse-per-secondsignal.Otheridentifiersarepossible,dependingonthetypeofthereferenceclock.

Thecolumnstreflectsthestratumnumberofthereferencetimesource.Intheexampleabove,thelocalclockhasstratum12,theremotetimeserverat172.16.3.103hasstratum1whichisthebestyoucanseeacrossthenetwork,andthelocalradioclockhasstratum0,sotheradioclockiscurrentlybeingpreferred.

Everytimeawhencountreachesthepollnumberinthesameline,theNTPdaemonqueriesthetimefromthecorrespondingtimesourceandresetsthewhencountto0.Thequeryresultsofeachpollingcyclearefilteredandusedasameasurefortheclock'squalityandreachability.

Thecolumnreachshowsifareferencetimesourcecouldbereachedatthelastpollingintervals,i.e.datacouldbereadfromthereferencetimesource,andthereferencetimesourcewassynchronized.Thevaluemustbeinterpretedasan8bitshiftregisterwhosecontentsisforhistoricalreasonsdisplayedasoctalvalues.IftheNTPdaemonhasjustbeenstarted,thevalueis0.Eachtimeaquerywassuccessfula'1'isshiftedinfromtheright,soafterthedaemonhasbeenstartedthesequenceofreachnumbersis0,1,3,7,17,37,77,177,377.Themaximumvalue377meansthattheeightlastquerieswerecompletedsuccessfully.

Queriesareconsideredsuccessfulifdatacanbereceivedfromthetimesource,andthetimesourceinturnclaimstobesynchronizedtosomeothertimesource.Incaseofahardwarereferenceclockthismeansthequeryconsideredunsuccessfulifthehardwarereferenceclockisnotsynchronizedtoitsincomingtimesignal,e.g.becausetheclock'santennahasbeendisconnected,orifnodatacanbereceivede.g.becausetheserialcabletoanexternaldevicehasbeendisconnected.

TheNTPdaemonmusthavereachedareferencetimesourceseveraltimes(reachnot0)beforeitselectsapreferredtimesourceandputsanasteriskinthefirstcolumn.

Thecolumnsdelay,offsetandjittershowsometimingvalueswhicharederivedfromthequeryresults.Insomeversionsofntpqthelastcolumnislabeleddisp(fordispersion)insteadofjitter.Allvaluesareininmilliseconds.Thedelayvalueisderivedfromtheroundtriptimeofthequeries.Theoffsetvalueshowsthedifferencebetweenthereferencetimeandthesystemclock.Thejittervalueindicatesthemagnitudeofjitterbetweenseveraltimequeries.

  • 上一篇:C語言:歌星大獎賽中,有十個評委為參賽的選手打分,分數為1-100分,選手最後得分為去掉壹個最高分
  • 下一篇:彈窗廣告怎麽做?網頁上出現的彈窗廣告怎麽操作?
  • copyright 2024編程學習大全網