import psutil
import os
import sys

if os.name == "nt":
    lst = psutil.win_service_iter()
    for itm in lst:
        dct = itm.as_dict()
        try:            
            if dct['display_name'][0:5] == 'ARDI ':                
                if dct['status'] == 'running':
                    fnd = dct['display_name'].find('(')
                    driverno = dct['display_name'][fnd+1:]
                    driverno = driverno[0:len(driverno)-1]
                    print(str(driverno) + "\t" + dct['display_name'] + "\t" + str(dct['pid']) + "\r\n")
        except:
            pass
    
else:
    pidlist = psutil.pids()

    for pid in pidlist:
        p = psutil.Process(pid)
        try:
            driverno = int(p.name())
            print(p.name() + "\t" + p.name() + "\t" + str(p.pid()) + "\r\n")            
        except:
            pass            
        
        try:
            lead = p.name()[0:5]
            if lead == 'ardi-':
                print(p.name() + "\t" + p.name() + "\t" + str(p.pid()) + "\r\n")
        except:
            pass            
