Shared memory Problem

  • Follow


HI all I am new to unix programming,
I have client and server that uses shared memory I have code like this,
key = 5678;
if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
        perror("shmget");
        exit(1);
    }
if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
        perror("shmat");
        exit(1);
    }
  /*Initialize some data to the shm*/
Basically server creates shared memory and stays in the memory untill
the
data in shm is modified. Where as client acess the shared memory
and changes the shm value. But problem is even though server is not
running
client can access the shared memory . Can some body explain how
to delete or free the shared memory when client is closing down. Thanks

Prasanna Bhat mavinkuli

0
Reply boss_bhat (11) 11/3/2005 11:44:42 AM

Mavinkuli wrote:

> HI all I am new to unix programming,
> I have client and server that uses shared memory I have code like this,
> key = 5678;
> if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
>         perror("shmget");
>         exit(1);
>     }
> if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
>         perror("shmat");
>         exit(1);
>     }
>   /*Initialize some data to the shm*/
> Basically server creates shared memory and stays in the memory untill
> the
> data in shm is modified. Where as client acess the shared memory
> and changes the shm value. But problem is even though server is not
> running
> client can access the shared memory . Can some body explain how
> to delete or free the shared memory when client is closing down. Thanks
>
> Prasanna Bhat mavinkuli



shmctl() with cmd option as IPC_RMID or shmdt() will destroy shared
memory .

0
Reply spat 11/3/2005 12:40:08 PM


"Mavinkuli" <boss_bhat@yahoo.co.in> wrote in message 
news:1131018282.788930.153280@g47g2000cwa.googlegroups.com...

> if ((shmid = shmget(key, SHMSZ, IPC_CREAT | 0666)) < 0) {
>        perror("shmget");
>        exit(1);
>    }
> if ((shm = shmat(shmid, NULL, 0)) == (char *) -1) {
>        perror("shmat");
>        exit(1);
>    }

> client can access the shared memory . Can some body explain how
> to delete or free the shared memory when client is closing down. Thanks

    shmctl(IPC_RMID);

    DS


0
Reply David 11/4/2005 6:46:27 AM

2 Replies
115 Views

(page loaded in 0.14 seconds)

Similiar Articles:













7/23/2012 2:32:50 AM


Reply: