In BASH I'd simply do something like this:
Code: Select all
RESULT=`ps -A | grep -c foobar`
if [ RESULT > 1 ]
then
exit
fi
Thanks,
Alex
Code: Select all
RESULT=`ps -A | grep -c foobar`
if [ RESULT > 1 ]
then
exit
fi
Droopy wrote:Try RunOnlyOneInstance() from the Droopy Lib
Author : netmaestro
Paul wrote:Good luck trying to run Windows library on Linux OS :)
Droopy wrote:Sorry :oops:
Code: Select all
ProcedureDLL RunOnlyOneInstance()
*a = CreateSemaphore_(NULL,0,1,GetProgramName())
If *a <> 0 And GetLastError_()= #ERROR_ALREADY_EXISTS
CloseHandle_(*a)
End
EndIf
EndProcedure

Code: Select all
;
; AppRunning(Name.s) ; return 1 if app allready running, else 0
; ; Name.s can be anything unique
;
; Compile the example like: pbcompiler test.pb -e exename
;
If(AppRunning("hello1224"))
PrintN("App allready running...")
End
EndIf
PrintN("Enter to exit")
Input()
End
olejr wrote:I made a quick PB Library with only one function in it: AppRunning()..
There's no docs, or anything.. Just axtract and copy the apprunning_lib to the purelibraries/userlibraries folder..
Download: apprunning_lib.tar.gz
(source included)
Usage:Only "problem" is that if your app crash, or you quit by <ctrl-c>,Code: Select all
; ; AppRunning(Name.s) ; return 1 if app allready running, else 0 ; ; Name.s can be anything unique ; ; Compile the example like: pbcompiler test.pb -e exename ; If(AppRunning("hello1224")) PrintN("App allready running...") End EndIf PrintN("Enter to exit") Input() End
it take some time before the semaphore is released by the system..
Oh.. btw.. have no idea if the C source is the "right" way of doing a BP lib, but it seem to work.. :wink: