Browse Source

Adding pypspy

master
sp0re 1 year ago
parent
commit
7c4f15a5ea
1 changed files with 47 additions and 0 deletions
  1. +47
    -0
      pspy.py

+ 47
- 0
pspy.py View File

@@ -0,0 +1,47 @@
#!/usr/bin/env python3
import os
from time import sleep
from threading import Thread

known_cmds = []


def cleanPids():
global known_cmds
known_cmds = []
sleep(0.2)


def getpids():
return [p for p in os.listdir("/proc") if p.isdigit()]


def main():
global known_cmds
print("Python version of pspy.")
print("Now we waiting for cron stuff...")
Thread(target=cleanPids).start()

p1 = getpids()
while True:
p2 = getpids()
if p1!=p2:
diff = list(set(p2).difference(p1))
if not len(diff):
p1=p2
continue
for d in diff:
try:
out=open(os.path.join("/proc", d, "cmdline"), "r").read().replace("\0", " ")
if out not in known_cmds:
print("{}: {}".format(d, out))
if not len(out):
print("{}:".format(d))
known_cmds += [out]
except IOError:
pass


if __name__=='__main__':
main()


Loading…
Cancel
Save