Quote:
Originally Posted by JudyL
This requirement cannot be changed.
|
I strongly doubt this, but I will appease the request
.
Under normal circumstances, global variables in C (even those with file scope) and function variables declared with
static are put in the
.data section the executable unless they are uninitialized (if they are uninitialized, they are put in the
.bss section. The problem is that once program execution begins, it is not necessarily true that changes to the file will reflect changes in the program image. So this gives you some place within a file to store the data, but you should not use the symbol(s) there from within your program (since the changes will not be written to the file after exiting).
So in order to account for this, you need to have some way of finding your static variable data in an open file descriptor of the executable from within the program. Obviously, this depends on the executable format (of which linux supports a few). I will assume that you are dealing with ELF files in particular. In this case, you might use libelf or libbfd to find the offset and size of a symbol in the file. Once you find this information, you could mmap it to a struct or something (in both programs, using
MAP_SHARED).
You can use file locking to ensure that the two processes don’t open the same file for reading and writing at the same time.