I can think of two ways:
Application side:
Create a lockfile somewhere on a specified location. If it already exists, another instance is running, otherwise create the lockfile. If the program exits, delete the lockfile. (For example X or firefox do this)
OS side: (Although this wouldn't be that practical)
2.1. For all started binaries, store some hash value somewhere. If an binary is already started, (E.g. the hash value is already available), don't start it.
2.2. This will fail quite often, as you could run only ONE JVM, ONE Python interpreter and so on. So to improve this, the OS could add the commandline arguments for example to the hash value.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…