Re: Using JNI to access shared memory

From: Gordon Beaton (not_at_for.email)
Date: 03/04/05


Date: 4 Mar 2005 08:24:46 +0100

On 3 Mar 2005 15:42:34 -0800, Lee wrote:
> I have a legacy program running on AIX coded in C that uses shared
> memory to store a sort of an index of information. I've written a C
> library that attaches and extracts information successfully when called
> from another C method. This same library when called from within a JNI
> wrapper method doesn't quite work. It compiles, links, loads and runs
> correctly (ie the debug output is functioning and proper) except when
> it attempts to attach to the shared memory section (via the shmat call
> in the C library) it returns a -24 EMFILE message. Any idea or
> experience with this?

I have successfully used shared memory from JNI (not on AIX, but on
Solaris and Linux), and I can see no inherent reasons why it should
not work.

AFAIK EMFILE means that your process already has too many mapped
segments. How do you change the per-process limit on AIX? Does AIX
implement shmat() with mmap(MAP_SHARED)? If so, maybe you've already
got too many open files in your process and need to close some.

Perhaps you are attempting to map the memory to a specific address in
your process (rarely a good idea), instead of letting the system find
an available area.

Or maybe you've got a basic pointer error in your code, and that's
causing random other things to fail.

At this point I'm just guessing...

/gordon

-- 
[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e


Relevant Pages