The web shows me plenty of ways to create a single instance app, and I can't see the forest for the trees anymore. My application is a script that acts as a layer between domotica and a web interface. Due to the communication happening over a serial port, it's important only one app has access to the serial port at the same time.
What is the currently accepted "best" way to create a single instance application on Linux? There are a couple of requirements and constraints:
- It's a Raspberry Pi, so the more lightweight, the better.
- I'm running Raspbian 4.1.18.
- I have full control over everything that runs, and everyone that has physical access to the machine. So I don't need to be able to solve situations where someone, for example, renames a locked file deliberately.
- If another instance of my app is running, I want the new instance to shut down. It doesn't need to pass anything to the old instance.
- I'd prefer if it was C89 and gcc compatible. But I suspect the code will be short enough to fix even if it's not.
Thanks in advance!