I am trying to implement a JIT compiler (I have very geeky hobbies).
I would like to have one main process that keeps some persistent variables, and a second process (that has been compiled just-in-time) that does some computation and can access and write on the persistent variables.
The second process can change and be recompiled, but the persistent variables have to stay same between two executions of the second process.
My first question is: is shared memory the right tool for it? (Also in terms of performance, because I want the execution to be as fast as possible.)
My second question is: if I use shared memory as described in shm_overview.7, it seems to me that any other process with the same uid can access it. How can I prevent it? I would like only the two above processes to be able to access this shared memory.
An alternative architecture you might consider is dynamic loading. Instead of 2 processes, you have just the first one; it uses
dlopen()
to load your newly compiled code. It calls the entry point of this "library", and the code has access to all the space including the persistant variables. On return, you unload the library, ready for the next "run".Creating such a loadable library and calling it is fairly simple, and faster than executing a whole new process. There are no problems with permissions, as your one and only process decides what to load and run.