diff --git a/ps_random_walk.py b/ps_random_walk.py new file mode 100644 index 0000000..b4775d9 --- /dev/null +++ b/ps_random_walk.py @@ -0,0 +1,29 @@ +import psutil +import random +from time import sleep + + +def reporta(p): + binario = bin(p.pid).replace('0b', '') + return p.pid, binario, binario[0:7], len(str(p.pid)), len(p.name()) + + +p = psutil.Process(pid=random.choice(psutil.pids())) +print('random chose', reporta(p)) + + +while True: + sleep(1) + children = p.children() + + if children: + p = psutil.Process(pid=random.choice([subp.pid + for subp in + children])) + print("\t↳", reporta(p)) + + else: + p = psutil.Process(pid=random.choice(psutil.pids())) + print('→', reporta(p)) + +