µ±Ç° UNIX ÉϵÄÆóÒµ¼¶Èí¼þ´ó²¿·Ö¶¼ÊÇΪÁËӺϴó¹«Ë¾µÄÉÌÎñÐèÒª¡£Òò¶øËü±ØÐëÖ§³ÖгöÏֵļ¼Êõ£¬²¢ÄÜ˳ӦѸËÙ·¢Õ¹µÄÊг¡³±Á÷£¬±ÈÈçÇ¿´ó¶øÁé»îµÄ Linux ²Ù×÷ϵͳµÄ´óÁ¿Ê¹Óá£ÓÉÓÚÕâÖÖÈí¼þ´ó²¿·ÖÊÇ´óÐ͵ġ¢¶àÏ̵߳ĶøÇÒÊǶà½ø³ÌµÄ£¬ËùÒÔ½«ÆäÒÆÖ²µ½ Linux ÃæÁÙ×ÅÌôÕ½¡£Í¨¹ý±¾ÎÄ£¬¿ÉÒÔ»ñµÃÔÚ°Ñij¸öÆóÒµ¼¶Èí¼þÕæÕýÒÆÖ²µ½ Linux µÄ¹ý³ÌÖеõ½µÄÇåµ¥ºÍ½¨Òé¡£
µ±Ç°ÉÌÎñ IT ÐÐΪµÄÒ»¸öʵ¼ÊÇéÐÎÊÇ£¬ºÜ¶à×éÖ¯ ÕýÔÚ ½« IT תÒƵ½ Linux£¬ÒòΪËü¾ß±¸ÁË×÷Ϊϵͳƽ̨µÄÁé»îÐÔÓëÎȶ¨ÐÔ¡£ÁíÒ»¸öʵ¼ÊÇéÐÎÊÇ£¬ÉáÆúÏÖÓÐÆóÒµ¼¶Èí¼þµÄ´ú¼Û¹ýÓڸ߰º¡£ÕâÁ½ÖÖÇéÐξ³£Í¬Ê±³öÏÖ£¬µ«¹Ø¼üÊÇÒª½â¾öËüÃÇ¡£
½«ÆóÒµ¼¶Èí¼þÒÆÖ²µ½ Linux ¿ÉÄÜ»áÃæÁٺܶàÓÐȤµÄÌôÕ½¡£Ã¿Ò»¸ö²½Ö趼±ØÐëҪСÐÄ ---- ´Ó×ö³öÉè¼ÆÑ¡Ôñ£¬µ½»ñµÃ¿ÉÓõĹ¹½¨ÏµÍ³£¬ÔÙµ½×îÖյõ½ÒªÔÚ Linux ÉÏÖ´ÐеÄÕë¶ÔÌض¨ÏµÍ³µÄ´úÂë¡£
±¾ÎÄ»ùÓÚÎÒÔÚ RHEL ºÍ SLES ·¢Ðа汾ÖУ¨ÔÚ Intel ºÍ IBM eServer zSeries Ìåϵ½á¹¹ÉÏÔËÐÐ C Ó¦ÓóÌÐò£©Ëù»ñµÃµÄ¾Ñ飬µ«ÊÇÕâЩ¾ÑéͬÑùÊÊÓÃÓÚÆäËû·¢Ðа汾¡£ÎÒ½«ÌÖÂÛһЩÔÚ Linux ÉÏÔËÐÐÄúµÄÓ¦ÓóÌÐòµÄ¼Æ»®ºÍÐèÒª¿¼Âǵļ¼ÊõÎÊÌ⣬°üÀ¨ÒÔÏÂÄÚÈÝ£º
»ñµÃ¿ÉÓõĹ¹½¨ÏµÍ³¡£
È·¶¨¿ÉÐеIJÙ×÷»·¾³¡£
¾¡Á¿¼õÉÙÔÚ¶àÖÖÌåϵ½á¹¹ÉϹ¹½¨²úÆ·ËùͶÈëµÄ¾«Á¦£¨Linux ÐèÒªµÃµ½ÄÇЩÌåϵ½á¹¹µÄÖ§³Ö£©¡£
È·¶¨Ìض¨Ìåϵ½á¹¹µÄ±ä»¯£¬±ÈÈç »¥³âËø¶¨£¨mutex locking£©¡£
ʹÓÃеıàÒëÆ÷£¬¾¡¿ÉÄÜΪ¶àÖÖÌåϵ½á¹¹Î¬³ÖÒ»¸öÏ꾡µÄͨÓôúÂë»ù£¨code base£©¡£
È·¶¨ IPC »úÖÆ¡£
Ñ¡ÔñºÏÊʵÄÏß³ÌÄ£ÐÍ¡£
°´ Linux Ìض¨µÄÖ¸µ¼·½Õë¸Ä±ä°²×°ºÍ°ü×°·½Ê½¡£
È·¶¨ÐźÅÑ¡Ïî¡£
Ñ¡Ôñ½âÎöÆ÷¹¤¾ß£¬±ÈÈç lex/yacc¡£
×ö³öÈ«¾Ö»¯Ñ¡Ôñ¡£
»ñµÃ¿ÉÓõĹ¹½¨ÏµÍ³
Ö§³Ö¶à¸öƽ̨µÄ²úƷͨ³£ÒªÇóÖ¸¶¨½«ÒªÔËÐвúÆ·µÄ¾ßÌå²Ù×÷ϵͳ¡£ÕâÖÖͨÓôúÂëͨ³£±£´æÔÚԴĿ¼½á¹¹µÄ¶ÀÁ¢´úÂë×é³É²¿·ÖÖС£
ÀýÈ磬Ìض¨ÓÚ²Ù×÷ϵͳµÄ´úÂë¹æ»®¿ÉÄÜÊÇÀàËÆÕâÑù£º
src/operating_system_specific_code_component/aix £¨ÓÃÓÚ AIX£©¡£
src/operating_system_specific_code_component/solaris £¨ÓÃÓÚ Solaris£©¡£
src/operating_system_specific_code_component/UNIX £¨ÓÃÓÚÆäËûÖÖÀàµÄ Unix£©¡£
ÏÂͼ´Ó¸üΪ¡°Í¼Ðλ¯¡±µÄ½Ç¶ÈչʾÁËÌض¨ÓÚ²Ù×÷ϵͳµÄ´úÂë¹æ»®¡£
ͼ 1. ´úÂë×éÖ¯¹æ»®
»ñµÃ Linux ¹¹½¨ÏµÍ³
Ê×ÏÈ£¬ÄúÓ¦¸ÃΪÌض¨ÓÚ Linux µÄ´úÂë´´½¨Ò»¸öĿ¼£¬²¢½«À´×Ôij¸öƽ̨µÄÎļþÖÃÓÚÆäÖС£µ±ÄúΪ Linux ÒýÈëÁËÒ»¸öÐÂĿ¼ºó£¬¹æ»®¿ÉÄÜÀàËÆÕâÑù£º
src/operating_system_specific_code_component/linux£¨ÓÃÓÚ Linux£©
È»ºóÕ⽫ÈÃÎÒÃǵõ½Ò»¸öÀàËÆÈçϵÄеĴúÂë¹æ»®¡£
Mrlinux ÓÚ 2005-12-17 08:57:07·¢±í:
±í 1. ´Ó pthreads draft 4 µ½ 10 µ÷ÓÃËù·¢ÉúµÄ±ä»¯
pthreads draft 4 pthreads draft 10
pthread_setcancel(CANCEL_ON) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL)
pthread_setcancel(CANCEL_OFF) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL)
pthread_setasynccancel(CANCEL_ON) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL)
pthread_setasynccancel(CANCEL_OFF) pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)
pthread_getspecific(key, value) *value = pthread_getspecific(&key)
¿ÉÑ¡µÄÏß³ÌÄ£ÐÍ°üÀ¨ native Linux threads ºÍ Native POSIX Thread Library£¨NPTL£©ÊµÏÖ£¬ºóÕßΪ Linux ÖеÄÏß³ÌÌṩÁËÓë POSIX ¼æÈݵÄʵÏÖ¡£Linux Äںˣ¨´Ó 2.5 °æ±¾Æð£©ÒѾµÃµ½Ð޸ģ¬¾ß±¸ÁË POSIX ¼æÈÝÖ§³Ö¡£ÔÚ SLES9 ÖÐ NPTL ÊÇ¿ÉÓõġ£Red Hat ÒѾΪ RHEL3£¨Ëü»ùÓÚ Linux 2.4 Äںˣ©·´ÏòÒÆÖ²£¨backport£©ÁË NPTL Ö§³Ö¡£RHEL 3 ¼ÈÖ§³Ö NPTL Ò²Ö§³Ö native Linux threads¡£¿ÉÒÔͨ¹ýÉèÖû·¾³±äÁ¿ LD_ASSUME_KERNEL=2.4.1 Çл»µ½ native Linux threads£¬µ«ÊǺܶàÌṩÉ̶¼ÒѾ½«ËûÃǵÄÈí¼þÒÆÖ²µ½ÁËÖ§³Ö NPTL µÄ RHEL3 ÉÏ¡£
ʹÓà native Linux threads µÄÖ÷ÒªÕÏ°ÔÚÓÚÒÔÏ·½Ã棺
×ÓÏß³Ì SIGCHILD »áË͵½Ï̶߳ø²»Êǽø³Ì£¨·Ç POSIX ÐÐΪ£©¡£
getpid() ±»ÆÆ»µ ---- »ñµÃ¹¹³É½ø³ÌµÄÒ»×éÏß³ÌµÄ pid ·Ç³£À§ÄÑ¡£
ÔÚij¸öÏß³ÌÖиıäÓû§±êʶ£¬²»Äܽ«´Ë±ä»¯Ó¦ÓÃÓÚ½ø³ÌÖеÄËùÓÐÏ̡߳£
¼òÑÔÖ®£¬Ã¿¸öÏ߳̿´ÆðÀ´¶¼ÏñÊÇÒ»¸öµ¥¶ÀµÄ½ø³Ì£¨ÆäÐÐΪµÄijЩ·½ÃæÒ²ÊÇÈç´Ë£©¡£
Äں˷½ÃæÒ²ÓÐÎÊÌ⣺
ÓµÓгɰÙÉÏǧÏ̵߳Ľø³Ì»áÁî /proc Îļþϵͳ¼¸ºõ²»ÄÜʹÓá£Ã¿Ò»¸öÏ̶߳¼±íÏÖΪһ¸ö¶ÀÁ¢µÄ½ø³Ì¡£
ÐźÅʵÏÖµÄÎÊÌâÖ÷ÒªÔÚÓÚȱÉÙÄÚºËÖ§³Ö¡£SIGSTOP µÈרÓÃÐźűØÐëÓÉÄÚºËÀ´ÎªËùÓÐÏ̴߳¦Àí¡£
ʵÏÖͬ²½ÔÓïʱ¶ÔÐźŵĴíÎóʹÓûá´øÀ´¸ü¶àÎÊÌâ¡£·¢ËÍÐźŲ»ÊÇÈ·±£Í¬²½µÄÃ÷ÖÇ·½·¨¡£
ÁíÒ»·½Ã棬ʹÓà NPTL£º
ÔÚ×îеķ¢Ðа汾ÖУ¨Linux 2.6 ÒԺ󣩣¬ÐźÅÎÊÌâËƺõÒѾ±»½â¾ö¡£ÏÖÔÚ£¬ÐźſÉÒÔ×÷Ϊһ¸öÕûÌå·¢Ë͸ø½ø³Ì¡£
ÒѾʵÏÖÁË futex£¨¿ìËÙÓû§¿Õ¼ä»¥³âÌ壨fast userspace mutex£© ÊÇÔÚ Linux ÉÏʵÏÖËø¶¨ºÍ¹¹½¨ semaphores ºÍ POSIX mutexes µÈ¸ß²ã´ÎËø¶¨³éÏóµÄ»ù±¾¹¤¾ß£©£¬ËüÄÜÁîµ÷ÓÃÕßÔÚÄÚºËÖеȴý²¢¿ÉÒÔ±»ÏÔʽµØ»½ÐÑ¡£ÕâÑù£¬PTHREAD_PROCESS_SHARED ºÍ½ø³Ì¼ä POSIX ͬ²½ÔÓï¿ÉÒÔ±»ÊµÏÖ£¬¶øÇÒÏÖÔÚ¿ÉÓá£
ËüʹÓà 1:1 Ä£ÐÍ£¨Ã¿¸öÓû§¼¶Ïß³ÌÓÐÒ»¸öµ×²ãµÄÄÚºËỊ̈߳©£¬²¢ÇÒ¿ÉÒÔÇÀÕ¼£¨ÄÚºËÏ߳̿ÉÒÔ±»ÇÀÕ¼£©¡£
ËüÊÊÓÃÓÚ¼«ÏûºÄ I/O ºÍ CPU µÄÓ¦ÓóÌÐò¡£
ÆäÄ¿±êÊÇʵÏÖ°Ù·ÖÖ®°Ù POSIX ¼æÈÝ¡£
»ùÓÚ¸÷¸ö·¢Ðа汾µÄ¸Ä½ø£¬Ê¹ÓÃÖ§³Ö NPTL µÄ Linux °æ±¾Í¨³£ÊÇÃ÷Öǵġ£
Îļþϵͳ£¬Ê¹ÓòÎÊý£¬Õ»
ÔÚÒÆÖ²¹¤×÷ÖУ¬ÎÒµÄС×é·¢ÏÖÁËÐí¶à±ä»¯¶àÑùµÄÊÂÇ飬ÓÉÓÚËüÃÇÏà¶Ô½ÏΪ¼òµ¥£¬ÔÚ´ËÎÒ½«¼¯ÖнøÐнéÉÜ¡£
¶ÔÎļþϵͳµÄÖ§³Ö
Èç¹ûÄúµÄÓ¦ÓóÌÐòÐèҪʹÓüǼÈÕÖ¾ºÍдÈëÊý¾ÝÎļþµÈ¹¤¾ß£¬ÄÇô£¬Ïà¶ÔÓÚÔʼµÄ I/O£¬»ùÓÚÎļþϵͳµÄÖ§³Ö¸ü±ãÓÚ°²×°¡¢ÅäÖú͹ÜÀí¡£
ϵͳʹÓòÎÊý
ºÃÏñ²»´æÔÚÊÕ¼¯²ÎÊýÐÅÏ¢£¨±ÈÈçÄÚ´æ¶ÑµÄʹÓ㩵ÄÖ±½ÓµÄϵͳµ÷Óá£ÒªÈ·¶¨´ËÀà²ÎÊý£¬ÐèÒªÀûÓà /proc ÎļþϵͳµÄÖ§³Ö¡£
Stackwalk
µ±Ç°£¬Ö»ÓÐÔÚ Intel Ìåϵ½á¹¹ÉÏÖ§³Ö pstack µÈµ÷Óã»ÔÚÆäËûÌåϵ½á¹¹ÉϵÄÖ§³Ö»¹ÔÚ¿ª·¢µÄ¹ý³ÌÖС£ÒªÍ¨¹ý³ÌÐò½øÐÐÕ»µÄ×·×Ù£¬³ÌÐòÔ±¿ÉÄܲ»µÃ²»Ê¹Óà ABI ¶¨ÒåΪÉÐδµÃµ½Ö§³ÖµÄÌåϵ½á¹¹È¥ÊµÏÖËûÃÇ×Ô¼ºµÄ°æ±¾¡£
ÁíÒ»¸öÑ¡ÔñÊÇʹÓûùÓÚ gdb µÄ½Å±¾À´»ñµÃÕ»µÄÐÅÏ¢¡£²úÆ·µÄ¸ß¿Éά»¤ÐÔͨ³£ÒªÓõ½Õ»µÄÐÅÏ¢¡£ gdb ¸üΪ±ê×¼»¯£¬¿É¿ç²»Í¬Ìåϵ½á¹¹ºÍ·¢Ðа汾ʹÓá£
ÄÚºËÓ³ÉäºÍ¹²ÏíÄÚ´æ¶ÎµÄʹÓÃ
Èç¹ûÓ¦ÓóÌÐòʹÓù²ÏíÄÚ´æ¶Î£¬ÄÇô±ØÐëҪСÐĵØÉèÖù²ÏíÄÚ´æ¶ÎµÄÆðʼλÖ㬳ý·ÇÓû§ÏëÒÀÀµÏµÍ³ËùÌṩµÄ³õʼµØÖ·¡£ÁíÍ⣬²»Í¬µÄÌåϵ½á¹¹¾ßÓв»Í¬µÄÄÚ´æÓ³ÉäÖ§³Ö£»¹²ÏíÄÚ´æ¿ÉÓõÄÇøÓòÒ²¿ÉÄܲ»Í¬¡£
ÀýÈ磬ÔÚ Intel Ìåϵ½á¹¹ÖУ¬Ã¿¸ö½ø³Ì½«µ×²¿ËÄ·ÖÖ®ÈýµÄµØÖ·¿Õ¼ä·ÖÅä¸øÓû§ÇøÓò£»¶¥²¿²¿·Ö·ÖÅä¸øÄںˡ£ÕâÒâζ×ÅÈκΠLinux ½ø³ÌËùÕ¼µÄÈ«²¿ÄÚ´æ×î¶à¿É´ï 2 GB£¨390£©»òÕß 3 GB£¨Intel£©¡£Õâ¸ö×ÜÊý±ØÐë°üÀ¨Îı¾¡¢Êý¾ÝºÍÕ»¶Î£¬ÔÙ¼ÓÉÏËùÓеĹ²ÏíÄÚ´æÇøÓò¡£ÔÚ Linux/390 ÉÏ£¬ÓÃÓÚ¹²ÏíÄÚ´æµÄÇøÓò´Ó 0x50000000 ¿ªÊ¼£¬²¢ÇÒ±ØÐëÔÚ 0x7fffa000 ֮ǰ½áÊø¡£Èç¹ûÄúÏëÒªÔÚÓ¦ÓóÌÐò½«ÒªÖ§³ÖµÄËùÓÐÌåϵ½á¹¹Éϱ£³ÖͨÓõÄÆðʼµØÖ·£¬ÄÇôÔÚÈ·¶¨ÄǸöµØַ֮ǰ±ØÐ뿼ÂÇËùÓеÄÌåϵ½á¹¹¡£
ÐźÅ
ÓëÆäËû Unix ƽ̨Ïà±È£¬ÐźŠ---- ·¢ËÍÆô¶¯ºÍֹͣij¸ö´«Êä»òÕßÆäËû²Ù×÷µÄ¿ØÖÆÐźŠ---- ²¢Ã»ÓÐÌ«´óµÄ²»Í¬£¬Ö»ÊÇÐźźÅÂë¿ÉÄܲ»Ò»Ñù£¬»òÕßÓÐЩÐźÅÔÚijЩ·¢Ðа汾£¨RHEL AS 3£©Éϲ»¿ÉÓ㬱ÈÈç SIGEMT¡££¨Òª»ñµÃ¹ØÓÚ Solaris ºÍ Linux Ö®¼äÐźÅÇø±ðµÄÏêϸ×ÊÁÏ£¬Çë²ÎÔÄ ²Î¿¼×ÊÁÏ ²¿·ÖµÄ²Î¿¼ÎÄÏס££©
ÅäÖÃÄں˲ÎÊý
³ÌÐòÔ±¿ÉÄܻᱻҪÇóÈ¥µ÷ÕûÄں˵ÄijЩ²ÎÊý£¬ÒÔʹµÃÓ¦ÓóÌÐòÄܹ»ÔÚÔËÐÐÆÚ½øÐе÷Õû¡£Èç¹ûÊÇÄÇÑù£¬ÔòÐèÒª¿¼ÂǵÄһЩÖØÒª²ÎÊý°üÀ¨ threads-max£¨Ã¿¸ö½ø³ÌµÄ×î´óÏß³ÌÊý£©¡¢shmmax¡¢ msgmax µÈµÈ¡£ÔÚ /proc/sys/kernel ÖÐÅäÖòÎÊýÁÐ±í¡£¿ÉÒÔʹÓà /sbin/sysctl ϵͳµ÷ÓÃÀ´ÅäÖÃÕâЩ²ÎÊý¡£Èç¹ûÄúÕýÔÚÒÆֲij¸ö´óÐ͵ĶàÏß³ÌÓ¦ÓóÌÐò£¬ÄÇô threads-max ²ÎÊý¿ÉÄÜ»áÓÈÆäÖØÒª¡£
lex/yacc µÈ½âÎöÆ÷¹¤¾ß
Òª×öºÃ×¼±¸£¬ÄúÔÚ AIX »òÕß Solaris ÉÏËù±àдµÄÓ﷨ijЩ²¿·Ö¿ÉÄܲ»ÄÜÖ±½ÓÔÚ Linux ÉÏʹÓá£ÀýÈ磬 yylineno£¨Ò»¸ö²»ÕýʽµÄ lex ɨÃèÆ÷ÄÚ²¿±äÁ¿£©µÈijЩ±äÁ¿Ä¬ÈÏÇé¿öÏ¿ÉÄܲ»ÄÜÖ±½ÓÔÚ Linux ÉÏʹÓá£ÏÂÃæµÄ´úÂëƬ¶Ï¿ÉÒÔ¼ì²é yylineno ÊÇ·ñµÃµ½ÁËÖ±½ÓµÄÖ§³Ö¡£´ò¿ªÒ»¸öÃûΪ a.l µÄÎļþ£¨ÆäÄÚÈÝÈçÏ£©£º
%{
%}
%%
%%
È»ºóÊäÈë lex a.l¡£ÔÚ lex.yy.c ÖÐËÑË÷¡°yylineno¡±¡£Èç¹ûÄǸö±äÁ¿²»¿ÉÓã¬ÓÐÁ½ÖÖ¿ÉÄܵÄÖ§³Ö yylineno µÄ½â¾ö·½°¸£¬¼´ÔÚ Linux ÖÐΪ lex ʹÓà -l Ñ¡Ï»»¾ä»°Ëµ£¬Ö´ÐÐ lex -l a.l£©£¬»òÕß½«´úÂëÐÞ¸ÄΪÈçÏÂËùʾ£º
%{
%}
%option yylineno
%%
%%
ijЩ·¢Ðа汾£¨±ÈÈç SLES 9£©Ä¬Èϲ¢Ã»Óи½´ø yacc£¬µ«¸½´ø bison¡£Èç¹ûÐèÒª yacc£¬¿ÉÄܵÃÈ¥ÏÂÔØËü¡£
È«¾Ö»¯ÎÊÌâ
ÔÚ Linux ÉÏijЩ´úÂëÒ³µÄÃüÃû¿ÉÄܻ᲻ͬ¡£ÀýÈ磬AIX É쵀 IBM-850 ÔÚ Linux ÉÏ¿ÉÄÜÁíÍâÃüÃûΪ ibm850£¬ ISO8859-1 ¿ÉÄܱ»ÁíÍâÃüÃûΪ ISO-8859-1¡£Èç¹ûÓ¦ÓóÌÐòÏûÏ¢±à¼ÒÀÀµÓÚÕâЩ´úÂëÒ³ÖеÄijЩ£¬¶øÇÒÐèÒª´úÂëҳת»»£¬Ôò¿ÉÄܱØÐëÐ޸Ľű¾£¨Ê¹Óà iconv ¹¤¾ß¿ÉÒÔÍê³É£©¡£ÔÚ Linux ÉÏ£¬ja_Jp¡¢en_US µÈ´ó²¿·Ö³£¼ûµÄλÖö¼¿ÉÓá£
°²È«ÐÔ¿¼ÂÇ
ÔÚеķ¢Ðа汾ÖУ¨RHEL AS 3£©£¬»ùÓÚÌ×½Ó×ÖµÄͨÐÅĬÈϵõ½Á˱£»¤£¬ËùÒÔ£¬Èç¹ûÄúÕýÔÚʵÏÖ»ùÓÚ IP µÄ·þÎñÆ÷£¬Æä½ø³ÌÒª¼àÌýij¸öÌض¨µÄ¶Ë¿Ú£¬ÄÇôÄúÓ¦¸ÃÏò iptables ÖÐÌí¼ÓеķþÎñ¡£ iptables ÓÃÓÚ½¨Á¢¡¢Î¬»¤ºÍ¼ì²é Linux ÄÚºËÖÐµÄ IP Êý¾Ý°ü¹ýÂËÆ÷¹æÔò±í¡£
ÀýÈ磬Ê×ÏÈÄú¿ÉÄܱØÐëÌí¼ÓÒ»¸öеÄÁ´£¬±ÈÈç /sbin/iptables -N RH-Firewall-1-INPUT£¬È»ºóÔÚÄǸöÁ´ÖÐÌí¼ÓеķþÎñ£¬ÏñÕâÑù£ºiptables -I RH-Firewall-1-INPUT -s 0/0 -i eth0 -m state --state NEW -p TCP --dport 60030 -j ACCEPT £¨ÐµÄÄ¿±ê¶Ë¿Ú 60030 ±»Ó³Éäµ½ /etc/services ÖеÄij¸ö·þÎñ£©¡£
¶¨Î»°²×°µÄÈí¼þ°üºÍ±äÁ¿Êý¾Ý
×ñÑ Linux ÉçÇøËùÌá³öµÄ´ò°ü£¨packaging£©ÖÒ¸æÊÇÒ»¸öºÃÖ÷Òâ ---- ÕâЩÖÒ¸æÓÐÖúÓÚ·ÀÖ¹ /opt ÖеĴúÂëºÍ /var ÖеÄÓ¦ÓóÌÐòÊý¾Ý³öÏÖ»ìÂÒ¡£ÕâЩÖҸ潨Ò齫ÌṩÉÌÓëÈí¼þ°üÃû³Æ°üº¬ÔÚ´æ·Å´úÂëºÍÊý¾ÝµÄλÖá£×÷Ϊ˵Ã÷£¬¿¼ÂÇÏÂÃæµÄʾÀý¡£
¼ÙÉè IBM ¿ª·¢ÁËÒ»¸öÃûΪ¡°abc¡±µÄÓ¦ÓóÌÐò¡£ÄǸöÈí¼þ°üÀíÂÛÉÏÓ¦¸Ã°²×°ÔÚ /opt/ibm/abc ÖС£Ïà¹ØµÄÊý¾ÝÓ¦¸ÃλÓÚ /var/opt/ibm/abc ÖУ¬¶ø²»ÊǼòµ¥µÄλÓÚ /var ÖС£
²âÊÔ
½«Ò»¸öвúÆ·ÒÆÖ²µ½ÐµÄƽ̨£¬ÐèÒª¶ÔÄǸö²úÆ·½øÐÐÏ꾡µÄ²âÊÔ¡£ÐèÒªÌرð×¢ÒâµÄ·½Ãæ°üÀ¨½ø³Ì¼äͨÐÅ¡¢´ò°ü¡¢ÏµÍ³¼äͨÐÅ£¨AIX Óë Linux£¬»òÕß Solaris Óë Linux Ö®¼äµÄ¿Í»§»ú-·þÎñÆ÷£©¡¢Ò»Ö´洢£¨³öÓÚ×Ö½Ú´ÎÐòµÄÒòËØ£©¡¢Êý¾Ý±ä»»¸ñʽ£¬µÈµÈ¡£
ÍⲿÎĵµ¿ÉÄܻᷢÉú±ä»¯£¬ËùÒÔÓ¦¸Ã½øÐг¹µ×µÄÎĵµ¸´²é¡£
ÒÆÖ²µ½ Linux ²âÊÔÓÃÀýÐèÒªÒÀÕÕ¿ª·¢¹¤×÷Êʵ±µØ½×¶Î»¯¡£ÔÚ¿ªÊ¼½øÐÐÍêÈ«²úÆ·²âÊÔ֮ǰ£¬Ó¦¸ÃÏȲâÊÔһЩ¿É½»¸¶Ê¹ÓõÄÖмä²úÆ·¡£Õ⽫°ïÖúÄúÔÚ²úÆ·¿ª·¢µÄÔçÆڽ׶ÎÕÒ³öÎÊÌâ¡££¨ÒªÉîÈëÁ˽â¸ßЧͨÓòâÊÔ·½·¨£¬Çë²ÎÔÄ ²Î¿¼×ÊÁÏ ²¿·Ö¹ØÓÚ XP µÄ²Î¿¼ÎÄÏס££©
½áÊøÓï
ÔÚ±¾ÎÄÖÐÎÒ¼òµ¥Éæ¼°ÁËÒÆÖ²µÄ²»Í¬½×¶Î£¬°üÀ¨Õë¶Ô²»Í¬ OS ·¶Î§µÄÉè¼ÆÑ¡Ôñ¡¢´´½¨ºÏÊʵÄĿ¼½á¹¹¡¢´´½¨¹¹½¨ÏµÍ³¡¢Íê³É´úÂëÐ޸ģ¬ÒÔ¼°²âÊÔ¡£ÎÒҲǿµ÷ÁËÄÇЩÐèÒª¼¯Öо«Á¦¹Ø×¢µÄµØ·½£¬±ÈÈçÐźš¢¹²ÏíÄÚ´æ¡¢»¥³âÌåºÍÌõ¼þ±äÁ¿¡¢Ïß³ÌÒÔ¼°Ìض¨ÓÚÌåϵ½á¹¹µÄ±ä»¯¡£±¾ÎÄ»ùÓÚÔÚÏò Linux 2.6-based ϵͳÖÐÒÆÖ²´óÐ͵ĶàÏß³ÌÓ¦ÓóÌÐòʱËù»ñµÃµÄʵ¼Ê¾Ñ飬ÎÒÏ£ÍûÕâ¸öÇåµ¥ÄÜ°ïÖúÄú½Úʡʱ¼äºÍ¾«Á¦¡£
ÿ´ÎÒÆÖ²µÄϸ½Ú¶¼»á·¢Éú±ä»¯£¬µ«ÊÇÎÒËùÁоٵĻù±¾¸ÅÄ½áºÏÏÂÃæµÄ²Î¿¼ÎÄÏ×ÖеIJÄÁÏ£©½«Ê¹Äú¸üÈÝÒ×µØÍê³ÉÒÆÖ²µÄ¹ý³Ì¡£
Mrlinux ÓÚ 2005-12-17 08:56:41·¢±í:
ͼ 2. еĴúÂë×éÖ¯¹æ»®
¡£
ÖÐËùÌá¼°µÄ£º
directly; include instead."
¡£
-I¡£ -fPIC °ïÖúÉú³ÉλÖÃÎ޹شúÂ룬µÈ¼ÛÓÚ Solaris É쵀 -fPIC ¡£-ansi µÈ¼ÛÓÚ Solaris É쵀 -Xa¡£
-L -l¡£ -shared µÈ¼ÛÓÚ Solaris É쵀 -G¡£
-e entry_point -L -l¡£
-I -DCMP_x86
-I -DCMP_PSERIES¡£
ͨ³££¬Ó¦ÓóÌÐòµÄ´ó²¿·Ö´úÂëͨÓÃÓÚËùÓÐÖÖÀàµÄ Unix£¬Ò²¿ÉÓÃÓÚ Linux¡£¾Ñé±íÃ÷£¬¶ÔÓÚÌض¨ÓÚ Linux µÄ´úÂ룬Ê×ÏÈÑ¡ÔñÌض¨ÓÚ Solaris µÄÎļþ¿ÉÒÔ ×îС»¯ Ïò Linux ÒÆÖ²Ìض¨ÓÚƽ̨µÄ´úÂëËùÐèµÄ¾«Á¦¡£
È»ºó£¬ÐÞ¸Ä makefile ²¢ÒýÈëÌض¨ÓÚ Linux µÄÌõÄ¿£º
¶Ô½«ÒªÊ¹ÓõıàÒëÆ÷µÄ¶¨Òå
³ÌÐò¿â·¾¶
Ï߳̿â·¾¶
±àÒëÆ÷±ê¼Ç
°üº¬Îļþ·¾¶
Ô¤´¦Àí³ÌÐò±ê¼Ç
ÐèÒªµÄËùÓÐÆäËûÄÚÈÝ
Ô´ÎļþÖеĺܶà¸Ä¶¯Óë°üº¬Îļþ·¾¶µÄÐÞ¸ÄÓйØϵ¡£ÀýÈ磬ҪʹÓñäÁ¿ errno£¬ÐèÒªÃ÷È·µØ°üº¬
ÔÚ²»Ö±½Ó°üº¬Ìض¨ÓÚÌåϵ½á¹¹µÄ°üº¬Îļþ£¨¶øÊÇ°üº¬ÍƼöÎļþ£©µÄËùÓеط½£¬¶¼±ØÐëҪСÐÄ¡£ÀýÈ磬¾ÍÏñÔÚ
#ifndef _DLFCN_H
# error "Never use
#endif
ÄúÓ¦¸ÃСÐĵØʹÓÃָʾ·û -Dlinux »òÕßµ¥´Ê¡°linux¡±¡£Linux ÉϵÄÔ¤´¦Àí³ÌÐò½«µ¥´Ê¡°linux¡±·ÒëΪÊý×Ö 1¡£ÀýÈ磬Èç¹ûÎļþÖÐÓÐÒ»¸ö /home/linux ·¾¶£¬¶øÇÒʹÓà cpp À´¶Ô´ËÎļþ½øÐÐÔ¤´¦Àí£¬ÔòÊä³öÎļþÖеÄ·¾¶½«ÊÇ /home/1¡£ÎªÁ˱ÜÃâ·¢ÉúÕâÖÖÌæ»»£¬Ô¤´¦Àí³ÌÐòָʾ·û¿ÉÒÔÊÇÀàËÆÕâÑùµÄ£º /lib/cpp -traditional -Ulinux
ͨÓñàÒëÃüÁî
³ÌÐòԱͨ³£ËùʹÓõıàÒëÆ÷ÊÇ gcc¡£µäÐ͵ıàÒëÃüÁîÐпÉÄÜÀàËÆÕâÑù£º gcc -fPIC -D_GNU_SOURCE -ansi -O2 -c
¶ÔÓÚ¹²Ïí¶ÔÏ󣬵äÐ͵ÄÁ´½Óʱ¼äָʾ·ûÓ¦¸ÃÊÇ gcc -fPIC -shared -o
¶ÔÓÚÓµÓÐÈë¿ÚµãµÄ¿ÉÖض¨Î»¶ÔÏ󣬵äÐ͵Äָʾ·û¿ÉÄÜÊÇ gcc -fPIC -shared -o
ÔÚ¿ªÊ¼Ñ¡Ôñ×î¼Ñ²Ù×÷»·¾³Ö®Ç°£¬ÎÒ½«ÏÈ·ÖÎöÔÚÆäËûÌåϵ½á¹¹ÉϱàÒë´úÂëËùÉæ¼°µÄÎÊÌâ¡£
ÆäËûÌåϵ½á¹¹ÉϵıàÒë
ÁíÒ»¸öÐèÒª¿¼ÂǵÄÖØÒªÊÂÏîÊÇ£¬³ÌÐòÔ±Ó¦¸ÃÄܹ»ÈôúÂ뾡¿ÉÄÜÈÝÒ×µØÔÚÆäËûÌåϵ½á¹¹ÉϱàÒë¡£¹¹½¨ÏµÍ³Ó¦¸ÃΪÉæ¼°µÄÿÖÖÌåϵ½á¹¹×¼±¸µ¥¶ÀµÄ¶¨ÒåÎļþ¡£ÀýÈ磬ÓÃÓÚ x86 Ìåϵ½á¹¹µÄ±àÒëÆ÷ָʾ·ûÓ¦¸ÃÓÐ -DCMP_x86 ±ê¼Ç£¬ÓÃÓÚijЩÌض¨ÓÚ pSeries ·þÎñÆ÷É쵀 Linux µÄ´úÂëÓ¦¸ÃÓÐ -DCMP_PSERIES ָʾ·û¡£¶ÔÓÚÔÚ x86 Ìåϵ½á¹¹µÄϵͳÉϽøÐеıàÒ룬¾ßÌå¹¹½¨¶¨ÒåÎļþÖеıàÒëÃüÁîÐÐÀàËÆÈçÏ£º
gcc -fPIC -D_GNU_SOURCE -ansi -O2 -c
¶øÏÂÃæµÄ±àÒëÃüÁîÐÐÓÃÓÚÔÚ pSeries Ìåϵ½á¹¹ÉϽøÐеıàÒ룺
gcc -fPIC -D_GNU_SOURCE -ansi -O2 -c
-CMP_x86 ºÍ -CMP_PSERIES ¶¼ÊÇÓû§¶¨Òå±ê¼Ç£¬µ±³ÌÐòµÄÌض¨ÓÚ Linux µÄ´úÂ뽫ҪʹÓÃÌض¨ÓÚÌåϵ½á¹¹µÄ´úÂëʱ¶¼ÒªÊ¹ÓÃËüÃÇ¡£ÎҵľÑéÊÇ£¬´ó²¿·ÖÓÃÓÚ Linux µÄÓ¦ÓóÌÐò´úÂ붼ÊÇÓëÌåϵ½á¹¹Î޹صģ¬Ìض¨ÓÚÌåϵ½á¹¹µÄ´úÂë³öÏÖÔÚÐèÒª±àд»ã±à´úÂëµÄµØ·½¡£ÀýÈ磬Èç¹ûÄúҪʹÓñȽϣ¨compare£©ºÍ½»»»£¨swap£©Ö¸ÁîµÄʵÏÖÀ´¿ª·¢Ëø£¬ÄÇôÄú½«ÒªÊ¹ÓÃÌض¨ÓÚÌåϵ½á¹¹µÄ´úÂë¡£
´úÂëµÄ°²ÅÅÓ¦¸ÃʹµÃÔÚ´úÂë¹æ»®ÖÐÌض¨ÓÚ Linux µÄĿ¼ÄÚ²»´æÔÚÌض¨ÓÚÌåϵ½á¹¹µÄ×ÓĿ¼¡£ÎªÊ²Ã´£¿ÒòΪ Linux ÒѾΪÆÁ±ÎÌåϵ½á¹¹Ï¸½Ú×ö³öÁ˺ܶ๤×÷£¬Ó¦ÓóÌÐòµÄ³ÌÐòԱͨ³£²»Ó¦¸Ã¹ØÐÄÓ¦ÓóÌÐò½«ÒªÔÚÄÄÖÖÌåϵ½á¹¹Ö®ÉÏÈ¥±àÒ롣Ŀ±êÓ¦¸ÃÊÇ£¬ÒÔ×îÉٵľ«Á¦£¬¶Ô´úÂë¡¢´úÂë¹æ»®ºÍ makefile Îļþ½øÐÐ×îÉÙµÄÐ޸ģ¬¾Í¿ÉÒÔÁîΪÌض¨Ìåϵ½á¹¹Ëù±àдµÄ³ÌÐòÔÚÆäËûÌåϵ½á¹¹Éϱ»±àÒ롣ͨ¹ý±ÜÃâÔÚ linux Ŀ¼ÖгöÏÖÌض¨ÓÚÌåϵ½á¹¹µÄ×ÓĿ¼£¬¿ÉÒÔ´ó´ó¼ò»¯ makefile Îļþ¡£
linux ×ÓĿ¼ÖеÄÔ´ÎļþÖпÉÄÜ»áÓдøÓÐÔ¤´¦Àí³ÌÐòָʾ·ûµÄ´úÂëÐÎʽ£¬ÈçÏ£º
#ifdef CMP_x86
#elif CMP_PSERIES
#else
#error No code for this architecture in __FILE__
#endif
È·¶¨¿ÉÐеIJÙ×÷»·¾³
¼Æ»®²½ÖèµÄ¹Ø¼üÊÇÈ·¶¨Ó¦ÓóÌÐòÒªÒÆÖ²µ½ Linux µÄÄĸö·¢Ðа汾¡£ÄúÓ¦¸ÃÈ·±£¼Æ»®ÒÆÖ²µÄ³Ì¶ÈËùÐèÒªµÄËùÓÐÈí¼þ¶¼¿ÉÓá£ÀýÈ磬¿ÉÄܲ»ÄÜΪ Linux 2.6 ·¢Ðа汾·¢²¼Ä³¸öÖмä¼þ²úÆ·£¬ÒòΪÔڴ󲿷ֵäÐÍÅäÖÃÖÐËùʹÓõÄÒ»¸ö¹Ø¼üµÄµÚÈý·½Êý¾Ý¿âÔÚÄǸö·¢Ðа汾Éϲ»ÄÜÓá£×î³õÌṩµÄ²úÆ·»òÕßÓ¦ÓóÌÐò¿ÉÄܲ»µÃ²»¸ÄΪ»ùÓÚ Linux 2.4 ·¢Ðа汾¡£
Ó¦ÓóÌÐò½»»¥ËùÐèÒªµÄijЩÈí¼þ£¬Ò²¿ÉÄܲ¢²»ÊÇÔÚÓ¦ÓóÌÐòËùÃæÏòµÄËùÓз¢Ðа汾ºÍÌåϵ½á¹¹É϶¼¿ÉÓ᣶ÔËùÑ¡²Ù×÷»·¾³µÄ¿ÉÐÐÐÔ½øÐÐ×ÐϸÑо¿¡£
ÐèÒª¿¼ÂǵÄÁíÒ»¸öÎÊÌâÊÇ£¬Ó¦ÓóÌÐòÊÇ 32 λµÄ»¹ÊÇ 64 λµÄ£¬ËüÊÇ·ñÒªÓëÆäËûÒ²ÒÔ 32 λ»ò 64 λģʽÔËÐеĵÚÈý·½Èí¼þ¹²´æ¡£
Ìض¨ÓÚÌåϵ½á¹¹µÄ±ä»¯
Ó¦ÓóÌÐòÖÐÌض¨ÓÚÌåϵ½á¹¹µÄ´úÂëͨ³£¾ÖÏÞÓÚÉÙÊýµØ·½¡£ÔÚ±¾½ÚÎÒ½«¿¼ÂÇһЩʾÀý¡£
È·¶¨×Ö½Ú´ÎÐò£¨endian-ness£©
³ÌÐòÔ±²»±Øµ£ÐÄÊÇΪºÎÖÖÌåϵ½á¹¹±àд´úÂë¡£Linux ÔÚ /usr/include/endian.h Öиø³öÁËÈ·¶¨×Ö½Ú´ÎÐòµÄ;¾¶¡£Äú¿ÉÒÔʹÓÃÏÂÃæµÄµäÐÍ´úÂëƬ¶ÏÀ´È·¶¨²Ù×÷»·¾³ÊÇ big-endian »¹ÊÇ little-endian£»Äú¿ÉÒÔ·½±ãµØÉèÖþßÌåµÄ±ê¼Ç¡£
/* Are we big-endian? */
#include
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define MY_BIG_ENDIAN
#elif __BYTE_ORDER == __BIG_ENDIAN
#undef MY_BIG_ENDIAN
#endif
È·¶¨Õ»Ö¸Õë
¿ÉÒÔ±àдÄÚÁª³ÌÐò¼¯£¨inline assembly£©À´È·¶¨Õ»Ö¸Õë¡£
int get_stack(void **StackPtr)
{
*StackPtr = 0;
#ifdef CMP_x86
__asm__ __volatile__ ("movl %%esp, %0": "=m" (StackPtr) );
#else
#error No code for this architecture in __FILE__
#endif
return(0);
}
ʵÏֱȽÏÓë½»»»
ÕâÀïÊÇΪ Intel Ìåϵ½á¹¹ÊµÏֱȽÏÓë½»»»µÄÒ»¸öʾÀý¡£
bool_t My_CompareAndSwap(IN int *ptr, IN int old, IN int new)
{
#ifdef CMP_x86
unsigned char ret;
/* Note that sete sets a 'byte' not the word */
__asm__ __volatile__ (
" lock\n"
" cmpxchgl %2,%1\n"
" sete %0\n"
: "=q" (ret), "=m" (*ptr)
: "r" (new), "m" (*ptr), "a" (old)
: "memory");
return ret;
#else
#error No code for this architecture in __FILE__
#endif
}
Ñ¡Ôñ IPC »úÖÆ
¿ÉÑ¡µÄ ½ø³Ì¼äͨÐÅ£¨interprocess communication£©£¨IPC£©»úÖÆ ---- ÓÃÓÚÓ¦ÓóÌÐò¼äͨÐźÍÊý¾Ý¹²ÏíµÄ»úÖÆ ---- ͨ³£°üÀ¨Ê¹Óà Ðźš¢±àд¿É¼ÓÔصÄÄÚºËÀ©Õ¹ »òÕß Ê¹Óýø³Ì¹²ÏíµÄ»¥³âÌ壨mutex£©ºÍÌõ¼þ±äÁ¿¡£
ÐźÅÊÇ×îÈÝÒ×ʵÏֵģ¬µ«ÊÇÔÚ¶àÏ̻߳·¾³ÖбØÐëҪСÐÄ£¬ÒòΪÅÉÉúµÄËùÓÐÏ̶߳¼¾ßÓÐÀàËƵÄÐźÅÑÚÂ루signal mask£©¡£ÔÚ½ø³Ì½á¹¹µÄ½¨Ä£ÖУ¬Í¨³£Ó¦¸ÃÖ»ÓÐÒ»¸öÏß³ÌÀ´´¦ÀíÐźţ¬·ñÔòÐźžͿÉÄܱ»·¢Ë͵½ÈÎÒâµÄỊ̈߳¬µ¼Ö½á¹û¿ÉÄܻ᲻¿ÉÔ¤Öª¡£Ï߳̿ÉÄÜÊÇÓɲ»ÊÜÓ¦ÓóÌÐò¿ØÖƵÄÆäËû²ÎÓëʵÌåÔÚ½ø³ÌÖÐÅÉÉúµÄ£¬Õâ¸öÓ¦ÓóÌÐò¿ÉÄܲ»ÄÜ¿ØÖÆËüÃǵÄÐźÅÑÚÂë¡£³öÓÚÕâ¸öÔÒò£¬ÐźſÉÄܲ¢²»ÊÇÔÚ´óÐͶàÏß³ÌÓ¦ÓóÌÐòÖнøÐÐ IPC µÄÁ÷Ðз½Ê½¡£ÀýÈ磬ÔÚÓ¦ÓóÌÐò·þÎñÆ÷ÖÐÔËÐеÄÓ¦ÓóÌÐò¿ÉÒÔÅÉÉúËüÃÇ×Ô¼ºµÄỊ̈߳¬¿ÉÒÔ²¶»ñ¶ÔÓ¦ÓóÌÐò·þÎñÆ÷½ø³ÌÓÐʵ¼ÊÒâÒåµÄÐźš£
ÄÚºËÀ©Õ¹²»ÈÝÒ×±àд£¬¿ÉÄܲ»ÄÜ·½±ãµØÔÚÖ§³Ö Linux µÄ¶àÖÖÌåϵ½á¹¹¼ä½øÐÐÒÆÖ²¡£
Ëæ×Å POSIX draft 10 ±ê×¼µÄ³ǫ̈£¬ÒÔ¼°ËüÔÚ Linux 2.6 ÉϵÄʵÏֵĿÉÓ㬽ø³Ì¹²Ïí»¥³âÌ壨»¥³â¶ÔÏó£ºÔÊÐí¶à¸ö³ÌÐò¹²Ïíͬһ×ÊÔ´µ«²»ÄÜͬʱʹÓõijÌÐò£©ºÍÌõ¼þ±äÁ¿³ÉΪÔÚ¶à½ø³Ì»·¾³ÖÐʵÏÖ IPC »úÖƵĺÏÊÊÑ¡Ôñ¡£´Ë»úÖÆÒªÇó½¨Á¢¹²ÏíÄڴ棬ÔÚÆäÖдæ·Å»¥³âÌåºÍÌõ¼þ±äÁ¿£¬ËùÓнø³Ì¶¼ÓжÔÕâЩ½á¹¹ÌåµÄ¹²Í¬µÄÒýÓá£
Ñ¡ÔñÏß³ÌÄ£ÐÍ
ÕýÒªÒÆÖ²µ½ Linux µÄijЩÀÏÓ¦ÓóÌÐò·Ç³£ÓпÉÄÜÊÇ»ùÓÚ pthreads draft 4¡£×îа汾µÄ Linux Ö§³Ö pthreads draft 10£¬ËùÒÔÐèҪСÐĵضԵ÷ÓýøÐÐÊʵ±µÄÓ³Éä¡£Èç¹ûÓ¦ÓóÌÐòʹÓÃÁËijЩ»ùÓÚµÚÈý·½ÊµÏÖµÄÒì³£´¦Àí»úÖÆ£¨±ÈÈ磬DCE ÌṩµÄ TRY-CATCH ºê£©£¬ÄÇô³ÌÐòÔ±ÐèҪȷ±£ÄÇЩÒì³£´¦Àí´úÂëÒ²Óë pthreads draft 10 Ïà¼æÈÝ¡£