Re: SHM_INFO and SHM_STAT
Re: SHM_INFO and SHM_STAT
- Subject: Re: SHM_INFO and SHM_STAT
- From: Terry Lambert <email@hidden>
- Date: Tue, 1 Apr 2008 20:31:30 -0700
On Mar 31, 2008, at 11:23 AM, Christof Rath wrote:
Hey there,
I try to compile a robot framework that is written for Linux. My
problem is, that it uses shmctl() commands that aren't defined in
shm.h (like on linux systems).
The four commands in use: SHM_INFO, SHM_STAT, SHM_LOCK and SHM_UNLOCK
a code fragment:
[...]
struct shmid_ds shm_info;
max_id = shmctl( 0, SHM_INFO, &shm_info );
if (max_id >= 0) {
for ( int i = 0; (_memptr == NULL) && (i <= max_id); ++i ) {
shm_id = shmctl( i, SHM_STAT, &shm_segment );
if ( shm_id < 0 ) continue;
[...]
or:
[...]
if (swapable) {
shmctl(__shared_mem_id, SHM_UNLOCK, NULL);
} else {
shmctl(__shared_mem_id, SHM_LOCK, NULL);
}
[...]
is there a workaround? Can anybody tell me how to access this
information?
Use standard APIs instead:
<http://www.opengroup.org/onlinepubs/009695399/functions/shmctl.html>
?
SHM_INFO you can emulate by writing code to popen the "ipcs" command.
You are better off using ftok(0 to identify a shared memory segment
key specifically, rather than trying to figure out the next available
one.
SHM_STAT does not appear to be a useful API, since it only returns an
array index, and that array index could in no way be useful to you
directly, since you can't access the array which is being indexed by
the number which would be returned.
SHM_LOCK/SHM_UNLOCK are really dangerous, since you are asking that
the memory region be wired down. You can ask for this via the
standard interfaces mlock() and munlock(). Typically, this is a bad
idea. Wiring down physical memory is constrained by administrative
limits which can not be bypassed, so if you ask for too much, you will
get none. These interfaces work equally well in Linux, and are more
portable.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden