Page MenuHomePhabricator

naughty_detector.py

Authored By
zhuyifei1999
Jan 25 2018, 5:13 PM
Size
893 B
Referenced Files
None
Subscribers
None

naughty_detector.py

#! /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)

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5436680
Default Alt Text
naughty_detector.py (893 B)

Event Timeline