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

LinuxÏÂselectºÍpollµÄÓ÷¨

select()º¯ÊýµÄ×÷ÓÃ
    ϵͳµ÷ÓÃselectºÍpollµÄºó¶ËʵÏÖ£¬ÓÃÕâÁ½¸öϵͳµ÷ÓÃÀ´²éѯÉ豸ÊÇ·ñ¿É¶Áд£¬»òÊÇ·ñ´¦ÓÚijÖÖ״̬¡£Èç¹ûpollΪ¿Õ£¬ÔòÇý¶¯É豸»á±»ÈÏΪ¼´¿É¶ÁÓÖ¿Éд£¬·µ»ØÖµÊÇÒ»¸ö״̬ÑÚÂë
ÈçºÎʹÓÃselect()º¯Êý?
    select()º¯ÊýµÄ½Ó¿ÚÖ÷ÒªÊǽ¨Á¢ÔÚÒ»ÖÖ½Ð'fd_set'ÀàÐ͵Ļù´¡ÉÏ¡£Ëü('fd_set') ÊÇÒ»×éÎļþÃèÊö·û(fd)µÄ¼¯ºÏ¡£ÓÉÓÚfd_setÀàÐ͵ij¤¶ÈÔÚ²»Í¬Æ½Ì¨Éϲ»Í¬£¬Òò´ËÓ¦¸ÃÓÃÒ»×é±ê×¼µÄºê¶¨ÒåÀ´´¦Àí´ËÀà±äÁ¿£º
    fd_set set;
    FD_ZERO(&set);      
    FD_SET(fd, &set);   
    FD_CLR(fd, &set);   
    FD_ISSET(fd, &set); 
     
ÔÚ¹ýÈ¥£¬Ò»¸öfd_setͨ³£Ö»ÄÜ°üº¬ÉÙÓÚµÈÓÚ32¸öÎļþÃèÊö·û£¬ÒòΪfd_setÆäʵֻÓÃÁËÒ»¸öintµÄ±ÈÌØʸÁ¿À´ÊµÏÖ£¬ÔÚ´ó¶àÊýÇé¿öÏ£¬¼ì²é fd_setÄÜ°üÀ¨ÈÎÒâÖµµÄÎļþÃèÊö·ûÊÇϵͳµÄÔðÈΣ¬µ«È·¶¨ÄãµÄfd_setµ½µ×ÄܷŶàÉÙÓÐʱÄãÓ¦¸Ã¼ì²é/Ð޸ĺêFD_SETSIZEµÄÖµ¡£*Õâ¸öÖµÊÇϵͳÏà¹ØµÄ*£¬Í¬Ê±¼ì²éÄãµÄϵͳÖеÄselect() µÄmanÊֲᡣÓÐһЩϵͳ¶Ô¶àÓÚ1024¸öÎļþÃèÊö·ûµÄÖ§³ÖÓÐÎÊÌâ¡£[ÒëÕß×¢£º Linux¾ÍÊÇÕâÑùµÄϵͳ£¡Äã»á·¢ÏÖsizeof(fd_set)µÄ½á¹ûÊÇ128(*8 = FD_SETSIZE=1024)¡¡¾¡¹ÜºÜÉÙÄã»áÓöµ½ÕâÖÖÇé¿ö¡£]
selectµÄ»ù±¾½Ó¿ÚÊ®·Ö¼òµ¥£º
    int select(int nfds, fd_set *readset, fd_set *writeset,
               fd_set *exceptset, struct timeval *timeout); 
ÆäÖУº
nfds    
     ÐèÒª¼ì²éµÄÎļþÃèÊö·û¸öÊý£¬ÊýÖµÓ¦¸Ã±ÈÊÇÈý×éfd_setÖÐ×î´óÊý
     ¸ü´ó£¬¶ø²»ÊÇʵ¼ÊÎļþÃèÊö·ûµÄ×ÜÊý¡£
readset   
     ÓÃÀ´¼ì²é¿É¶ÁÐÔµÄÒ»×éÎļþÃèÊö·û¡£
writeset
     ÓÃÀ´¼ì²é¿ÉдÐÔµÄÒ»×éÎļþÃèÊö·û¡£
exceptset
     ÓÃÀ´¼ì²éÒâÍâ״̬µÄÎļþÃèÊö·û¡£(×¢£º´íÎó²¢²»ÊÇÒâÍâ״̬)
timeout
     NULLÖ¸Õë´ú±íÎÞÏ޵ȴý£¬·ñÔòÊÇÖ¸Ïòtimeval½á¹¹µÄÖ¸Õ룬´ú±í×î
     ³¤µÈ´ýʱ¼ä¡£(Èç¹ûÆäÖÐtv_sec


Ïà¹ØÎĵµ£º

Linux »ñȡϵͳʱ¼ä

1.ʱ¼ä±íʾ
ÔÚ³ÌÐòµ±ÖÐ,ÎÒÃǾ­³£ÒªÊä³öϵͳµ±Ç°µÄʱ¼ä,±ÈÈçÎÒÃÇʹÓÃdateÃüÁîµÄÊä³ö½á¹û¡£Õâ¸öʱºòÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæÁ½¸öº¯Êý
time_t time(time_t *tloc);                    //ʱ¼ä¾«¶ÈΪÃë
char *ctime(const time_ ......

linux ½ø³ÌÉÏÏÂÎĺÍÖжÏÉÏÏÂÎÄ


¶ÔLinuxÄÚºËÖнø³ÌÉÏÏÂÎĺÍÖжÏÉÏÏÂÎĵÄÀí½â
 
 
 
 
 
 
2010Äê3ÔÂ3ÈÕ 10:51  Î¬¿â¿ª·¢Íø  ×÷ ÕߣºÑî˶,»ªÇåÔ¶¼ûǶÈëʽѧԺ½²Ê¦
Äں˿ռäºÍÓû§¿Õ¼äÊDzÙ×÷ϵͳÀíÂ۵Ļù´¡Ö®Ò»£¬¼´Äں˹¦ÄÜÄ£¿éÔËÐÐÔÚÄں˿ռ䣬¶øÓ¦ÓóÌÐòÔËÐÐÔÚÓû§¿Õ¼ä¡£ÏÖ´úµÄCPU¶¼¾ßÓв»Í¬ ......

LinuxÉ豸Çý¶¯¿ª·¢Ïê½â ±Ê¼Ç1 LinuxÉ豸Çý¶¯ÈëÃÅ


ʲôÊÇÇý¶¯£¿
×îͨË׵ĽâÊ;ÍÊÇ“ÇýʹӲ¼þÉ豸Ðж¯”
×÷Óã¿
É豸Çý¶¯Óëµ×²ãÓ²¼þÖ±½Ó´ò½»µÀ£¬°´ÕÕÓ²¼þÉ豸µÄ¾ßÌ幤×÷·½Ê½¶ÁдÉ豸¼Ä´æÆ÷£¬Íê³ÉÉ豸µÄÂÖѯ¡¢Öжϴ¦Àí¡¢DMAͨÐÅ£¬½øÐÐÎïÀíÄÚ´æÏòÐéÄâÄÚ´æµÄÓ³É䣬×îÖÕʹͨÐÅÉ豸Äܹ»ÊÕ·¢Êý¾Ý£¬Ê¹ÏÔʾÉ豸Äܹ»ÏÔʾÎÄ×ֺͻ­Ã棬ʹ´æ´¢É豸Äܹ»¼Ç¼ÎļþºÅÊý¾Ý
¼ÆË ......

LinuxÉ豸Çý¶¯¿ª·¢Ïê½â ±Ê¼Ç4 LinuxÄÚºËÄ£¿é

modprobeÃüÁî±ÈinsmodÃüÁîÇ¿´ó£¬ËüÔÚ¼ÓÔØijģ¿éʱ»áͬʱ¼ÓÔظÃÄ£¿éËùÒÀÀµµÄÆäËûÄ£¿é¡£Ê¹ÓÃmodprobeÃüÁî¼ÓÔصÄÄ£¿éÈôÒÔ“modprobe –r filename”µÄ·½Ê½Ð¶Ôؽ«Í¬Ê±Ð¶ÔØÆäÒÀÀµµÄÄ£¿é¡£
printk´òÓ¡µ½var/log/messages
2.6ÄÚºËÖÐÒѼÓÔصÄÐÅÏ¢Ò²´æÔÚÓÚ/sys/moduleĿ¼Ï£¬¼ÓÔØhello.koºó£¬ÄÚºËÖн«°üº¬/sys/mod ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ