Ö÷Ì⣺һ¸ö¼òµ¥µÄlinuxÏ̳߳Ø
Ï̳߳Ø
£º¼òµ¥µØ˵£¬Ï̳߳Ø
¾ÍÊÇÔ¤ÏÈ´´½¨ºÃÒ»ÅúỊ̈߳¬·½±ã¡¢¿ìËٵش¦ÀíÊÕµ½µÄÒµÎñ¡£±ÈÆð´«Í³µÄµ½À´Ò»¸öÈÎÎñ£¬¼´Ê±´´½¨Ò»¸öÏß³ÌÀ´´¦Àí£¬½ÚÊ¡ÁËÏ̵߳Ĵ´½¨ºÍ»ØÊյĿªÏú£¬ÏìÓ¦¸ü¿ì£¬Ð§ÂÊ
¸ü¸ß¡£
ÔÚlinuxÖУ¬Ê¹ÓõÄÊÇposixÏ߳̿⣬Ê×ÏȽéÉܼ¸¸ö³£Óõĺ¯Êý£º
1 Ï̵߳Ĵ´½¨ºÍÈ¡Ïûº¯Êý
pthread_create
´´½¨
pthread_join
ºÏ²¢Ïß³Ì
pthread_cancel
È¡ÏûÏß³Ì
2 Ïß³Ìͬ²½º¯Êý
pthread_mutex_lock
pthread_mutex_unlock
pthread_cond_signal
pthread_cond_wait
¹ØÓÚº¯ÊýµÄÏêϸ˵Ã÷£¬²Î¿¼manÊÖ²á
Ï̳߳صÄʵÏÖ£º
Ï̳߳صÄʵÏÖÖ÷Òª·ÖΪÈý²¿·Ö£¬Ï̵߳Ĵ´½¨¡¢Ìí¼ÓÈÎÎñµ½Ï̳߳ØÖС¢¹¤×÷Ï̴߳ÓÈÎÎñ¶ÓÁÐÖÐÈ¡³öÈÎÎñ½øÐд¦Àí¡£
Ö÷ÒªÓÐÁ½¸öÀàÀ´ÊµÏÖ£¬CTask,CThreadPool
/**
Ö´ÐÐÈÎÎñµÄÀ࣬ÉèÖÃÈÎÎñÊý¾Ý²¢Ö´ÐÐ
**/
class CTask
{
protected:
string m_strTaskName; //ÈÎÎñµÄÃû³Æ
void* m_ptrData; //ÒªÖ´ÐеÄÈÎÎñµÄ¾ßÌåÊý¾Ý
public:
CTask(){}
CTask(string taskName)
{
this->m_strTaskName = taskName;
m_ptrData = NULL;
}
virtual int Run()= 0;
void SetData(void* data); //ÉèÖÃÈÎÎñÊý¾Ý
};
ÈÎÎñÀàÊǸöÐéÀ࣬ËùÓеÄÈÎÎñÒª´ÓCTaskÀàÖм̳Ð
£¬ÊµÏÖrun½Ó¿Ú£¬run½Ó¿ÚÖÐÐèҪʵÏֵľÍÊǾßÌå½âÎöÈÎÎñµÄÂß¼¡£m_ptrDataÊÇÖ¸ÏòÈÎÎñÊý¾ÝµÄÖ¸Õ룬¿ÉÒÔÊǼòµ¥Êý¾ÝÀàÐÍ£¬Ò²¿ÉÒÔÊÇ×Ô¶¨ÒåµÄ¸´ÔÓ
Êý¾ÝÀàÐÍ¡£
Ï̳߳ØÀà
/**
Ï̳߳Ø
**/
class CThreadPool
{
private:
vector<CTask*> m_vecTaskList; //ÈÎÎñÁбí
int m_iThreadNum; //Ï̳߳ØÖÐÆô¶¯µÄÏß³ÌÊý
static vector<pthread_t> m_vecIdleThread; //µ±Ç°¿ÕÏеÄÏ̼߳¯ºÏ
static vector<pthread_t> m_vecBusyThread; //µ±Ç°ÕýÔÚÖ´ÐеÄÏ̼߳¯ºÏ
static pthread_mutex_t m_pthreadMutex; //Ïß³Ìͬ²½Ëø
static pthread_cond_t m_pthreadCond; //Ïß³Ìͬ²½µÄÌõ¼þ±äÁ¿
protected:
static void* ThreadFunc(void * threadData); //ÐÂÏ̵߳ÄÏ̺߳¯Êý
static int MoveToIdle(pthread_t tid); //Ïß³ÌÖ´ÐнáÊøºó£¬°Ñ×Ô¼º·ÅÈëµ½¿ÕÏÐÏß³ÌÖÐ
static int MoveToBusy(pthread_t tid); //ÒÆÈ뵽æµÏß³ÌÖÐÈ¥
int Create(); //´´½¨ËùÓеÄÏß³Ì
public:
CThreadPool(int threadNum);
int AddTask(CTask *task); //°ÑÈÎÎñÌí¼Óµ½Ï̳߳ØÖÐ
int StopAll(
Ïà¹ØÎĵµ£º
¼òµ¥½âÊÍÒ»ÏÂipcsÃüÁîºÍipcrmÃüÁî¡£
È¡µÃipcÐÅÏ¢£º
ipcs [-m|-q|-s]
-m Êä³öÓйع²ÏíÄÚ´æ(shared memory)µÄÐÅÏ¢
-q Êä³öÓйØÐÅÏ¢¶ÓÁÐ(message queue)µÄÐÅÏ¢
-s Êä³öÓйؓÕÚ¶ÏÆ÷”(semaphore)µÄÐÅÏ¢
%ipcs -m
ɾ³ýipc
ipcrm -m|-q|-s shm_id
%ipcrm -m 105
ÀýÈ磬ÎÒÃÇÔÚÒÔ0x12345678ΪKEY´´½¨ÁËÒ»¸ö¹ ......
ѧLinuxÒ»Äê¶àÁË£¬¶ÔÇý¶¯µÄ֪ʶһµã¶¼Á˽⣬ÉÏÖÜÂòÁ˱¾¡¶LinuxÉ豸Çý¶¯¡·£¬O'REILLY³ö°æ£¬´òËãѧϰѧϰ¡£Ñ§Ï°¹ýµÄ´óÏÀ£¬Ï£Íû¿ÉÒÔÖ¸µ¼Ö¸µ¼¡£
Ê×ÏÈÏÂÔØLinuxÄںˣ¬°´×÷ÕßµÄ˵·¨£¬Ö»ÒªÊÇlinux-2.6.xxxµÄÄں˶¼¿ÉÒÔ£¬ÎÒµÄÊÇlinux-2.6.33.2¡£ÓÐλÍøÓÑ˵ÏÂÔغó×îºÃ½âѹµ½/usr/src/Ŀ¼Ï£¬½âѹ
ÔÚ¹¹½¨ÄÚºËÊ÷ÊDzο¼ÁËÔÊéµÚËÄÕÂ& ......
1£©±ÕÍø¿¨É豸
¡¡¡¡/sbin/ifconfig eth0 down
2£©ÐÞ¸ÄMACµØÖ·
¡¡¡¡/sbin/ifconfig eth0 hw ether 00:50:56:C0:00:01
3£©ÖØÆôÍø¿¨
¡¡¡¡/sbin/ifconfig eth0 up
ͨ¹ýifconfig¿ÉÒÔ¿´µ½ÐÞ¸ÄÒѾÉúЧ,¿ÉÊÇÖØÆô»úÆ÷ºóÓÖ»Ö¸´³ÉÁËÔÀ´µÃmac.
ÒªÏëÓÀ¾ÃÐÞ¸ÄMAC
ÔÚ/etc/rc.d/rc.localÀï¼ÓÉÏÕâÈý¾ä(Ò²¿ÉÒÔÔÚ/etc/init.d/networ ......
/***************************************************************************** ³ÌÐò˵Ã÷£ºÊ¾Àý³ÌÐòÑÝʾÁË2440ƽ̨ÏÂlinux´®¿ÚÓ¦Óÿª·¢£¬¿ÉʵÏÖ2440´®¿Ú2Óë´®¿Ú3µÄͨѶ*** Ó²¼þÉèÖ㺽«2440°å×ÓÉϵĴ®¿Ú2¡¢3TXD¡¢RXD½»²æ¶Ì½Ó*** ±àÒëÔËÐУºÔÚËÞÖ÷»úÉϱàÒë³ÌÐòÔ´Â룬´ò¿ª³¬¼¶Öնˣ¨¿ÉÓë2440½øÐÐÃüÁî½»»¥£©£¬*** &nb ......