#include #include #include #include #include #include #include #include void produce ( int n, int t, int shmid ) { int *M, i, c, item; int *cnt, *sum; M = (int *)shmat(shmid, 0, 0); printf("Producer is alive\n"); cnt = (int *)malloc((n+1) * sizeof(int)); sum = (int *)malloc((n+1) * sizeof(int)); for (i=0; i<=n; ++i) cnt[i] = sum[i] = 0; for (i=0; i 1) ? atoi(argv[1]) : 1; t = (argc > 2) ? atoi(argv[2]) : 10; printf("n = %d\nt = %d\n", n, t); shmid = shmget(IPC_PRIVATE, 2*sizeof(int), 0777 | IPC_CREAT); M = (int *)shmat(shmid, 0, 0); M[0] = M[1] = 0; for (i=1; i<=n; ++i) { if (!fork()) consume(i,shmid); } produce(n,t,shmid); exit(0); }