Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

LinuxÖÐselectº¯Êýѧϰ¼°ÊµÀý±Ê¼Ç

UnixÖеĺ¯ÊýselectºÍpollÓÃÀ´£¬Ö§³ÖUnixÖÐI/O¸´ÓõŦÄÜ£¬ÔÚUnixÖÐI/OÄ£ÐÍ¿ÉÒÔ·ÖΪÒÔÒ»¼¸ÖÖ£º
£¨1£©×èÈûI/O
£¨2£©·Ç×èÈûI/O
£¨3£©I/O¸´Óã¨selectºÍpoll£©
£¨4£©ÐźÅÇý¶¯I/O(SIGIO)
£¨5£©Òì²½I/O
   ÆäÖУ¬ÏÖÔڱȽÏÁ÷ÐеÄI/OÄ£ÐÍÊÇ×èÈûI/OÄ£ÐÍ.×èÈûI/OÊǵ±Ó¦ÓóÌÐòºÍÄں˽»»»Êý¾Ýʱ£¬ÓÉÓÚÄں˻¹Ã»ÓÐ×¼±¸ºÃÊý¾Ý£¬ÄÇôӦÓóÌÐò±ØÐë½øÐÐ×èÈû£¬²»ÄܼÌÐøÖ´ÐУ¬Ö±µ½Äں˵ÄÊý¾Ý×¼±¸ºÃ£¡Ó¦ÓóÌÐòÈ¡µ½Êý¾Ý·µ»Øºó£¬×èÈû¹ý³Ì½áÊø£¡µ«·µ»ØµÄ½á¹ûÒ²²¢²»Ò»¶¨ÊÇÕýÈ·µÄ£¡ÕâÀïÖ»ÊǾÙÒ»¸ö¼òµ¥µÄÀý×Ó£¡Ò²ÐíÇé¿ö»á¸ü¼ÓµÄ¸´ÔÓ£¡
   ·Ç×èÈûI/O£¬ÀýÈçÔÚºÍÄں˽»»»Êý¾Ýʱ£¬Èç¹ûÄں˵ÄÊý¾ÝûÓÐ×¼±¸ºÃ£¬ÄÇôӦÓóÌÐò²»»áÒ»ÕæµÈ´ý£¬»áÓÐÒ»¸ö·µ»ØÐÅÏ¢£¬ÒÔÅжÏÊÇÄÇÀï³öÁËÎÊÌ⣡ÕâÑùÓÐÖúÓÚÈ·ÈÏÊÇÔÚÄǸö½×¶Î³öÁËÎÊÌ⣡
   I/O¸´Óã¬ÎÒÃǾͿÉÒÔµ÷ÓÃϵͳµ÷ÓÃselectºÍpoll£¡ÔÚÕâÁ½¸öϵͳµ÷ÓÃÖеÄijһ¸ö×èÈû£¬¶ø²»ÊÇÕæÕýµÄ×èÈûI/Oϵͳµ÷Óã¡
   ÏÂÃæÖ÷Òª½éÉÜI/O¸´ÓÃÖеÄselectº¯Êý£¡selectº¯Êý¿ÉÒÔָʾÄں˵ȴý¶à¸öʼþÖеÄÈÎÒ»¸ö·¢Éú£¬½öÔÚÒ»¸ö»ò¶à¸öʼþ·¢Éú£¬»òÕߵȴýÒ»¸ö×ã¹»µÄʱ¼äºó²Å»½Ðѽø³Ì£¡selectº¯ÊýµÄÔ­ÐÍÈçÏ£º
#include <sys/types.h>
#include<sys/time.h>
int select (int maxfdp1,fd_set *readset,fd_set * writeset,fd_set excpetset,const struct timeval *timeout);
·µ»ØÖµ£º×¼±¸ºÃµÄÃèÊö·ûµÄÕýÊýÄ¿ 0---³¬Ê± -1---³ö´í£¡
ÆäÖÐ×îºóÒ»¸ö²ÎÊýÊÇÒ»¸ö½á¹¹ÌåµÄÖ¸Õ룬Ëü±íʾµÈ´ýÄÚºËÖеÄÒ»×éÃèÊö·ûÈÎÒ»¸ö×¼±¸ºÃÐèÒª»¨·Ñ¶à¾ÃµÄʱ¼ä£¡ÆäÖÐtimevalÖ¸¶¨ÁËÃëÊýºÍ΢ÃëÊý¡£
struct timeval{
         long tv_sec;//ÃëÊý
         long tv_usec;//΢ÃëÊý
};
        
   ½« timeoutÉèÖÃΪ¿ÕÖ¸Õëʱ£¬»áÓÀÔ¶µÈ´ýÏÂÈ¥£¬µÈ´ý¹Ì¶¨µÄʱ¼ä£ºÈç¹ûtimeoutÖ¸ÏòµÄtimevalÖеľßÌåµÄֵʱ£¬»áµÈ´ýÒ»¸ö¹Ì¶¨µÄʱ¼ä£¬²»µÈ´ýÁ¢¿Ì·µ»Ø£¬ÕâʱtimevalÖеÄtv_secºÍtv_usecΪ0.
selectÓÐÈý¸ö¿ÉÄܵķµ»ØÖµ¡£
1£®Õý³£Çé¿öÏ·µ»Ø¾ÍÐ÷µÄÎļþÃèÊö·û¸öÊý£»
2£®¾­¹ýÁËtimeoutʱ³¤ºóÈÔÎÞÉ豸׼±¸ºÃ£¬·µ»ØֵΪ0£»
3£®Èç¹ûselect±»Ä³¸öÐźÅÖжϣ¬Ëü½«·µ»Ø-1²¢ÉèÖÃerrnoΪEINTR¡£
4£®Èç¹û³ö´í£¬·µ»Ø-1²¢ÉèÖÃÏàÓ¦µÄerrno¡£
EBADF ÎļþÃèÊö´ÊΪÎÞЧµÄ»ò¸ÃÎļþÒѹرÕ
EINTR ´Ëµ÷Óñ»ÐźÅË


Ïà¹ØÎĵµ£º

LinuxÏÂËøÓû§Óë½âËøÎÊÌâ

LinuxÏÂËøÓû§Óë½âËøÎÊÌâ [Ô­´´ 2010-02-03 21:44:35]   
×ֺţº´ó ÖРС
Ò»£ºµÇ¼ʧ°Ü´Î»Ø³¬¹ýÏÞÖÆ
1£©ËøÓû§µÄÉ趨
/etc/pam.d/Ï°üº¬¸÷ÖÖÈÏÖ¤³ÌÐò»ò·þÎñµÄÅäÖÃÎļþ¡£±à¼­ÕâЩ¿ÉÏÞÖÆÈÏ֤ʧ°Ü´ÎÊý£¬µ±Ê§°Ü´ÎÊý³¬¹ýÖ¸¶¨ÖµÊ±Óû§»á±»Ëøס¡£
ÔÚ´Ë£¬ÒÔrun levelΪ3µÄʱºò£¬¶à´ÎµÇ¼µÇ¼ʧ°Ü¼´ËøÓû§ÎªÀý£º
......

Linux²é¿´Ó²¼þÐÅÏ¢

ÔÚLINUX»·¾³¿ª·¢Çý¶¯³ÌÐò£¬Ê×ÏÈҪ̽²âµ½ÐÂÓ²¼þ£¬½ÓÏÂÀ´¾ÍÊÇ¿ª·¢Çý¶¯³ÌÐò¡£
³£ÓÃÃüÁîÕûÀíÈçÏ£º
ÓÃÓ²¼þ¼ì²â³ÌÐòkudzu̽²âÐÂÓ²¼þ£ºservice kudzu start ( or restart)
²é¿´CPUÐÅÏ¢£ºcat /proc/cpuinfo
²é¿´°å¿¨ÐÅÏ¢£ºcat /proc/pci
²é¿´PCIÐÅÏ¢£ºlspci (Ïà±Ècat /proc/pci¸üÖ±¹Û£©
²é¿´ÄÚ´æÐÅÏ¢ ......

Linux ƽ̨ÉϵÄÈí¼þ°ü¹ÜÀí

°²×°£¬Éý¼¶ºÍжÔØÓ¦ÓÃÈí¼þÊÇÓ°ÏìÓû§¶Ô²Ù×÷ϵͳÆÀ¼ÛµÄ¾ö¶¨ÐÔÒòËØÖ®Ò»¡£¶ÔÓÚÈÕ½¥Á÷ÐÐµÄ GNU/Linux ²Ù×÷ϵͳ£¬ÓµÓмò½àÇ¿´óµÄÈí¼þ°ü¹ÜÀí»úÖƹ¦²»¿Éû¡£±¾ÎÄ´Ó»ù±¾µÄ rpm/dpkg ÃüÁîÐгö·¢£¬ÒÔ RHEL ºÍ Ubuntu
ΪÀý£¬½éÉܵäÐÍ Linux ϵͳÖÐÓ¦ÓÃÈí¼þµÄ¹ÜÀíºÍʹÓá£
RPM/DPKG Á½´óÕóÓª¼ò½é
ÔÚ GNU/Linux( ÒÔϼò³Æ Linux) ²Ù× ......

ǶÈëʽLinuxÎļþϵͳ¼°Æä´æ´¢»úÖÆ·ÖÎö

     ǶÈëʽϵͳÓëͨÓÃPC»ú²»Í¬£¬Ò»°ãûÓÐÓ²ÅÌÕâÑùµÄ´æ´¢É豸¶øÊÇʹÓÃFlashÉÁ´æоƬ¡¢Ð¡ÐÍÉÁ´æ¿¨µÈרΪǶÈëʽϵͳÉè¼ÆµÄ´æ´¢×°Ö㬱¾ÎÄ·ÖÎöÁËǶÈëʽϵͳÖг£ÓõĴ洢É豸¼°Æä¹ÜÀí»úÖÆ£¬½éÉÜÁ˳£ÓõĻùÓÚFLASHµÄÎļþϵͳÀàÐÍ¡£
1£®Ç¶Èëʽϵͳ´æ´¢É豸¼°Æä¹ÜÀí»úÖÆ·ÖÎö
¡¡¡¡¹¹½¨ÊÊÓÃÓÚǶÈëʽϵͳµÄLi ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ