even better:
This handles the problem for existing a pre-existing key that belongs to another process. Those keys are assigned sequentially by the kernel. You can't know ahead of time if "1492" is in use already or not.
Plus, based on the OP's repsonses, I would suggest to the OP to read the man page for shmget. Simply copying code off the internet is NOT a good idea. That code has several problems, as pointed out.
Dear Reader,
Is is necessary to attach / dettach the shared memory segments for write operations , if more than one program is accessing same shared memory segments..
I have used semaphore mutex and still I'm getting segmentation fault when I write to the segment when other program is already... (1 Reply)
I am running HP-UX B.11.11.
I'm increasing a parameter for a database engine so that it uses more memory to buffer the disk drive (to speed up performance). I have over 5GB of memory not being used.
But when I try to start the DB with the increased buffer parameter I get told.
"Not... (1 Reply)
Hi all :confused: ,
I am new to unix.I have been asked to implement shared memory in user's mode.What does this mean?What is the difference it makes in kernel mode and in users mode?What are the advantages of this impemenation(user's mode)?
And also i would like to know why exactly shared... (0 Replies)
hi all
I have been asked to implement shared memory in user mode?But :rolleyes: im not understanding how to do this.And what does it mean in user mode?Is it that we need to simulate what kernal does...like attaching ,detaching memory..etc...?
And would also like to know why shared memory is... (3 Replies)
hi,
this is the problem: i want to swap a linked list between 4 processes (unrelated), is there any way i can do that just by sending a pointer to a structure?
//example
typedef struct node
{
int x;
char c;
struct node *next;
} node;
or i should send the items ( x,c ) by... (9 Replies)
I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability.
Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Hello.
I am new to this forum and I would like to ask for advice about low level POSIX programming.
I have to implement a POSIX compliant C shared library.
A file will have some variables and the shared library will have some functions which need those variables.
There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies
LEARN ABOUT OSF1
nshmget
nshmget(3) Library Functions Manual nshmget(3)NAME
nshmget - Returns (or creates) the ID for a shared memory region (libnuma library)
SYNOPSIS
#include <numa.h> #include <sys/shm.h>
int nshmget(
key_t key,
size_t size,
int shmflg,
memalloc_attr_t *attr );
PARAMETERS
Specifies the key that identifies the shared memory region. The value for the key parameter can be IPC_PRIVATE or a random number other
than zero (0). If the value of key is IPC_PRIVATE, it can be used to assure the return of a new, unused shared memory region. Specifies
the minimum number of bytes to allocate for the region. Specifies the creation flags. See shmget(2) for a description of these flags.
Points to a memory allocation policy and attributes structure. If the specified key does not exist, and a shared memory region is created,
these attributes will be assigned to the memory object created to manage the shared memory region.
DESCRIPTION
If the attr argument is NULL, the nshmget() function behaves identically to the shmget() function.
If the attr argument is non-NULL, it points to a memory allocation policy and attributes structure that specifies where the pages should be
allocated for a newly created shared memory region. To change the policy of an existing shared memory region, use the nmadvise()function.
If the mattr_policy member of the structure pointed to by attr is MPOL_DIRECTED and the mattr_rad member is RAD_NONE, the system will
choose the Resource Affinity Domain (RAD) where the pages of the shared memory region will be allocated from among the RADs specified in
the mattr_radset member of *attr. If the mattr_radset member is the empty set, the system will select a RAD for the memory object from
among all of the RADs in the caller's partition, and the overflow set will be the empty set.
RETURN VALUES
Success. Failure. In this case, errno is set to indicate the error.
ERRORS
In addition to the error conditions for the shmget() function, the nshmget()function sets errno to one of the specified values for the
specified condition: A non-NULL attr argument points to an invalid address. The structure pointed to by the attr argument contains an
invalid memory allocation policy or invalid RAD. The striped allocation was requested with a stride of 0.
SEE ALSO
Functions: shmget(2), nmadvise(3), numa_intro(3)
Files: numa_types(4), shmid_ds(4)nshmget(3)