Determine if only one instance is running: Difference between revisions

m
Remove needless import
(Remove needless logging)
m (Remove needless import)
Line 372:
All we need is to generate a unique name for our program and pass it as the address when calling bind(). The trick is that instead of specifying a file path as the address, we pass a null byte followed by the name of our choosing (e.g. "\0my-unique-name"). The initial null byte is what distinguishes abstract socket names from conventional Unix domain socket path names, which consist of a string of one or more non-null bytes terminated by a null byte.
Read more here: [https://blog.petrzemek.net/2017/07/24/ensuring-that-a-linux-program-is-running-at-most-once-by-using-abstract-sockets/]
<lang d>import std.socket;
 
import std.socket;
 
bool is_unique_instance()
{
import std.socket;
auto socket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
auto addr = new UnixAddress("\0/tmp/myapp.uniqueness.sock");
8

edits