get process id of program

def get_pid(pname):
    process = psutil.process_iter()
    for pro in process:
        str_pro = str(pro)
        pat = re.compile(pname)
        if pat.search(str_pro):
            pid = str_pro.split('pid=')[1].split(',')[0]
            return pid
posted @ 2017-03-28 15:30  idlewith  阅读(154)  评论(0编辑  收藏  举报