An old Unix trick for saving databases
October 19, 2012
Suppose that you have a program with a significant in-memory database, or just in-memory state of some sort. You need to save or checkpoint the database every so often, but you have a big enough database that the program will pause visibly while you write everything out. In the modern era, people might reach for threads and start spraying locking over their in-memory data structures and so on. But in the old days you didn't have threads so you couldn't do it the hard way; instead, you had to do it the easy way.
The traditional easy Unix way of handling this is to just
(Because the database-saving child has to be deliberately created by the
main process, the main process can generally guarantee that the database
is in a consistent state before it
This approach has the great advantage that it's generally dirt simple to implement (and then relatively bombproof in operation). You probably have a routine to save the database when the program shuts down, so a basic version is to fork, call this routine, and then exit. However it has at least two disadvantages, one semi-recent and one that's always been there right from the start.
The semi-modern problem is that
(After all, snapshotting the memory is the entire point of this trick.)
* * *
Atom feeds are available; see the bottom of most pages.