Page 1 of 1
Don't Want the 2 Copies of Program Running
Posted: Tue Sep 27, 2005 7:52 pm
by Alex
How do I keep a program from running two copies of itself at once? Can I write the program so that it checks the currently running processes, and exits if it discovers that there is already a copy of itself in memory?
In BASH I'd simply do something like this:
Code: Select all
RESULT=`ps -A | grep -c foobar`
if [ RESULT > 1 ]
then
exit
fi
Is there an equivalent for purebasic?
Thanks,
Alex
Posted: Tue Sep 27, 2005 7:56 pm
by Droopy
Try RunOnlyOneInstance() from the Droopy Lib
Author : netmaestro
Posted: Wed Sep 28, 2005 6:10 am
by Alex
Thanks, I'll try it!
Alex
Droopy wrote:Try RunOnlyOneInstance() from the Droopy Lib
Author : netmaestro
Posted: Wed Sep 28, 2005 2:47 pm
by Paul
Good luck trying to run Windows library on Linux OS

Posted: Wed Sep 28, 2005 2:55 pm
by traumatic
Paul wrote:Good luck trying to run Windows library on Linux OS


Posted: Wed Sep 28, 2005 5:06 pm
by Alex
Thanks for the heads up! I hadn't had a chance to look at the library yet.
Do you have a good suggestion for doing the same thing under Linux?
Thanks,
Alex
Paul wrote:Good luck trying to run Windows library on Linux OS :)
Posted: Wed Sep 28, 2005 8:08 pm
by Droopy
Sorry

Posted: Thu Sep 29, 2005 5:15 pm
by Alex
No objections. At least you tried. Is your library written in purebasic? Could it possibly be compiled on Linux?
Droopy wrote:Sorry :oops:
Posted: Thu Sep 29, 2005 6:45 pm
by Droopy
Code: Select all
ProcedureDLL RunOnlyOneInstance()
*a = CreateSemaphore_(NULL,0,1,GetProgramName())
If *a <> 0 And GetLastError_()= #ERROR_ALREADY_EXISTS
CloseHandle_(*a)
End
EndIf
EndProcedure
CreateSemaphore is Win32 API function.
You must look as the same function in the GTK ?
Posted: Thu Sep 29, 2005 7:11 pm
by ts-soft
See on:
http://lidn.sourceforge.net/ and search for: gdk_threads_mutex
i have no example for you

Posted: Fri Sep 30, 2005 11:18 am
by olejr
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:
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
Only "problem" is that if your app crash, or you quit by <ctrl-c>,
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..

Posted: Mon Oct 03, 2005 2:55 pm
by Alex
Thanks, I'll give it a try.
Alex
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:
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
Only "problem" is that if your app crash, or you quit by <ctrl-c>,
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: