Computing.Net > Forums > Unix > Shared Memory

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Shared Memory

Reply to Message Icon

Original Message
Name: HaukyPauky
Date: May 31, 2005 at 12:25:24 Pacific
Subject: Shared Memory
OS: XP
CPU/Ram: Centrino 1400
Comment:

Hi,

does anyone know how i can read out a shared memory segment by using the shm_id? I have two progs. the one creates the segment and writes a value into the shm, which is given as parameter. the second is supposed to read out the shm unfortunately it shows me the environment variable USER=***** for my user account. the following are fragments of the programm code. WOuld be great if someone could help me.

Programm one:

int main(int argc, int argv[]){

int i, id, arg;
char *shared_mem;

id = shmget(IPC_PRIVATE, SEGSIZE, IPC_CREAT | 0644);

shared_mem = shmat(id, 0, 0);

arg = argv[1];
*shared_mem = arg;

printf("Die id vom Shared Memory ist %i\n", id);

...

programm two:

int main(int argc, char *argv[]){

int i, id, id2, *shared_mem, *tmp;
char *arg;

arg = argv[1];
id = atoi(arg);

shared_mem = (int *)shmat(id, 0, 0);

printf("Der inhalt vom Shared Memory ist %s\n", *shared_mem);

...

cheers
Hauke


Report Offensive Message For Removal








Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software