linuxÏÂÉú²úÕßÏû·ÑÕßµÄʵÏÖ
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define M 10 // »º³åÊýÄ¿
int in = 0; // Éú²úÕß·ÅÖòúÆ·µÄλÖÃ
int out = 0; // Ïû·ÑÕßÈ¡²úÆ·µÄλÖÃ
int buff[M] = {0}; // »º³å³õʼ»¯Îª0£¬ ¿ªÊ¼Ê±Ã»ÓвúÆ·
sem_t empty_sem; // ͬ²½ÐźÅÁ¿£¬ µ±ÂúÁËʱ×èÖ¹Éú²úÕ߷ŲúÆ·
sem_t full_sem; // ͬ²½ÐźÅÁ¿£¬ µ±Ã»²úƷʱ×èÖ¹Ïû·ÑÕßÏû·Ñ
pthread_mutex_t mutex; // »¥³âÐźÅÁ¿£¬ Ò»´ÎÖ»ÓÐÒ»¸öÏ̷߳ÃÎÊ»º³å
int product_id = 0; //Éú²úÕßid
int prochase_id = 0; //Ïû·ÑÕßid
/* ´òÓ¡»º³åÇé¿ö */
void print()
{
int i;
for(i = 0; i < M; i++)
printf("%d ", buff[i]);
printf("\n");
}
/* Éú²úÕß·½·¨ */
void *product()
{
int id = ++product_id;
while(1)
{
// ÓÃsleepµÄÊýÁ¿¿ÉÒÔµ÷½ÚÉú²úºÍÏû·ÑµÄËٶȣ¬±ãÓÚ¹Û²ì
sleep(1);
//sleep(1);
sem_wait(&empty_sem);
pthread_mutex_lock(&mutex);
Õâ¶þ¾äÈç¹ûµßµ¹µÄ»°,¿ÉÄܳöÏÖÒ»ÖÖÒì³£Çé¿ö,
µ±½øÈëÁË»º³åÇøΪÂúʱ,µßµ¹Ö®ºó»á¶Ô»º³åÇøÏȼÓËø,È»ºó,½ø³ÌÓÉÓÚ»º³åÇøΪÂòû·¨Éú²ú²úÆ·,ÔÚÕâÀï±»×èÈû,¶øÏû·ÑÕßÓÖÎÞ·¨»ñµÃ»º³åÇøµÄËø½øÈ뻺³åÇø,Òò¶ø»á³öÏÖËÀËø
in = in % M;
printf("product%d in %d. like: \t", id, in);
buff[in] = 1;
print();
++in;
pthread_mutex_unlock(&mutex);
sem_post(&full_sem);
}
}
/* Ïû·ÑÕß·½·¨ */
void *prochase()
{
int id = ++prochase_id;
while(1)
{
// ÓÃsleepµÄÊýÁ¿¿ÉÒÔµ÷½ÚÉú²úºÍÏû·ÑµÄËٶȣ¬±ãÓÚ¹Û²ì
sleep(2);
sem_wait(&full_sem); // Õâ¶þ¾äÈç¹ûµßµ¹µÄ»°,¿ÉÄܳöÏÖÒ»ÖÖÒì³£Çé¿ö,
µ±½øÈëÁË»º³åÇøΪ¿Õʱ,µßµ¹Ö®ºó»á¶Ô»º³åÇøÏȼÓËø,È»ºó,½ø³ÌÓÉÓÚ»º³åÇøΪ¿Õû·¢Ïû·Ñ²úÆ·,ÔÚÕâÀï±»×èÈû,¶øÉú²úÕßÓÖÎÞ·¨»ñµÃ»º³åÇøµÄËø½øÈ뻺³åÇø,Òò¶ø»á³öÏÖËÀËø
pthread_mutex_lock(&mutex);
Ïà¹ØÎĵµ£º
ÈçºÎ°²×°:
ÏÈ°Ñ Mingming µÄ Launchpad PPA Ìí¼Óµ½ÄãµÄÈí¼þÔ´£º
½«ÏÂÃæÁ½ÐÐÌí¼Óµ½ /etc/apt/sources.list/totem-pps.list
deb http://ppa.launchpad.net/portis25/ppa/ubuntu karmic main
deb-src http://ppa.launchpad.net/portis25/ppa/ubuntu karmic main
ÔÚÖÕ¶ËÖÐÖ´ÐÐÏÂÃæµÄÃüÁîÀ´»ñÈ¡ÉÏÊö PPA Ô´µÄÃÜÔ¿¡£ ......
vim(vi)ÊÇLinuxÖй¦ÄÜÇ¿´óµÄ±à¼¹¤¾ß¡£vimÓÐ3ÖÐÖ÷ÒªµÄģʽ£º
1.normal mode£ºµ±½øÈëvimʱ£¬Ä¬ÈϵÄģʽ¾ÍÊÇnormal mode¡£ÔÚ´ËģʽÏ£¬ÎÞ·¨ÊäÈëÈκÎÎÄ×Ö£¬²»¹ý¿ÉÒÔÀûÓð´¼üÃüÁîÀ´Ö´ÐÐÐí¶à²Ù×÷ÃüÁÀýÈçÒƶ¯¹â±êλÖᢸ´ÖÆ¡¢É¾³ý¡£
2.insert mode£º½øÈëvimÊäÈëa¡¢i¡¢»òo¼ü¡£¼´¿É½øÈëinsert  ......
1) ÓÀ¾ÃÐÔÉúЧ£¬ÖØÆôºó²»»á¸´Ô
¿ªÆô£º chkconfig iptables on
¹Ø±Õ£º chkconfig iptables off
2) ¼´Ê±ÉúЧ£¬ÖØÆôºó¸´Ô
¿ªÆô£º service iptables start
¹Ø±Õ£º service iptables stop
¿ªÆôºÍ¹Ø±Õ¶Ë¿ÚÏà¹ØÅäÖÃÎļþ
/etc/sysconfig/iptables ......
Ïß³Ì ÊǼÆËã»úÖжÀÁ¢ÔËÐеÄ×îСµ¥Î»£¬ÔËÐÐʱռÓúÜÉÙµÄϵͳ×ÊÔ´¡£¿ÉÒÔ°ÑÏ߳̿´³ÉÊDzÙ×÷ϵͳ·ÖÅäCPUʱ¼äµÄ»ù±¾µ¥Ôª¡£Ò»¸ö½ø³Ì¿ÉÒÔÓµÓÐÒ»¸öÖÁ¶à¸öÏ̡߳£ËüÏß³ÌÔÚ½ø³ÌÄÚ²¿¹²ÏíµØÖ·¿Õ¼ä¡¢´ò¿ªµÄÎļþÃèÊö·ûµÈ×ÊÔ´¡£Í¬Ê±Ïß³ÌÒ²ÓÐÆä˽ÓеÄÊý¾ÝÐÅÏ¢£¬°üÀ¨£ºÏ̺߳š¢¼Ä´æÆ÷£¨³ÌÐò¼ÆÊýÆ÷ºÍ¶ÑÕ»Ö¸Õ룩¡¢¶ÑÕ»¡¢ÐźÅÑÚÂë¡¢ÓÅÏȼ¶¡¢Ïß³ÌË ......