[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

shared memory example

Joe Van Dyk

4/4/2005 8:42:00 PM

Can someone post a really small example of connecting to sysv shared
memory and accessing data there?

I'm trying to connect to some previously-created shmem and it's not
really working.

key = SystemVIPC.ftok("/tmp/key_file", 1)
shmem = SharedMemory.new(key)
p shmem.size

I get: "No such file or directory - shmget(2) (Errno::ENOENT)" when
trying to get shmem.

Thanks in advance,
Joe


2 Answers

Caleb Tennis

4/5/2005 12:09:00 PM

0

On Monday 04 April 2005 03:41 pm, Joe Van Dyk wrote:
> key = SystemVIPC.ftok("/tmp/key_file", 1)
> shmem = SharedMemory.new(key)
> p shmem.size

Don't forget to shmem.attach.

You can use the (linux) command "ipcs" to take a look at existing shared
memory segments, and make sure you are indeed attaching to what you think you
are. You should also verify that the value of "key" matches up to the real
key value of the segment (again, using ipcs).

HTH,
Caleb


Joe Van Dyk

4/6/2005 1:32:00 AM

0

On Apr 5, 2005 5:09 AM, Caleb Tennis <caleb@aei-tech.com> wrote:
> On Monday 04 April 2005 03:41 pm, Joe Van Dyk wrote:
> > key = SystemVIPC.ftok("/tmp/key_file", 1)
> > shmem = SharedMemory.new(key)
> > p shmem.size
>
> Don't forget to shmem.attach.
>
> You can use the (linux) command "ipcs" to take a look at existing shared
> memory segments, and make sure you are indeed attaching to what you think you
> are. You should also verify that the value of "key" matches up to the real
> key value of the segment (again, using ipcs).
>
> HTH,
> Caleb

It's failing on SharedMemory.new(key). I tried printing the key (with
puts key) and it's different than what ipcs is reporting as the id.