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);
Ïà¹ØÎĵµ£º
ÀýÒ»£º·¢ËÍSignaling Packet£º
Signaling CommandÊÇ2¸öBluetoothʵÌåÖ®¼äµÄL2CAP²ãÃüÁî´«Êä¡£ËùÒÔµÃSignaling CommandʹÓÃCID 0x0001.
¶à¸öCommand¿ÉÒÔÔÚÒ»¸öC-frame£¨control frame£©Öз¢ËÍ¡£
Èç¹ûÒªÖ±½Ó·¢ËÍSignaling Command.ÐèÒª½¨Á¢SOCK_RAWÀàÐ͵ÄL2CAPÁ¬½ÓSocket¡£ÕâÑù²ÅÓлú»á×Ô¼ºÌî³äCommand Code£¬Identi ......
¸ñʽ: echo "\033[×Ö±³¾°ÑÕÉ«;×ÖÌåÑÕÉ«m×Ö·û´®\033[0m"
ÀýÈç:
echo "\033[41;36m something here \033[0m"
ÆäÖÐ41µÄλÖôú±íµ×É«, 36µÄλÖÃÊÇ´ú±í×ÖµÄÑÕÉ«
ÄÇЩascii code ÊǶÔÑÕÉ«µ÷ÓõÄʼĩ.
\033[ ; m …… \033[0m
×Ö±³¾°ÑÕÉ«·¶Î§:40----49
40:ºÚ
41:Éîºì
42:ÂÌ
43:»ÆÉ«
44:À¶É«
45:×ÏÉ«
4 ......
Ò»¸ö¼òµ¥ÊµÓõÄС¹¦ÄÜ¡£¡£
1.ÓÃwÃüÁî²é¿´¶¼ÓÐÄÄЩÖжÏÓû§
[]#w
jeff pts/5 192.168.96.128 16:47 10:44 0.03s 0.03s -bash
2.·¢ËÍÏûÏ¢
[]#write jeff pts/5
hello!
½ÓÏÂÀ´Ã¿Ð´Ò»ÐУ¬°´»Ø³µºó¾Í»á·¢Ë͵½¶Ô·½ÏàÓ¦µÄÖնˡ£
......
Ïß³Ì ÊǼÆËã»úÖжÀÁ¢ÔËÐеÄ×îСµ¥Î»£¬ÔËÐÐʱռÓúÜÉÙµÄϵͳ×ÊÔ´¡£¿ÉÒÔ°ÑÏ߳̿´³ÉÊDzÙ×÷ϵͳ·ÖÅäCPUʱ¼äµÄ»ù±¾µ¥Ôª¡£Ò»¸ö½ø³Ì¿ÉÒÔÓµÓÐÒ»¸öÖÁ¶à¸öÏ̡߳£ËüÏß³ÌÔÚ½ø³ÌÄÚ²¿¹²ÏíµØÖ·¿Õ¼ä¡¢´ò¿ªµÄÎļþÃèÊö·ûµÈ×ÊÔ´¡£Í¬Ê±Ïß³ÌÒ²ÓÐÆä˽ÓеÄÊý¾ÝÐÅÏ¢£¬°üÀ¨£ºÏ̺߳š¢¼Ä´æÆ÷£¨³ÌÐò¼ÆÊýÆ÷ºÍ¶ÑÕ»Ö¸Õ룩¡¢¶ÑÕ»¡¢ÐźÅÑÚÂë¡¢ÓÅÏȼ¶¡¢Ïß³ÌË ......