LinuxÏÂSocket±à³Ì
ÔÎĵØÖ·: http://www.kuqin.com/networkprog/20080512/8361.html
ʲôÊÇSocket
¡¡¡¡ Socket½Ó¿ÚÊÇTCP/IPÍøÂçµÄAPI£¬Socket½Ó¿Ú¶¨ÒåÁËÐí¶àº¯Êý»òÀý³Ì£¬³ÌÐòÔ±¿ÉÒÔÓÃËüÃÇÀ´¿ª·¢TCP/IPÍøÂçÉϵÄÓ¦ÓóÌÐò¡£ÒªÑ§InternetÉϵÄTCP/IPÍøÂç±à³Ì£¬±ØÐëÀí½âSocket½Ó¿Ú¡£
¡¡ ¡¡ Socket½Ó¿ÚÉè¼ÆÕß×îÏÈÊǽ«½Ó¿Ú·ÅÔÚUnix²Ù×÷ϵͳÀïÃæµÄ¡£Èç¹ûÁ˽âUnixϵͳµÄÊäÈëºÍÊä³öµÄ»°£¬¾ÍºÜÈÝÒ×Á˽âSocketÁË¡£ÍøÂçµÄ SocketÊý¾Ý´«ÊäÊÇÒ»ÖÖÌØÊâµÄI/O£¬SocketÒ²ÊÇÒ»ÖÖÎļþÃèÊö·û¡£SocketÒ²¾ßÓÐÒ»¸öÀàËÆÓÚ´ò¿ªÎļþµÄº¯Êýµ÷ÓÃSocket()£¬¸Ãº¯Êý·µ »ØÒ»¸öÕûÐ͵ÄSocketÃèÊö·û£¬ËæºóµÄÁ¬½Ó½¨Á¢¡¢Êý¾Ý´«ÊäµÈ²Ù×÷¶¼ÊÇͨ¹ý¸ÃSocketʵÏֵġ£³£ÓõÄSocketÀàÐÍÓÐÁ½ÖÖ£ºÁ÷ʽSocket £¨SOCK_STREAM£©ºÍÊý¾Ý±¨Ê½Socket£¨SOCK_DGRAM£©¡£Á÷ʽÊÇÒ»ÖÖÃæÏòÁ¬½ÓµÄSocket£¬Õë¶ÔÓÚÃæÏòÁ¬½ÓµÄTCP·þÎñÓ¦Óã»Êý¾Ý ±¨Ê½SocketÊÇÒ»ÖÖÎÞÁ¬½ÓµÄSocket£¬¶ÔÓ¦ÓÚÎÞÁ¬½ÓµÄUDP·þÎñÓ¦Óá£
Socket½¨Á¢
¡¡¡¡ÎªÁ˽¨Á¢Socket£¬³ÌÐò¿ÉÒÔµ÷ÓÃSocketº¯Êý£¬¸Ãº¯Êý·µ»ØÒ»¸öÀàËÆÓÚÎļþÃèÊö·ûµÄ¾ä±ú¡£socketº¯ÊýÔÐÍΪ£º
¡¡¡¡ int socket(int domain, int type, int protocol);
¡¡ ¡¡ domainÖ¸Ã÷ËùʹÓõÄÐÒé×壬ͨ³£ÎªPF_INET£¬±íʾ»¥ÁªÍøÐÒé×壨TCP/IPÐÒé×壩£»type²ÎÊýÖ¸¶¨socketµÄÀàÐÍ£º SOCK_STREAM »òSOCK_DGRAM£¬Socket½Ó¿Ú»¹¶¨ÒåÁËÔʼSocket£¨SOCK_RAW£©£¬ÔÊÐí³ÌÐòʹÓõͲãÐÒ飻protocolͨ³£¸³Öµ"0"¡£ Socket()µ÷Ó÷µ»ØÒ»¸öÕûÐÍsocketÃèÊö·û£¬Äã¿ÉÒÔÔÚºóÃæµÄµ÷ÓÃʹÓÃËü¡£
¡¡¡¡ SocketÃèÊö·ûÊÇÒ»¸öÖ¸ÏòÄÚ²¿Êý¾Ý½á¹¹µÄÖ¸Õ룬ËüÖ¸ÏòÃèÊö·û±íÈë¿Ú¡£µ÷ÓÃSocketº¯Êýʱ£¬socketÖ´ÐÐÌ彫½¨Á¢Ò»¸öSocket£¬Êµ¼ÊÉÏ"½¨Á¢Ò»¸öSocket"Òâζ×ÅΪһ¸öSocketÊý¾Ý½á¹¹·ÖÅä´æ´¢¿Õ¼ä¡£SocketÖ´ÐÐÌåΪÄã¹ÜÀíÃèÊö·û±í¡£
¡¡¡¡Á½¸öÍøÂç³ÌÐòÖ®¼äµÄÒ»¸öÍøÂçÁ¬½Ó°üÀ¨ÎåÖÖÐÅÏ¢£ºÍ¨ÐÅÐÒé¡¢±¾µØÐÒéµØÖ·¡¢±¾µØÖ÷»ú¶Ë¿Ú¡¢Ô¶¶ËÖ÷»úµØÖ·ºÍÔ¶¶ËÐÒé¶Ë¿Ú¡£SocketÊý¾Ý½á¹¹Öаüº¬ÕâÎåÖÖÐÅÏ¢¡£
SocketÅäÖÃ
¡¡ ¡¡Í¨¹ýsocketµ÷Ó÷µ»ØÒ»¸ösocketÃèÊö·ûºó£¬ÔÚʹÓÃsocket½øÐÐÍøÂç´«ÊäÒÔÇ°£¬±ØÐëÅäÖøÃsocket¡£ÃæÏòÁ¬½ÓµÄsocket¿Í»§¶Ëͨ¹ý µ÷ÓÃConnectº¯ÊýÔÚsocketÊý¾Ý½á¹¹Öб£´æ±¾µØºÍÔ¶¶ËÐÅÏ¢¡£ÎÞÁ¬½ÓsocketµÄ¿Í»§¶ËºÍ·þÎñ¶ËÒÔ¼°ÃæÏòÁ¬½ÓsocketµÄ·þÎñ¶Ëͨ¹ýµ÷Óà bindº¯ÊýÀ´ÅäÖñ¾µØÐÅÏ¢¡£
Bindº¯Êý½«socketÓë±¾»úÉϵÄÒ»¸ö¶Ë¿ÚÏà¹ØÁª£¬ËæºóÄã¾Í¿ÉÒÔÔڸö˿ڼàÌý·þÎñÇëÇó¡£Bindº¯ÊýÔÐÍΪ£º
¡¡¡¡ int bind(int sockfd,struct sockaddr *my_addr,
Ïà¹ØÎĵµ£º
×î½üÔÚÑо¿ÔõôÈÃDiscuz!È¥Ó¦ÓÃMemcacheÈ¥×öһЩÊÂÇ飬¼Ç¼ÏÂMemcache°²×°µÄ¹ý³Ì¡£
LinuxÏÂMemcache·þÎñÆ÷¶ËµÄ°²×°
·þÎñÆ÷¶ËÖ÷ÒªÊÇ°²×°memcache·þÎñÆ÷¶Ë£¬Ä¿Ç°µÄ×îа汾ÊÇ memcached-1.3.0 ¡£
ÏÂÔØ£ºhttp://www.danga.com/memcached/dist/memcached-1.2.2.tar.gz
ÁíÍ⣬MemcacheÓõ½ÁËlibeventÕâ¸ö¿âÓÃÓÚSocketµÄ´¦Àí£ ......
1,»ù±¾²Ù×÷
Ìí¼ÓÓû§
useradd
ɾ³ýÓû§
userdel
±ä¸üÃÜÂë
passwd username
²é¿´Ö´ÐÐÖнø³Ì
ps aux
ps auxf
ps
l ³¤¸ñʽÊä³ö£»
u °´Óû§ÃûºÍÆô¶¯Ê±¼äµÄ˳ÐòÀ´ÏÔʾ½ø³Ì£»
j ÓÃÈÎÎñ¸ñʽÀ´ÏÔʾ½ø³Ì£»
f ÓÃÊ÷ÐθñʽÀ´ÏÔʾ½ø³Ì£»
......
¶ÔÓÚ¶¯Ì¬Á´½Ó¿âºÍ¾²Ì¬Á´½Ó¿âµÄ¸ÅÄîÒÔ¼°Á´½Ó·½Ê½²»ÔÙÀÛ׸¡£Ö±½Ó¿ªÊ¼ÉÏ´úÂëºÍ½øÐбàÒë¡£-__-||¡£
´úÂëºÜ¼òµ¥£¬ºáÊú¾ÍÈý¸öµ±¼ÒµÄ¡£
¿âÍ·Îļþcorey.hpp:
#ifndef LIBRARY_H
#define LIBRARY_H
void add(int,int,int*);
#endif
¿âʵÏÖÎļþcorey.cpp
#include "corey.hpp"
void add(int a,int b,int *c){
int total=a ......
Ä¿Ç°£¬GCC¿ÉÒÔÓÃÀ´±àÒëC/C++¡¢FORTRAN¡¢JAVA¡¢OBJC¡¢ADAµÈÓïÑԵijÌÐò£¬¿É¸ù¾ÝÐèҪѡÔñ°²×°Ö§³ÖµÄÓïÑÔ¡£±¾ÎÄÒÔÔÚRedhat LinuxÉÏ°²×°GCC4.1.2ΪÀý(ÒòÔÚÏîÄ¿¿ª·¢¹ý³ÌÖÐÒªÇóʹÓã¬Ã»ÓÐÓÃ×îеÄGCC°æ±¾)£¬½éÉÜGCCµÄ°²×°¹ý³Ì¡£
°²×°Ö®Ç°£¬ÏµÍ³ÖбØÐëÒªÓÐcc»òÕßgccµÈ±àÒëÆ÷£¬²¢ÇÒÊÇ¿ÉÓõģ¬»òÕßÓû·¾³±äÁ¿CCÖ¸¶¨ÏµÍ³ÉϵıàÒëÆ÷¡£È ......
¼¸¸öcpu
more /proc/cpuinfo |grep "physical id"|uniq|wc -l
ÿ¸öcpuÊǼ¸ºË£¨¼ÙÉècpuÅäÖÃÏàͬ£©
more /proc/cpuinfo |grep "physical id"|grep "0"|wc -l
cpuʹÓÃÂÊ
vmstat
ÍƼöС¹¤¾ßnmon£¨aixºÍlinux¶¼ÓУ©
topºó°´Êý×Ö1,¶à¸öcpuµÄ»°»áÏÔʾ¶à¸ö
fdisk -l¿ÉÒÔ¿´µ½¶à¸öÎïÀíÓ²ÅÌ£¬×öÁËÓ²raidÖ»ÄÜ¿´µ½Ò»¸öӲŠ......