Operating System - HP-UX
1829929 Members
2082 Online
109998 Solutions
New Discussion

a question about share memory

 
William Cai_1
New Member

a question about share memory

I am developing a software system on HP9000. Now I encounted a problem. I create a block of share memory, store some important information into it. but sometimes the information is changed automaticly. My program do not do that . Is there some system process change the contain in the share memory. Anyone can answer my question?

Thank you very much!
from China
8 REPLIES 8
U.SivaKumar_2
Honored Contributor

Re: a question about share memory

Hi,

Ensure that shared memory is sufficient for other programs.
Some running program may be already accessing the shard memory address segments which your program is using. Try using higher order of shared memory address in your program which can be free.
regards,
U.SivaKumar

Innovations are made when conventions are broken
Stefan Farrelly
Honored Contributor

Re: a question about share memory

According to the manpage for shmget any process can also access this shared memory segment if it has the proper permissions - so yes, other processes can use it/overwrite it.

For a test trying running it as root and locking it into memory (shmctl) and see if it still gets overwritten.
Im from Palmerston North, New Zealand, but somehow ended up in London...
William Cai_1
New Member

Re: a question about share memory

thank U.SivaKumar and Stefan Farrelly.

I get the key use ftok function,I think it's unique in the whole system.

I'll try to use shmctl function , But I have to run the program as a common user.

what can I do?

Is it system process overwrite the share memory?

from China
William Cai_1
New Member

Re: a question about share memory

how to use shmctl?
key = ftok("/usr/caiw",'r');
shmid = shmget(key,SHMSIZE,IPC_CREAT|IPC_EXCL|0666);
if (shmid == -1){...}
shmptr = shmat(shmid,0,0);

shmctl(shmid,IPC_STAT?IPC_SET,buff);
from China
U.SivaKumar_2
Honored Contributor

Re: a question about share memory

Hi,

Use this command to see the information of current active shared memory segments like memory address , owner and permissions in the system

#ipcs -m

Avoid using those segments shown by the above command in your program.

regards,
U.SivaKumar
Innovations are made when conventions are broken
William Cai_1
New Member

Re: a question about share memory

[/home/caiwl]ipcs -m
IPC status from /dev/kmem as of Wed Dec 11 17:18:29 2002
T ID KEY MODE OWNER GROUP
Shared Memory:
m 0 0x41200629 --rw-rw-rw- root root
m 1 0x4e0c0002 --rw-rw-rw- root root
m 2 0x4124037b --rw-rw-rw- root root
m 44003 0x2ee8af94 --rw-r----- oracle dba
m 41004 0x0001e243 --rw-rw-rw- tuxdman app
m 8005 0x00000000 --rw------- tuxdman app
m 12006 0x64203cec --rw-rw-rw- root sys
m 2007 0x6b203cec --rw-rw-rw- root sys
m 2008 0x000003e8 --rw-rw-rw- tuxdman app
m 21009 0x7a203cec --rw-rw-rw- caiwl users
m 4010 0x78203cec --rw-rw-rw- tuxdman app

my key is 0x64203cec and 0x6b203cec,I think is unique in the system.
:'(
from China
Deepak Extross
Honored Contributor

Re: a question about share memory

It's rather improbable that an unrelated process will use the same key to get a handle to your shared memory segment. Most likely, an old instance of your process is running and messing up your shared memory.

U.SivaKumar_2
Honored Contributor

Re: a question about share memory

Hi,

Iam not a expert in calls.

try changing the permission of your program shared memory segment to rw-----

regards,
U.SivaKumar
Innovations are made when conventions are broken