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.
}

Recommended Answers

All 2 Replies

when i was a child, i used to watch the re-runs of a US sitcom called "Laverne and Shirley".

it was about these two women who were roomates and coworkers at a beer-bottling plant, and their antics and adventures with their bluecollar friends in their urban Milwaukee neighborhood. Laverne was the dominant personality, Shirley still slept with her childhood stuffed animal named "Boo Boo Kitty."

So anyhow, in the beginning of every show, the theme song would play while showing comic clips from various episodes. There was always this one scene I really enjoyed, where Laverne put one of Shirley's work gloves on the bottling conveyor line and Shirley was first upset, but then became resigned as she realized there was nothing she could do but watch it disappear into the distance. More on this in a moment.

Now the one thing that always confused me was this little chant that started the lyrics to the theme song it went something like this:

Shlmeel, Shlmazel, Fasenfeffer incorporated.

Now i never knew what the hell any that meant. What's a shlmeel? What's a shlmazel? What on earth is a Fassenfeffer? My mom didnt know either. We sheepishly suggested they maybe weren't even real words, but we were thinking that surely it was our knowledge that is at fault, because SOMEBODY knows what those words meant, SOMEWHERE.

Now I'm considering your functions, "shmat" and "shmget", and once again I'm asking "what the hell is this?" The old feelings of inadequacy resurface. Because surely it must be my knowledge that is at fault. Because obviously SOMEBODY knows what these things mean. Right?

Now what does this have to do with anything, you ask? Okay, here's where it all ties together: You see, your thread is like the work glove on the conveyor belt. At first you will be mad. But then you will become resigned to watching it slowly disappear into the distance, off towards the horizon of the Daniweb ether, and all while Laverne sits smirking.

Just remember: you do have the consolation of going home and cuddling up with a soft stuffed animal.

Boo Boo Kitty never judges.

All will be well with the world.


.

commented: Reminiscence Rep +3
commented: But not helpful. -2
commented: wtf??? -5

>>But it does not operate well.

What exactly does that mean?

lines 23-31: If the return value is -1 then the program prints an error message and continues to process as if the return value were ok ??? That's a little like when chopping an onion, you accidentally chop off a finger but say "That's ok, I'll just finish chopping the onion."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.