Page MenuHomePhabricator
Paste P6507

naughty_detector.py
ActivePublic

Authored by zhuyifei1999 on Dec 31 2017, 5:19 AM.
Tags
None
Referenced Files
F12789581: naughty_detector.py
Jan 25 2018, 5:13 PM
F12181715: naughty_detector.py
Jan 1 2018, 5:58 AM
F12159876: naughty_detector.py
Dec 31 2017, 5:19 AM
Subscribers
#! /usr/bin/env python3
import datetime
import os
import time
os.chdir('/proc')
next_data = set()
while True:
last_data, next_data = next_data, set()
for proc in os.listdir():
try:
int(proc)
except ValueError:
continue
try:
with open(os.path.join(proc, 'stat'), 'rb') as f:
data = f.read().split(b' ')
except OSError:
continue
if data[2] == b'D':
try:
with open(os.path.join(proc, 'cmdline'), 'rb') as f:
cmdline = repr(f.read().rstrip(b'\x00').split(b'\x00'))
except OSError:
cmdline = '(Unknown)'
v = proc, cmdline
next_data.add(v)
if v in last_data:
print('[%s] PID %s: %s' % ((datetime.datetime.now().isoformat(),) + v))
time.sleep(10)