I'm involved in a project with multiple teams which are developing C code for a Linux machine and we would like to have our program pass data to one of the other group's programs. The immediate idea is to have shared memory between the programs which would simply consist of variables whose size and offset from the beginning of the file are specified and have one program read from it while the other writes to it.
Will we run into any problems if we simply treat this file like any other file in our respective programs (i.e. fd = open(....) and just write to/read from fd at our leisure) or are there special steps that need to be taken in order to avoid simultaneously accessing the same data or something of that nature?
I'm involved in a project with multiple teams which are developing C code for a Linux machine and we would like to have our program pass data to one of the other group's programs. The immediate idea is to have shared memory between the programs which would simply consist of variables whose size and offset from the beginning of the file are specified and have one program read from it while the other writes to it.
Will we run into any problems if we simply treat this file like any other file in our respective programs (i.e. fd = open(....) and just write to/read from fd at our leisure)
I don't see the point of using read()/write() if you're also mapping in shared memory. It still ought to work, I think, but it really defeats the point.
You don't need to hardcode offsets, either, you can use C's own complex data structures inside shared memory:
The only caveat is that the structure can't hold pointers. Pointers from one process won't make sense in another. Even pointers to inside the shared area might not work since the shared area might not always end up in the same address in every process. If you need something like pointers, use long integers that mean the index of an array inside the shared memory (or just an offset from the beginning of shared memory).
Quote:
are there special steps that need to be taken in order to avoid simultaneously accessing the same data or something of that nature
yes, always, even if you were just read/writing the files all the time instead of mapping them.
Since you have the file open anyway, you can use POSIX advisory locking to control who gets to access the memory when. These functions will block when the section you ask for is busy with something else.
I am using a cluster where all the programs are located in a shared folder (I can only read but not modify anything in this folder).
The path of the share folder is in my .bashrc file (and thus also in my $PATH - first position):
source /home/shared/bashrc
But some of the programs are... (5 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)
Hi all
I hope I am posting in the right section. If not please excuse me and redirect me to the right section.
Here is my problem:
I am using a shared hosting plan at Godady. I have shell access and of course my own folder.
I would like to be able to install programs in my own folder... (4 Replies)
I was curious how to tell which programs are accessing a file (libobjc.A.dylib) in /usr/lib
This file seems to be the culprit in a bunch of Safari crashes, and I just wanted to know if and what other programs use it.
Also, I was curious what a good way to find out what files are being written... (4 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)
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)
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)
How can you make a program as Memory resident in AIX.
If I make a program as a memory resident program whether all the parts of the program like code and data (stack) segements of the program will be loaded in to the Memory.
For Ex:
I have a C code which is creating array of 10000 long ints... (4 Replies)
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)