PDA

View Full Version : IPC shared memory and threads



cyclops
03-20-2010, 06:14 AM
i want to create program with a size 10 and then create and array and put the values entered thru keyboard and store it.here it asks the user to enter the size of the array and then enter integer numbers.

consumer we have to get the array and print it in the consumer


can somebody PLZZZZZZZZZZZZZZZZZZZZZZZZZZZ HELP MEE





#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>

#define SHMSZ 10

main()
{
int a;
int shmid;
int *shm;
key_t key;
int u;
int i;
printf("enter array size\n");
scanf("%d",&u);


int* arrray=(int*) malloc(sizeof(int) * user);

key = 1234;

if((shmid = shmget(key,SHMSZ, IPC_CREAT | 0666)) < 0)
{
perror("shmget");
exit(1);
}

if((shm = shmat (shmid, NULL, 0)) == (int *) -1)
perror("shmat");
exit(1);
}




a =shm;

for(i = 0; i<user;i++)
{ scanf("%d",&a);
array[i]=a;
}

*ar = NULL;

while(*shm != '*')
sleep(1);

exit(0);

}

Salem
03-20-2010, 06:30 AM
There seems to be a plethora of idiots unable to either comprehend forum posting rules OR figure out what to do with a "use code tags" popup when they post code without code tags.

Kudose
04-02-2010, 07:00 PM
I had to bite my tongue when I saw a post from someone in a developing country asking for the complete code from people they are taking jobs from.

MK27
04-03-2010, 09:59 AM
I had to bite my tongue when I saw a post from someone in a developing country asking for the complete code from people they are taking jobs from.

Unless you want to move away from a capitalist economic system, that is the situation you are stuck with. If I am willing to do your job for less money you are obsolete.

In that case, making a distinction based on where someone is located is (still) foolish -- you should not offer help or advise to anyone at all, because anyone could just as easily do the same thing. You will be worth more money if you can keep everything secret from everyone.