<pre name="code" class="cpp"><h2>/*<strong>运行时使用 gcc -o sem sem.c -lpthread </strong></h2><h2><strong>L加左边猴子数 R加右边猴子数*/</strong></h2>
<pre name="code" class="cpp">#include<stdio.h>
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdlib.h>
#include<string.h>
#include<semaphore.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<signal.h>
/* interfAcer */
/*欢迎访问我的csdn blog http://blog.csdn.net/nibiru_holmes*/
sem_t *sem_a_task;
sem_t *sem_b_task;
int RightMonkey=20;
int LeftMonkey=20;
int bridgelen=5;
int Temp;
int i,j;
pid_t fpid,fpi