One copy of the program?

Linux specific forum
Foz
Addict
Addict
Posts: 1359
Joined: Tue Nov 13, 2007 12:42 pm
Location: Manchester, UK

Re: One copy of the program?

Post by Foz »

Which is fine for Windows, but not Linux.
nikoniko
User
User
Posts: 20
Joined: Fri Nov 11, 2011 7:58 am

Re: One copy of the program?

Post by nikoniko »

Check proccess list to find running copy
run ps -aux (linux/macosx) or tasklist (windows, may be blocked by admin or viruses) in hte hidden console and try to find unique application name in console output
lakomet
User
User
Posts: 53
Joined: Mon Apr 04, 2011 3:56 am
Location: Russia,Angarsk

Re: One copy of the program?

Post by lakomet »

Compile and try to run twice.

Code: Select all

Procedure GetRunningProgramm(prog.s)
     Protected RegEx.i = CreateRegularExpression(#PB_Any, "[0-9]+")
     Protected Directory.s = "/proc"
     Protected ExamDir.i = ExamineDirectory(#PB_Any, Directory, "*.*") 
     Protected OutFile.i
     Protected Sum.i=0
     If RegEx And ExamDir
          While NextDirectoryEntry(ExamDir)
               If MatchRegularExpression(RegEx, DirectoryEntryName(ExamDir))
                    OutFile = ReadFile(#PB_Any,Directory+"/"+DirectoryEntryName(ExamDir)+"/cmdline")
                    If  OutFile
                         If FindString(ReadString(OutFile), prog, 1)
                              Sum + 1
                         EndIf 
                         CloseFile(OutFile)
                    EndIf 
               EndIf
          Wend
          FinishDirectory(ExamDir)
     EndIf
     ProcedureReturn Sum
EndProcedure

If GetRunningProgramm(ProgramFilename())>1
     MessageRequester("","yes working")
Else
     MessageRequester("","no working")
EndIf
ps -aux Works on the same principle :?:
Linux Mint Maya(Mate), x86, PureBasic 5.00(5.10b1)
Post Reply