[Gllug] Possible to read shared memory from bash?

Pete Ryland pdr at pdr.cx
Fri Oct 6 21:35:45 UTC 2006


On 06/10/06, Julian Somers <lists at bigpip.com> wrote:
>
> On 14:51 Thu 05 Oct     , - Tethys wrote:
> > On 10/5/06, Julian Somers <lists at bigpip.com> wrote:
> >
> > >Bash can see my shared memory block with `ipcs`, and delete it with
> > >`ipcrm -M $shmkey`. Is there a way to read its contents?
> >
> > Not off the top of my head, no. But it should be trivial to knock up a
> > wrapper around shmat(3) that will give you access to shared memory
> > segments from a shell.
>
> Since my C doesn't even stretch to knocking up a trivial wrapper, I have
> made a php script that fetches the stuff out of shared memory for the
> shell scripts. Probably more of a pass-the-parcel than a wrapper, but it
> works.
>
> My understanding of shared memory is that I need to avoid simultaneous
> writes, but don't need to worry about simultaneous reads. Is this the
> case? And do I need to block anything from reading the memory while
> I'm writing to it?


Can you not re-write your bash scripts in php?

#!/usr/bin/php works just the same. :-)

It's ok to have multiple readers, but reading memory that is being written
to is normally to be avoided, and multiple writers to the same location is
definitely to be avoided (but different parts of the same shared memory is
of course ok).  You'd normally use some sort of locking mechanism, that is a
thing that gets set atomically when you want to write to the shared memory.
When locked, the other processes should block until it is unset.  This can
be implemented in any number of ways, from a semaphore to a lock file.

Another approach is to use some sort of intermediary that has sole control
of the memory through which all the other things get access.

Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20061006/857594e2/attachment.html>
-------------- next part --------------
-- 
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list