linuxÏÂCÓïÑÔ¶àÏ̱߳à³ÌʵÀý
ѧ¶«Î÷£¬ÍùÍùʵÀý²ÅÊÇ×îÈÃÈ˸ÐÐËȤµÄ£¬ÀÏÊÇѧ»ù´¡ÀíÂÛ£¬²»¶¯ÊÖ£¬¸Ð¾õûÓгɾ͸У¬ºÇºÇ¡£
ÏÂÃæÏÈÀ´Ò»¸öʵÀý¡£ÎÒÃÇͨ¹ý´´½¨Á½¸öÏß³ÌÀ´ÊµÏÖ¶ÔÒ»¸öÊýµÄµÝ¼Ó¡£
»òÐíÕâ¸öʵÀýûÓÐʵ¼ÊÔËÓõļÛÖµ£¬µ«ÊÇÉÔ΢¸Ä¶¯Ò»Ï£¬ÎÒÃǾͿÉÒÔÓõ½ÆäËûµØ·½È¥À¡£
ÏÂÃæÊÇÎÒÃǵĴúÂ룺
/*thread_example.c : c multiple thread programming in linux
*author : falcon
*E-mail : tunzhj03@st.lzu.edu.cn
*/
#include <pthread.h>
#include <stdio.h>
#include <sys/time.h>
#include <string.h>
#define MAX 10
pthread_t thread[2];
pthread_mutex_t mut;
int number=0, i;
void *thread1()
{
printf ("thread1 : I'm thread 1\n");
for (i = 0; i < MAX; i++)
{
printf("thread1 : number = %d\n",number);
pthread_mutex_lock(&mut);
number++;
pthread_mutex_unlock(&mut);
sleep(2);
}
printf("thread1 :Ö÷º¯ÊýÔÚµÈÎÒÍê³ÉÈÎÎñÂð£¿\n");
pthread_exit(NULL);
}
void *thread2()
{
printf("thread2 : I'm thread 2\n");
for (i = 0; i < MAX; i++)
{
printf("thread2 : number = %d\n",number);
pthread_mutex_lock(&mut);
number++;
pthread_mutex_unlock(&mut);
sleep(3);
}
printf("thread2 :Ö÷º¯ÊýÔÚµÈÎÒÍê³ÉÈÎÎñÂð£¿\n");
pthread_exit(NULL);
}
void thread_create(void)
{
int temp;
memset(&thread, 0, sizeof(thread)); //comment1
/*´´½¨Ïß³Ì*/
if((temp = pthread_create(&thread[0], NULL, thread1, NULL)) != 0) //comment2
printf("Ïß³Ì1´´½¨Ê§°Ü!\n");
else
printf("Ïß³Ì1±»´´½¨\n");
if((temp = pthread_create(&thread[1], NULL, thread2, NULL)) != 0) //comment3
printf("Ïß³Ì2´´½¨Ê§°Ü");
else
printf("Ïß³Ì2±»´´½¨\n");
}
void thread_wait(void)
{
/*µÈ´
Ïà¹ØÎĵµ£º
½â¾ö²½Ö裺
gylu@dell-desktop:~$ sudo apt-get install ckermit
ÏÔʾ°²×°¹ý³Ì
gylu@dell-desktop:~$gedit ~/.kermrc
ÊäÈëÏÂÃæÄÚÈݺ󱣴æ.kermrcÍ˳ö:
set line /dev/ttyS0
set speed & ......
viÓëvimÒ»Ñù¶¼ÊDZà¼Æ÷£¬²»Í¬µÄÊÇvim¸ü¸ß¼¶Ò»Ð©£¬¿ÉÒÔÀí½âÊÇviµÄ¸ß¼¶°æ±¾¡£vi¾ÍÏñWindowsÖеļÆʱ¾£¬¶øvimÔò¿ÉÒÔËãµÄÉÏÊÇ
officeÖеÄword¡£viÖ÷ÒªÓÃÀ´±à¼Ò»Ð©Îļþ£¬vimÊdzÌÐòÔ±µÄºÃ¹¤¾ß¡£ºÃµÄ¡£¡£¡£¡£ÏÂÃæÔÚ½éÉÜÒ»ÏÂviµÄʹÓᣡ£¡£¡£¡£¡£
1.
ʹÓÃvi½øÈëÒ»°ãģʽ
[root@linux ~]# vi test.tx ......
1 ÒýÑÔ
¡¡¡¡Ị̈߳¨thread£©¼¼ÊõÔçÔÚ60Äê´ú¾Í±»Ìá³ö£¬µ«ÕæÕýÓ¦ÓöàÏ̵߳½²Ù×÷ϵͳÖÐÈ¥£¬ÊÇÔÚ80Äê´úÖÐÆÚ£¬solarisÊÇÕâ·½ÃæµÄٮٮÕß¡£´«Í³µÄUnixÒ²Ö§³ÖÏ̵߳ĸÅÄµ«ÊÇÔÚÒ»¸ö½ø³Ì£¨process£©ÖÐÖ»ÔÊÐíÓÐÒ»¸öỊ̈߳¬ÕâÑù¶àÏ߳̾ÍÒâζ×Ŷà½ø³Ì¡£ÏÖÔÚ£¬¶àÏ̼߳¼ÊõÒѾ±»Ðí¶à²Ù×÷ϵͳËùÖ§³Ö£¬°üÀ¨Windows/NT£¬µ±È»£¬Ò²°üÀ¨Linux¡£
......
LinuxµÄI/O»úÖƾÀúÁËһϼ¸¸ö½×¶ÎµÄÑݽø£º
1. ͬ²½×èÈûI/O: Óû§½ø³Ì½øÐÐI/O²Ù×÷£¬Ò»Ö±×èÈûµ½I/O²Ù×÷Íê³ÉΪֹ¡£
2. ͬ²½·Ç×èÈûI/O: Óû§³ÌÐò¿ÉÒÔͨ¹ýÉèÖÃÎļþÃèÊö·ûµÄÊôÐÔO_NONBLOCK£¬I/O²Ù×÷¿ÉÒÔÁ¢¼´·µ»Ø£¬µ«ÊDz¢²»±£Ö¤I/O²Ù×÷³É¹¦¡£
3. Ò첽ʼþ×èÈûI/O: Óû§½ø³Ì¿ÉÒÔ¶ÔI/Oʼþ½øÐÐ×èÈû£¬µ«ÊÇI/O²Ù×÷²¢²»×èÈû¡£Í¨¹ýse ......
1.1 Ê×ÏÈÏÂÔØlibnet.tar.gz£¬heartbeat-2.0.4.tar.gz
1.2 °´Ë³ÐòÏÖ×°libnetÔÙ×°heartbeat
¶¼ÊÇÔ´Âë°ü£¬½âѹ¿ªºó·Ö±ðÖ´ÐУº
./configure ;make ;make install;
°²×°Íê±Ï¡£
1.3 Èí¼þµÄÅäÖÃ
HeartbeatÈí¼þµÄ°²×°Ä¿Â¼Îª/usr/local/etc/ha.d£¬ÆäÖеÄREADME.config¶ÔÅäÖÃÎļþ½øÐÐÁË˵Ã÷£¬¹²ÓÐÈý¸öÖ÷ÒªµÄÅäÖÃ
Îļþ£ºha.cf£¬ ......