1819871 Members
2486 Online
109607 Solutions
New Discussion юеВ

shmat()

 
Victor.Lin
Occasional Contributor

shmat()

I remenber that my program worked well the first time, but failed several times later.
I guess that the problem is that only shmget() shmat() and shmdt() are performed, but shmctl() is not. Ultimately the resource runs out.
But how can I remove this memory "garbage" ?
I use "ipcrm -m" to remove these shared memory and reboot the system, but the problem is still there.
3 REPLIES 3
Ravi_8
Honored Contributor

Re: shmat()

shmctl(free) makes all shared memory free
never give up
Victor.Lin
Occasional Contributor

Re: shmat()

ravi:
What did you mean ?
int shmctl(int shmid, int cmd, struct shmid_ds *buf);
There are only IPC_STAT IPC_SET IPC_RMID SHM_LOCK SHM_UNLOCK for cmd. Where is free ?
A. Clay Stephenson
Acclaimed Contributor

Re: shmat()

No, here's what you want to do:

struct shmis_ds dummy;

int my_shmid; /* I assume you have done a shmget to get the shared memory identifier*/

result = shmctl(my_shmid,IPC_RMID,&dummy);

This will only work if you have the proper permissions (super-user or shm segment owner)

Regards, Clay
If it ain't broke, I can fix that.