I'm doing school assignment. But I can't solve it yet.
Will you help me?
Using shared memory,I have to copy structure to second program.
But it does not operate well.
Maybe it's type problem especially shmat part.
Will you help me guys? Thanks you in advance.
struct work_list {
int speed_rate;
int dirty_rate;
} ;
//------------------------------------------------------------------
int main(void)
{
int shmid;
int index=0;
int buffer;
int pid;
int icount, jcount;
srand(time(NULL));
struct work_list work_ll[10];
struct work_list *ptr;
struct work_list *ptr1;
ptr = &work_ll[0];
ptr1 = &work_ll[0];
for(jcount=0; jcount<3;jcount++)
{
work_ll[jcount].speed_rate = rand()%5;
work_ll[jcount].dirty_rate = rand()%5;
}
shmid = shmget(SHMKEY, BUFSIZE*sizeof(char), IPC_CREAT | 0x1FF );
if (shmid == -1) perror("shmget: ");
prt1 = (struct work_list *)shmat(shmid, NULL, 0);
if (semid == -1) perror("semget: ");
index = (index + 1) % 5; // Circular queue.
}