Linux socket±à³Ì
ʲôÊÇ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, int
Ïà¹ØÎĵµ£º
http://content.hccfl.edu/pollock/AUnix1/FilePermissions.htm
http://en.wikipedia.org/wiki/Sticky_bit
http://www.anqn.com/os/linux/2009-03-01/a09108173.shtml
7.4.3 ÎļþÌØÊâȨÏÞ£ºSUID/SGID/Sticky Bit
Ç°ÃæÒ»Ö±Ìáµ½ÎļþµÄÖØÒªÈ¨ÏÞ£¬¾ÍÊÇrwxÕâ3¸ö¶Á¡¢Ð´¡¢Ö´ÐеÄȨÏÞ¡£µ«ÊÇ£¬Ôõô /tmpȨÏÞÓÐÐ©Ææ¹Ö ......
tar [-cxtzjvfpPN] ÎļþÓëĿ¼ ....
²ÎÊý£º
-c £º½¨Á¢Ò»¸öѹËõÎļþµÄ²ÎÊýÖ¸Áî(create µÄÒâ˼)£»
-x £º½â¿ªÒ»¸öѹËõÎļþµÄ²ÎÊýÖ¸Á
-t £º²é¿´ tarfile ÀïÃæµÄÎļþ£¡
ÌØ±ð×¢Ò⣬ÔÚ²ÎÊýµÄÏ´ïÖУ¬ c/x/t ½öÄÜ´æÔÚÒ»¸ö£¡²»¿Éͬʱ´æÔÚ£¡
ÒòΪ²»¿ÉÄÜͬʱѹËõÓë½âѹËõ¡£
-z £ºÊÇ·ñͬʱ¾ßÓÐ gzip µÄÊôÐÔ£¿Ò༴ÊÇ·ñÐ ......
ÎÒÃÇÒ»°ãʹÓÓdate -s”ÃüÁîÀ´ÐÞ¸Äϵͳʱ¼ä¡£±ÈÈ罫ϵͳʱ¼äÉ趨³É2010Äê3ÔÂ5ÈÕµÄÃüÁîÈçÏ¡£
#date -s 03/05/10
½«ÏµÍ³Ê±¼äÉ趨³ÉÖÐÎç8µã52·Ö0ÃëµÄÃüÁîÈçÏ¡£
#date -s 08:52:00
×¢Ò⣬ÕâÀï˵µÄÊÇϵͳʱ¼ä£¬ÊÇlinuxÓɲÙ×÷ϵͳά»¤µÄ¡£
ÔÚϵͳÆô¶¯Ê±£¬Linux ......
void __init mem_init(void)
{
unsigned int codepages, datapages, initpages;
int i, node;
codepages = &_etext - &_text;//Äں˴úÂë¶ÎµÄ´óС¡£
datapages = &_end - &__data_start;//ÄÚºËÊý¾Ý¶ÎµÄ´óС¡£
initpages = &__init_end - &__i ......