SystemVIPC now compatible with Ruby 1.8 and Ruby 1.9
1
SystemVIPC is a Ruby 1.8 module for System V Inter-Process Communication: message queues, semaphores, and shared memory.
We Have 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
- $key = ftok '/tmp/shm' , IPC_CREAT
- $sh = SharedMemory.new($key, 33554432, IPC_CREAT | 0660)
- $sh.attach
- child = open("|-","w+")
- if child.nil?
- $sh.write('In Shared Memory')
- sleep 2
- $sh.write('now showing you the world!')
- else
- sleep 1
- puts $sh.read(100)
- sleep 3
- puts $sh.read(100)
- 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 as dummy events syncronization..
Hope this is helpful....
View The SystemVIPC documentation at : http://sysvipc.rubyforge.org/
Written By:
Moustafa A. Emara ( moustafaemara.wordpress.com )
Comments
Post a Comment
eSpace podcast Prodcast
Archive
- September 2011
- April 2011
- March 2011
- December 2010
- November 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- November 2009
- October 2009
- September 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- September 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- April 2007
- March 2007
Latest Comments
- SpectraMind Commented on Egypt Wins UK's National Outsourcing Association Award
- Rofaida Awad Commented on Go Egypt Go!
- Different Mike Commented on Only idiots change their iPhone root password!
- Mike Commented on Only idiots change their iPhone root password!
- smile Commented on Only idiots change their iPhone root password!

