Linux µÄ¶àÏ̱߳à³ÌµÄ¸ßЧ¿ª·¢¾Ñé
2009 Äê 4 ÔÂ 23 ÈÕ
±¾ÎÄÖÐÎÒÃÇÕë¶Ô Linux É϶àÏ̱߳à³ÌµÄÖ÷ÒªÌØÐÔ×ܽá³ö 5 Ìõ¾Ñ飬ÓÃÒÔ¸ÄÉÆ Linux ¶àÏ̱߳à³ÌµÄÏ°¹ßºÍ±ÜÃâÆäÖеĿª·¢ÏÝÚå¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇ´©²åһЩ Windows µÄ±à³ÌÓÃÀýÓÃÒÔ¶Ô±È Linux ÌØÐÔ£¬ÒÔ¼ÓÉî¶ÁÕßÓ¡Ïó¡£
±³¾°
Linux ƽ̨ÉϵĶàÏ̳߳ÌÐò¿ª·¢Ïà¶ÔÓ¦ÆäËûƽ̨£¨±ÈÈç Windows£©µÄ¶àÏß³Ì API ÓÐһЩϸ΢ºÍÒþ»ÞµÄ²î±ð¡£²»×¢ÒâÕâЩ Linux ÉϵÄһЩ¿ª·¢ÏÝÚ壬³£³£»áµ¼Ö³ÌÐòÎÊÌâ²»ÇËÀËø²»¶Ï¡£±¾ÎÄÖÐÎÒÃÇ´Ó 5 ¸ö·½Ãæ×ܽá³ö Linux ¶àÏ̱߳à³ÌÉϵÄÎÊÌ⣬²¢·Ö±ðÒý³öÏà¹Ø¸ÄÉƵĿª·¢¾Ñ飬ÓÃÒÔ±ÜÃâÕâЩµÄÏÝÚå¡£ÎÒÃÇÏ£ÍûÕâЩ¾Ñé¿ÉÒÔ°ïÖú¶ÁÕßÃÇÄܸüºÃ¸ü¿ìµÄÊìϤ Linux ƽ̨µÄ¶àÏ̱߳à³Ì¡£
ÎÒÃǼÙÉè¶ÁÕ߶¼ÒѾºÜÊìϤ Linux ƽ̨ÉÏ»ù±¾µÄÏ̱߳à³ÌµÄ Pthread ¿â API ¡£ÆäËûµÄµÚÈý·½ÓÃÒÔÏ̱߳à³ÌµÄ¿â£¬Èç boost£¬½«²»»áÔÚ±¾ÎÄÖÐÌá¼°¡£±¾ÎÄÖÐÖ÷ÒªÉæ¼°µÄÌâ²Ä°üÀ¨Ï߳̿ª·¢ÖеÄÏ̹߳ÜÀí£¬»¥³â±äÁ¿£¬Ìõ¼þ±äÁ¿µÈ¡£½ø³Ì¸ÅÄ²»»áÔÚ±¾ÎÄÖÐÉæ¼°¡£
»ØÒ³Ê×
Linux ÉÏÏ߳̿ª·¢ API µÄ¸ÅÒª½éÉÜ
¶àÏ߳̿ª·¢ÔÚ Linux ƽ̨ÉÏÒѾÓгÉÊìµÄ Pthread ¿âÖ§³Ö¡£ÆäÉæ¼°µÄ¶àÏ߳̿ª·¢µÄ×î»ù±¾¸ÅÄîÖ÷Òª°üº¬Èýµã£ºỊ̈߳¬»¥³âËø£¬Ìõ¼þ¡£ÆäÖУ¬Ï̲߳Ù×÷ÓÖ·ÖÏ̵߳Ĵ´½¨£¬Í˳ö£¬µÈ´ý 3 ÖÖ¡£»¥³âËøÔò°üÀ¨ 4 ÖÖ²Ù×÷£¬·Ö±ðÊÇ´´½¨£¬Ïú»Ù£¬¼ÓËøºÍ½âËø¡£Ìõ¼þ²Ù×÷ÓÐ 5 ÖÖ²Ù×÷£º´´½¨£¬Ïú»Ù£¬´¥·¢£¬¹ã²¥ºÍµÈ´ý¡£ÆäËûµÄһЩÏß³ÌÀ©Õ¹¸ÅÄÈçÐźŵƵȣ¬¶¼¿ÉÒÔͨ¹ýÉÏÃæµÄÈý¸ö»ù±¾ÔªËصĻù±¾²Ù×÷·â×°³öÀ´¡£
Ị̈߳¬»¥³âËø£¬Ìõ¼þÔÚ Linux ƽ̨É϶ÔÓ¦µÄ API ¿ÉÒÔÓñí 1 ¹éÄÉ¡£ÎªÁË·½±ãÊìϤ Windows Ï̱߳à³ÌµÄ¶ÁÕßÊìϤ Linux ¶àÏ߳̿ª·¢µÄ API£¬ÎÒÃÇÔÚ±íÖÐͬʱҲÁгö Windows SDK ¿âÖÐËù¶ÔÓ¦µÄ API Ãû³Æ¡£
±í 1. Ï̺߳¯ÊýÁбí
¶ÔÏó
²Ù×÷
Linux Pthread API
Windows SDK ¿â¶ÔÓ¦ API
Ïß³Ì
´´½¨
pthread_create
CreateThread
Í˳ö
pthread_exit
ThreadExit
µÈ´ý
pthread_join
WaitForSingleObject
»¥³âËø
´´½¨
pthread_mutex_init
CreateMutex
Ïú»Ù
pthread_mutex_destroy
CloseHandle
¼ÓËø
pthread_mutex_lock
WaitForSingleObject
½âËø
pthread_mutex_unlock
ReleaseMutex
Ìõ¼þ
´´½¨
pthread_cond_init
CreateEvent
Ïú»Ù
pthread_cond_destroy
CloseHandle
´¥·¢
pthread_cond_signal
SetEvent
¹ã²¥
pthread_cond_broadcast
SetEvent / ResetEvent
µÈ´ý
pthread_cond_wait / pthread_cond_timedwait
SingleObjectAndWait
¶àÏ߳̿ª·¢ÔÚ Linux
Ïà¹ØÎĵµ£º
a.¿ª»ú½øÈëͼÐνçÃ棺°²×°Ê±Ñ¡Í¼ÐÎÆô¶¯·½Ê½»ò°Ñ/etc /inittabµÄid:x:initdefault:ÕâÐиijÉid:5:initdefault:¡£
b.¿ª»ú²»½øÈëͼÐνçÃ棺°²×°Ê±Ñ¡Îı¾Æô¶¯·½Ê½»ò°Ñ/etc/inittabµÄid:x:initdefault:ÕâÐиijÉid:3:initdefault:¡£
*inittabÊÇ×öʲôµÄ£¿
ÔÚKERNELÆðÀ´Ö®ºó£¬½«Éú³ÉµÚÒ»¸ö½ø³Ì——init£¬Êµ¼ÊÉÏÊÇÖ´Ð ......
1,freadÊÇ´ø»º³åµÄ,read²»´ø»º³å.
2,fopenÊDZê×¼cÀﶨÒåµÄ,openÊÇPOSIXÖж¨ÒåµÄ.
3,fread¿ÉÒÔ¶ÁÒ»¸ö½á¹¹.readÔÚlinux/unixÖжÁ¶þ½øÖÆÓëÆÕͨÎļþûÓÐÇø±ð.
4,fopen²»ÄÜÖ¸¶¨Òª´´½¨ÎļþµÄȨÏÞ.open¿ÉÒÔÖ¸¶¨È¨ÏÞ.
5,fopen·µ»ØÖ¸Õë,open·µ»ØÎļþÃèÊö·û(ÕûÊý).
6,linux/unixÖÐÈκÎÉ豸¶¼ÊÇÎļþ,¶¼¿ÉÒÔÓÃopen,read.
Èç¹ ......
·½Ê½Ò»£º
ifconfig eth0 192.168.1.18 netmask 255.255.255.0
˵Ã÷£º¸ÃÖÖ·½Ê½¿ÉÒÔʹ¸Ä±ä¼´Ê±ÉúЧ£¬ÖØÆôºó»á»Ö¸´ÎªÔÀ´µÄIP
·½Ê½¶þ£º
vi /etc/sysconfig/network-scripts/ifcfg-eth0
˵Ã÷£º¸Ã·½Ê½ÒªÖØÆôºóÉúЧ£¬ÇÒÊÇÓÀ¾ÃµÄ
Èç¹ûÒªÁ¢¼´¸ü¸ÄÇÒÓÀ¾ÃÉúЧ£¬¾ÍÖ»ÄÜÒÔÉÏÁ½ÖÖ·½Ê½Í¬Ê±Ê¹ÓÃÁË¡£
ÒÔÉÏÊÇͨ¹ýlinuxÃüÁîÐÐÐÞ¸ÄIPµÄ· ......
Linux·þÎñÆ÷ÐÔÄܼà²âÊǺÜÖØÒªµÄ¹¤×÷£¬·þÎñÆ÷ÔËÐÐÓ¦¸ÃÌṩ×îÓÐЧµÄϵͳÐÔÄÜ¡£µ±·þÎñÆ÷ϵͳÐÔÄÜͻȻµÍÓÚƽ¾ùÓ¦ÓеÄÇé¿ö£¬ÎÊÌâ¿ÉÄÜÀ´×ÔÔÚÖ´ÐеĽø³Ì¡¢ÄÚ´æµÄʹÓÃÂÊ¡¢´ÅÅ̵ÄÐÔÄÜ¡¢ÍøÂçÁ÷Á¿ºÍCPU µÄѹÁ¦¡£ÔÚÔ¤Ëã¶ÌȱµÄ½ñÌ죬Àí½âÈçºÎÓÅ»¯ÏµÍ³ÐÔÄܱÈÒÔÍùÈκÎʱºò¶¼ÖØÒª¡£ÒªÊµÏÖËüµÄÇ°ÌáÊÇ£¬Äã±ØÐë³ä·ÖÁ˽â×Ô¼ºµÄ¼ÆËã»úºÍÍøÂ磬´Ó¶ ......