import os,time,threading

class Message(threading.Thread):
    def __init__(self,name):
        threading.Thread.__init__(self)
        self.name = name
    
    def printIt(self):
        # print 'checking process is : ' + self.num
        cmd = 'ps -C ' + self.name + ' -o pid,cmd'
        ret=os.popen(cmd).readlines()
        if len(ret) < 2:
            print '[' + self.name + '] process ' + ' process  not found'
                    # os.system('top')
        elif len(ret) >= 2:
            print '[' + self.name + '] process ' + ret[0].strip()[0:3] + ' is ' + ret[-1].strip()[:-3]
        else:
            print "other error"

def run(type):
    thread1 = Message(type[0])
    thread2 = Message(type[1])
    thread1.printIt()
    thread2.printIt()
if __name__ == '__main__':
    type=["top","aa"]
    run(type)

 

相关文章:

  • 2022-01-21
  • 2021-12-28
  • 2021-11-07
  • 2021-11-23
  • 2021-12-29
  • 2021-10-19
  • 2022-12-23
  • 2021-08-17
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2021-09-05
  • 2021-05-27
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案