开发者

linux process localstorage

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

We have a library that we dynamically load and unload. While running, the library will create a large data structure....about 1GB. When the library is unloaded it leaves that data structure in the process' memory. When the process reloads the library we need the library to be able to find the address of this data structure. We do this because updates to our server software occur in real time and can't afford the time to create that data structure. we also un-update when an update fails, so this lets us fall back to a previous version quickly. We do not h开发者_如何学JAVAave the ability to change the code of the calling application so it could pass us the address of the data structure.

pthreads has thread local storage. I am looking for something analogous to thread local storage except it would be process local storage. I don't want to create a file in a temp dir because our servers crash and restart from time to time....I don't want to deal with having to clean dead process data files. I was looking at the /proc/ directory, which would be ideal since it goes away after a process terminates, but I am unsure if functions inside proc_fs.h are meant to be called from a user-land application.

Thanks!


The executable that loads the library can't just keep this for you, and pass it after loading the library?

Either way, some alternatives are:

  • Scan /proc/self/maps for the data - depending on how you allocated it.
  • Open a file, dup2() it to a "magic" fd, rm the file and then write your state data to it. It'll go away completely when closed.
  • Load a tiny library which has the sole purpose of storing this address for you. dlopen() it again when reloaded, and ask it for the address.
  • Set/read an environment variable

Personally I'd go with the environment variable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜