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

Linux select()Ïê½â

Linux select()Ïê½â
 
    selectϵͳµ÷ÓÃÊÇÓÃÀ´ÈÃÎÒÃǵijÌÐò¼àÊÓ¶à¸öÎļþ¾ä±ú(file descriptor)µÄ״̬±ä»¯µÄ¡£³ÌÐò»áÍ£ÔÚselectÕâÀïµÈ´ý£¬Ö±µ½±»¼àÊÓµÄÎļþ¾ä±úÓÐijһ¸ö»ò¶à¸ö·¢ÉúÁË״̬¸Ä±ä¡£
ÎļþÔÚ¾ä±úÔÚLinuxÀïºÜ¶à£¬Èç¹ûÄãmanij¸öº¯Êý£¬ÔÚº¯Êý·µ»ØÖµ²¿·Ö˵µ½³É¹¦ºóÓÐÒ»¸öÎļþ¾ä±ú±»´´½¨µÄ¶¼Êǵģ¬Èçman socket¿ÉÒÔ¿´µ½“On success, a file descriptor for the new socket is returned.”¶øman 2 open¿ÉÒÔ¿´µ½“open() and creat() return the new file descriptor”£¬ÆäʵÎļþ¾ä±ú¾ÍÊÇÒ»¸öÕûÊý£¬¿´socketº¯ÊýµÄÉùÃ÷¾ÍÃ÷°×ÁË£º
int socket(int domain, int type, int protocol);
µ±È»£¬ÎÒÃÇ×îÊìϤµÄ¾ä±úÊÇ0¡¢1¡¢2Èý¸ö£¬0ÊDZê×¼ÊäÈ룬1ÊDZê×¼Êä³ö£¬2ÊDZê×¼´íÎóÊä³ö¡£0¡¢1¡¢2ÊÇÕûÊý±íʾµÄ£¬¶ÔÓ¦µÄFILE *½á¹¹µÄ±íʾ¾ÍÊÇstdin¡¢stdout¡¢stderr£¬0¾ÍÊÇstdin£¬1¾ÍÊÇstdout£¬2¾ÍÊÇstderr¡£
±ÈÈçÏÂÃæÕâÁ½¶Î´úÂ붼ÊÇ´Ó±ê×¼ÊäÈë¶ÁÈë9¸ö×Ö½Ú×Ö·û£º
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char ** argv)
{
        char buf[10] = "";
        read(0, buf, 9); /* ´Ó±ê×¼ÊäÈë 0 ¶ÁÈë×Ö·û */
        fprintf(stdout, "%s\n", buf); /* Ïò±ê×¼Êä³ö stdout д×Ö·û */
        return 0;
}
/* **ÉÏÃæºÍÏÂÃæµÄ´úÂ붼¿ÉÒÔÓÃÀ´´Ó±ê×¼ÊäÈë¶ÁÓû§ÊäÈëµÄ9¸ö×Ö·û** */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(int argc, char ** argv)
{
        char buf[10] = "";
        fread(buf, 9, 1, stdin); /* ´Ó±ê×¼ÊäÈë stdin ¶ÁÈë×Ö·û */
        write(1, buf, strlen(buf));
        return 0;
}
   ¼ÌÐøÉÏÃæ˵µÄselect£¬¾ÍÊÇÓÃÀ´¼àÊÓij¸ö»òijЩ¾ä±úµÄ״̬±ä»¯µÄ¡£selectº¯ÊýÔ­ÐÍÈçÏ£º
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
º¯ÊýµÄ×îºóÒ»¸ö²ÎÊýtimeoutÏÔÈ»ÊÇÒ»¸ö³¬Ê±Ê±¼äÖµ£¬ÆäÀàÐÍÊÇstruct tim


Ïà¹ØÎĵµ£º

Linux µÄ¶àÏ̱߳à³ÌµÄ¸ßЧ¿ª·¢¾­Ñé

2009 Äê 4 ÔÂ 23 ÈÕ
±¾ÎÄÖÐÎÒÃÇÕë¶Ô Linux É϶àÏ̱߳à³ÌµÄÖ÷ÒªÌØÐÔ×ܽá³ö 5 Ìõ¾­Ñ飬ÓÃÒÔ¸ÄÉÆ Linux ¶àÏ̱߳à³ÌµÄÏ°¹ßºÍ±ÜÃâÆäÖеĿª·¢ÏÝÚå¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇ´©²åһЩ Windows µÄ±à³ÌÓÃÀýÓÃÒÔ¶Ô±È Linux ÌØÐÔ£¬ÒÔ¼ÓÉî¶ÁÕßÓ¡Ïó¡£
±³¾°
Linux ƽ̨ÉϵĶàÏ̳߳ÌÐò¿ª·¢Ïà¶ÔÓ¦ÆäËûƽ̨£¨±ÈÈç Windows£©µÄ¶àÏß³Ì API ÓÐһЩϸ΢ ......

Èý¿î Linux ϵÄÃâ·Ñ×ÀÃ漶ɱ¶¾Èí¼þ(ͼ)


ÓÉÓÚ Linux Á¼ºÃµÄÓû§È¨ÏÞ¹ÜÀíÌåϵ£¬²¡¶¾ÍùÍùÊÇ Linux ϵͳ¹ÜÀíÔ±×îºó²ÅÐèÒª¿¼ÂǵÄÎÊÌâ¡£ÒÔÍù£¬Linux ÉϵÄɱ¶¾Èí¼þÖ÷ÒªÊÇΪÆóÒµµÄÓʼþºÍÎļþ·þÎñÆ÷ËùÉè¼ÆµÄ¡£Èç½ñ£¬Ëæ×Å Linux ×ÀÃæÓû§ÊýÁ¿µÄÔö³¤£¬×ÀÃæÓû§ÔÚÊÜÒæÓÚ Linux ϵͳ¶Ô²¡¶¾½ÏÇ¿µÄÌìÈ»ÃâÒßÁ¦µÄͬʱ£¬Ò²ÐèҪɱ¶¾Èí¼þÇåÀí´ÓÍøÂç»òUÅÌ´øÀ´µÄWIndows²¡¶¾¡£¾¡¹ÜÄÇЩ ......

LinuxϵͳSudoÃüÁîµÄʹÓÃ˵Ã÷

“Sudo” ÊÇUnix/Linuxƽ̨ÉϵÄÒ»¸ö·Ç³£ÓÐÓõŤ¾ß£¬ËüÔÊÐíϵͳ¹ÜÀíÔ±·ÖÅä¸øÆÕͨÓû§Ò»Ð©ºÏÀíµÄ“ȨÀû”£¬ÈÃËûÃÇÖ´ÐÐһЩֻÓг¬¼¶Óû§»òÆäËûÌØÐíÓû§²ÅÄÜÍê³ÉµÄÈÎÎñ£¬±ÈÈ磺ÔËÐÐһЩÏñmount£¬halt£¬suÖ®ÀàµÄÃüÁ»òÕ߱༭һЩϵͳÅäÖÃÎļþ£¬Ïñ/etc/mtab£¬ /etc/samba/smb.confµÈ¡£ÕâÑùÒÔÀ´£ ......

LinuxÏ°²×°SVN·þÎñÆ÷

°²×°»·¾³
CentOS 4.3 Final
Èí¼þÁбí
httpd-2.0.61.tar.gz
db-4.3.29.tar.gz
subversion-1.3.2.tar.gz
Èí¼þλÖÃ
/data/software
°²×°²½Öè
#mkdir /data/software/pkg
-p
°²×°Berkeley DB
#cd
/data/software/pkg
#tar zxvf ../db-4.3.29.tar.gz
#cd
db-4.3.29/docs
#../dist/configure
#make &&am ......

LinuxÏÂTomcat 6.0.26 °²×°

ÎÒÓõÄÊÇ fedora 12 ×Ô´ýµÄjdk 1.6 ÔÚ /usr/lib/jvm/java-1.6.0-openjdk
µÚÒ»²½£º°Ñapache-tomcat-6.0.26.tar.gz½âѹºó·Åµ½/usr/local/ÏÂÖØÃüÃûΪapache-tomcat-6.0.26
µÚ¶þ²½£ºÔÚ/etc/profileÎļþÖÐÊʵ±µÄλÖÃÌí¼ÓÈçÏ»·¾³±äÁ¿
CATALINA_HOME=/usr/local/apache-tomcat-6.0.26
CATALINA_BASE=/usr/local/apache-tomcat ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ