Quote:
Originally Posted by porter
You could have an additional process who's job it is to create and shutdown the shared memory. This process could have some form of IPC to so the other processes can attach and detach, when the last goes, the manager process can clean up and die.
You could have the manage process fork/exec'd by the client libraries when they start so it does not have to prestart, and have setuid bit to run with the appropriate rights other than the first user to start up.
If the clients connect to the manager process with a UNIX domain socket then the manager could use poll() on all connections to monitor that the processes are alive, if they exit uncleanly the socket connection will still die.
I was considering this approach, and it may work...but I thought to myself, why bother use shared memory if I'm going to have a socket connection. In which case, I may as well just relay the entire request to the manager process and let him decision it and not make the memory shared.
Hummm....
Another shared memory question:
Storing pointers in shared memory (of course to other areas of shared memory), can this be done? I think the answer lies in how you attach the shared memory to the process, no? Looking at the shmat call, the second parameter specifies the memory address. I assume this is the "base address" given to the process for the shared memory segment. I would guess that pointers will only be valid throughout all applications accessing the shared memory iff all applications specify this parameter similarly when attaching the segment. Is this correct?
If the above is correct, then I would guess that I may compete with other applications for the address I want to attach to (being a library and all) and that I may not easily be able to guarantee that I can get the address I want. To prevent this, it seems the OS allows one to pass NULL to this parameter and the OS will chose an available address to map to. In which case, I could not really store pointers in shared memory, rather I must store offsets and let the application compute the actual pointer value by adding its individual "base address." This is obviously performance draining....
So...how is that "obstacle" usally overcome?