Linux process localstorage

What is the best linux way to store the value associated with a process.

We have a library that we dynamically load and unload. During operation, the library will create a large data structure ... about 1 GB. When the library is unloaded, it leaves this data structure in the process memory. When the process reloads the library, we need a library to find the address of this data structure. We do this because our server software updates take place in real time and cannot afford the time to create this data structure. we also delete the update when the update fails, so this allows us to quickly revert to the previous version. We do not have the ability to change the code of the calling application so that it can pass us the address of the data structure.

pthreads has local thread storage. I am looking for something similar to a local thread store, except that it will be a local process store. I do not want to create a file in a temporary directory, because our servers break and restart from time to time. I do not want to deal with cleaning dead process data files. I looked at / proc / directory , which would be ideal as it leaves after the process is complete, but I'm not sure if the functions inside proc_fs.h are meant to be called from a user application.

Thanks!

+1
source share
1 answer

The executable loading the library can't just save this for you and transfer it after loading the library?

In any case, some alternatives:

  • Scan /proc/self/maps for data - depending on how you allocated it.
  • Open the file, dup2() it in the "magic" fd, rm file, and then write status data to it. When it is closed, it will completely disappear.
  • Download a small library that has the sole purpose of storing this address for you. dlopen() it reboots again and asks for the address.
  • Set / read environment variable

Personally, I would go with an environment variable.

+2
source

Source: https://habr.com/ru/post/988238/


All Articles