Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
823 views
in Technique[技术] by (71.8m points)

operating system - Single instance of application

In general, what are the ways that we can make sure a single instance of application? This is not specific to any programming language. I just want to know how we can prevent starting the second instance of an application?

question from:https://stackoverflow.com/questions/65914077/single-instance-of-application

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I can think of two ways:

  1. 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)

  2. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...