You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.1KB

  1. #!/usr/bin/env python3
  2. import os
  3. from time import sleep
  4. from threading import Thread
  5. known_cmds = []
  6. def cleanPids():
  7. global known_cmds
  8. known_cmds = []
  9. sleep(0.2)
  10. def getpids():
  11. return [p for p in os.listdir("/proc") if p.isdigit()]
  12. def main():
  13. global known_cmds
  14. print("Python version of pspy.")
  15. print("Now we waiting for cron stuff...")
  16. Thread(target=cleanPids).start()
  17. p1 = getpids()
  18. while True:
  19. p2 = getpids()
  20. if p1!=p2:
  21. diff = list(set(p2).difference(p1))
  22. if not len(diff):
  23. p1=p2
  24. continue
  25. for d in diff:
  26. try:
  27. out=open(os.path.join("/proc", d, "cmdline"), "r").read().replace("\0", " ")
  28. if out not in known_cmds:
  29. print("{}: {}".format(d, out))
  30. if not len(out):
  31. print("{}:".format(d))
  32. known_cmds += [out]
  33. except IOError:
  34. pass
  35. if __name__=='__main__':
  36. main()