acá un primordio del random walk
This commit is contained in:
parent
58c6adfea6
commit
ecb70926a7
29
ps_random_walk.py
Normal file
29
ps_random_walk.py
Normal file
@ -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))
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user