SystemVIPC now compatible with Ruby 1.8 and Ruby 1.9

September 9, 2008

SystemVIPC is a Ruby 1.8  module for System V Inter-Process Communication: message queues, semaphores, and shared memory.

eSpace Has released a version from SystemVIPC-0.8 RC1 that is compatible and works fine for Ruby 1.8 and Ruby 1.9

It’s really nice to work with SysVIPC with its simple used APIs , Here I’ll provide a simple tutorial for using SysVIPC Shared Memory.

Downloading and Installing

  • Download SysVIPC  Compatible Release for Ruby 1.8 , Ruby 1.9 at :  http://github.com/espace/sysvipc-0.8-rc1.git
  • Extract the Source , then run : ruby1.9 extconf.rb ( note : run with the ruby version you want ) then :  make install Makefile
  • You will have the sysvipc.so file appearing now
  • In all cases you have to put these lines of code :

require ‘sysvipc.so’

include SystemVIPC

Shared Memroy Example

## Testing Shared Memory

  1. $key = ftok ‘/tmp/shm’ , IPC_CREAT
  2. $sh = SharedMemory.new($key, 33554432, IPC_CREAT | 0660)
  3. $sh.attach
  4. child = open(“|-“,”w+”)
  5. if child.nil?
  6. $sh.write(‘In Shared Memory’)
  7. sleep 2
  8. $sh.write(‘now showing you the world!’)
  9. else
  10. sleep 1
  11. puts $sh.read(100)
  12. sleep 3
  13. puts $sh.read(100)
  14. end

Lines 1 ,  2 , 3  we convert the path name into as SysVIPC key , then we initiate if necessary 8 MegaBytes shared Memory Segment associated with key , then finally we attach the shared memory segment.

lines 4 , 5 we for a child for the process

At lines 6 , 8 we use the SharedMemory method write to write two data items to the shared memory segment

lines 11 , 13 the forked child process reads the data written by the parent process in the shared Memory segment and prints it.

sleep call is used for synchronizing the events..

Hope this is helpful….

View The SystemVIPC documentation at : http://sysvipc.rubyforge.org/

One Response to “SystemVIPC now compatible with Ruby 1.8 and Ruby 1.9”

  1. roger Says:

    how does this differ from say mmap shared memory?


Leave a Reply to roger Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: