These questions How to block running two instances of the same program? , How to create a single instance application in C or C++ and Preventing multiple instances of my applica
This is not really a complete answer, but look into something like holding a specific file handle for exclusive access. You can use this like a mutex, but with the added benefit that the OS should "clean up" the handle on process termination automatically.
I cannot speak to if this will work on Linux, but at least on Windows, this should let you achieve the same effect. Hope that helps.