Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Éú²úÕß Ïû·ÑÕßÎÊÌâʵÏÖ (linuxÏÂCÓïÑÔ)

²Ù×÷ϵͳµÄÒ»¸ö¾­µäÎÊÌâÊÇ"Éú²úÕß-Ïû·ÑÕß"ÎÊÌâ, ÕâÉ漰ͬ²½ÐźÅÁ¿ºÍ»¥³âÐźÅÁ¿µÄÓ¦ÓÃ, ÔÚÕâÀï,ÎÒÓÃÏ̵߳Äͬ²½ºÍ»¥³âÀ´ÊµÏÖ.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h>
#define N 2   // Ïû·ÑÕß»òÕßÉú²úÕßµÄÊýÄ¿
#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(1);
//sleep(1);
  
   sem_wait(&full_sem);
   pthread_mutex_lock(&mutex);
  
   out = out % M;
   printf("prochase%d in %d. like: \t", id, out);
  
   buff[out] = 0;
  


Ïà¹ØÎĵµ£º

[תÌû]LinuxÇý¶¯¿ª·¢Ñ§Ï°µÄһЩ±ØÒª²½Öè

 1. ѧ»áд¼òµ¥µÄmakefile
2. ±àһЩӦÓÃ
³ÌÐò
£¬¿ÉÒÔÓÃmakefileÅÜÆðÀ´
3. ѧ»áдÇý¶¯
µÄmakefile
4. дһ¼òµ¥charÇý¶¯£¬makefile±àÒëͨ¹ý£¬¿ÉÒÔinsmod£¬ lsmod£¬ rmmod. ÔÚÇý¶¯µÄinitº¯ÊýÀï´òÓ¡hello world£¬insmodºóÓ¦¸ÃÄܹ»Í¨¹ýdmesg¿´µ½Êä³ö
¡£
5. дһÍêÕûÇý¶¯£¬ ¼ÓÉÏread£¬ write£¬ ioctl£¬ pollingµÈ¸ ......

linuxÖ®gccÃüÁî

      ÔÚLinuxϽøÐÐCÓïÑÔ±à³Ì£¬±ØȻҪ²ÉÓÃGNU GCCÀ´±àÒëCÔ´´úÂëÉú³É¿ÉÖ´ÐгÌÐò¡£GccÖ¸ÁîµÄÒ»°ã¸ñʽΪ£º
Gcc [Ñ¡Ïî] Òª±àÒëµÄÎļþ [Ñ¡Ïî] [Ä¿±êÎļþ]¡£ÆäÖУ¬Ä¿±êÎļþ¿Éȱʡ£¬GccĬÈÏÉú³É¿ÉÖ´ÐеÄÎļþÃûΪ£º±àÒëÎļþ.out
¿´Ò»Ï¾­µäÈëÃųÌÐò"Hello World£¡"
# vi hello.c £¬±à¼­ÈçÏ£º
#inclu ......

ŪÁË°ëÒ¹¾ÍûÏëÃ÷°×£¬µô½øCÏÝÚåÁË£¬555

 
//ÊäÈëÒ»¸öÊý×飬ÔÙÐÞ¸ÄÕâ¸öÊý×éËùÓÐÔªËØ£¬ÈçºÎʵÏÖ£¿
int main()
{
 vector<int> a;
 int i(0);
 while(cin>>i)
  a.push_back(i);
 //////////////////////////////////////////////////////Êä³ö½¨Á¢µÄÊý×飺
 cout << "µÃµ½µÄÊý×éΪ£º" << ......

C/C++±ÊÊÔÃæÊÔÌâÄ¿

1£®ÒÑÖªstrcpy º¯ÊýµÄÔ­ÐÍÊÇ£º
char *strcpy(char *strDest, const char *strSrc);
ÆäÖÐstrDest ÊÇÄ¿µÄ×Ö·û´®£¬strSrc ÊÇÔ´×Ö·û´®¡£²»µ÷ÓÃC++/C µÄ×Ö·û´®¿âº¯Êý£¬Çë±àдº¯Êý strcpy
´ð°¸£º
char *strcpy(char *strDest, const char *strSrc)
{
if ( strDest == NULL || strSrc == NULL)
return NULL ;
if ( strDest ......

LinuxµÄÏÂÔØÃüÁîwgetÏê½â

 WgetÊÇÒ»¸öÊ®·Ö³£ÓÃÃüÁîÐÐÏÂÔع¤¾ß£¬¶àÊýLinux·¢Ðа汾¶¼Ä¬ÈÏ°üº¬Õâ¸ö¹¤¾ß¡£Èç¹ûûÓа²×°¿ÉÔÚ http: //www.gnu.org/software/wget/wget.html ÏÂÔØ×îа汾£¬²¢Ê¹ÓÃÈçÏÂÃüÁî±àÒë°²×°£º
# tar zxvf wget-1.9.1.tar.gz
# cd wget-1.9.1
# ./configure
# make
# make install
ËüµÄÓ÷¨ºÜ¼òµ¥.
1£©Ö§³Ö¶ÏµãÏ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ