All pastes #349070 Raw Edit

Stuff

public text v1 · immutable
·published 2007-02-10 15:14 UTC
rendered paste body
#!/usr/bin/env python
import os,sys,time
from pylib import openPipe

if len(sys.argv) < 2:
  sys.exit("At least one argument is needed")

processes = openPipe(["ps", "-A"])

found = []
for arg in sys.argv[1:]:
  match = False
  for line in processes:
    if arg in line:
      found.append(line)
      match = True
  if not match:
    print "%s was not found!" % arg
    time.sleep(2)

if not found:
  sys.exit("No matches found")

pids = []
for line in found:
  pid = line.strip().split(" ")[0]
  pids.append(pid)

param = ""
for pid in pids:
  param += "-p%s " % pid

os.system("top %s" % param)