This task is to determine if there is only one instance of an application running. If the program discovers that an instance of it is already running, then it should display a message indicating that it is already running and exit.

 
bool is_unique_instance()
{
    import std.socket;
    auto socket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
    auto addr = new UnixAddress("\0/tmp/myapp.uniqueness.sock");
    try
    {
        socket.bind(addr);
        return true;
    }
    catch (SocketOSException e)
    {
        import core.stdc.errno : EADDRINUSE;
 
        if (e.errorCode == EADDRINUSE)
            return false;
        else
            throw e;
    }
}
 