+def getOmniNamesPid(port):
+ """
+ Return OmniNames pid by port number.
+ """
+ import sys,subprocess,re
+ if sys.platform == "win32":
+ # Get process list by WMI Command Line Utility(WMIC)
+ # Output is formatted with each value listed on a separate line and with the name of the property:
+ # ...
+ # Caption=<caption0>
+ # CommandLine=<commandline0>
+ # ProcessId=<processid0>
+ #
+ #
+ #
+ # Caption=<caption1>
+ # CommandLine=<commandline1>
+ # ProcessId=<processid1>
+ # ...
+ cmd = 'WMIC PROCESS get Caption,Commandline,Processid /VALUE'
+ proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+ # Get stdout
+ allProc = proc.communicate()[0]
+ # find Pid of omniNames
+ pid = re.findall(r'Caption=.*omniNames.*\n?CommandLine=.*omniNames.*\D%s\D.*\n?ProcessId=(\d*)'%(port),allProc)[0]
+ else:
+ cmd = "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*%s\" | awk '{print $1}'"%(port)
+ proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+ pid = proc.communicate()[0]
+ pass
+
+ return pid
+# --
+
+def killOmniNames(port):
+ """
+ Kill OmniNames process by port number.
+ """
+ try:
+ pid = getOmniNamesPid(port)
+ if pid: killpid(pid)
+ except:
+ pass
+ pass
+# --