生产者和消费者
#include<unistd.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/sem.h>
#include<sys/shm.h>
#include<sys/mman.h>
#include<stdio.h>
#include<stdlib.h>
#define SHM_SIZE (1024*1024)
#define SHM_MODE 0600
#define SEM_MODE 0600
#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
/* union semun is defined by including <sys/sem.h> */
#else
/* according to X/OPEN we have to define it ourselves */
union semun{
int val;
struct semid_ds *buf;
unsigned short *array;
};
#endif
struct ShM{
int start;
int end;
}* pSM;
int count=30;//计数器,produce执行30次后终止程序
const int num_of_consumer = 3;//消费者数量
const int size_of_buffer=5;//缓冲区大小
int shmId = -1;
int semSetId = -1;
union semun su;//sem union,用于初始化信号量
void semWait(int semSetId,int semNum)
{
stru