Determine if only one instance is running: Difference between revisions
Content added Content deleted
(Added Kotlin) |
(→{{header|TXR}}: New section.) |
||
Line 1,038: | Line 1,038: | ||
exit 1 |
exit 1 |
||
}</lang> |
}</lang> |
||
=={{header|TXR}}== |
|||
==== Microsoft Windows ==== |
|||
<lang txrlisp>;;; Define some typedefs for clear correspondence with Win32 |
|||
(typedef HANDLE cptr) |
|||
(typedef LPSECURITY_ATTRIBUTES cptr) |
|||
(typedef WINERR (enum WINERR ERROR_SUCCESS |
|||
(ERROR_ALREADY_EXISTS 183))) |
|||
(typedef BOOL (enum BOOL FALSE TRUE)) |
|||
(typedef LPCWSTR wstr) |
|||
;;; More familiar spelling for null pointer. |
|||
(defvarl NULL cptr-null) |
|||
;;; Define access to foreign functions. |
|||
(with-dyn-lib "kernel32.dll" |
|||
(deffi CreateMutex "CreateMutexW" HANDLE (LPSECURITY_ATTRIBUTES BOOL LPCWSTR)) |
|||
(deffi CloseHandle "CloseHandle" BOOL (HANDLE)) |
|||
(deffi GetLastError "GetLastError" WINERR ())) |
|||
;;; Now, the single-instance program: |
|||
(defvar m (CreateMutex NULL 'TRUE "ApplicationName")) |
|||
(unless (eq (GetLastError) 'ERROR_ALREADY_EXISTS) |
|||
;; mutual exclusion here |
|||
) |
|||
(CloseHandle m) |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |