Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired 😉 )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow:

Check if the lock file exists.

Try to delete the lock file to check if there’s really a running process lock the file.

Get the file lock.

If failed to get the lock file, show error that there’s already an instance running –&amp;amp;amp;amp;amp;amp;gt; the end

If successfully get the lock then go on with your application want to do.

When application ended/closed release the lock and delete the file lock.