OK, turing.

<- leave blank

Wed May 16 09:37:27 EDT 2018

#!/usr/bin/env python3

# proctolog: new processes monitor

import os
from time import sleep

def print_pid(pid):
    try:
	with open('/proc/' + pid + '/status') as f:
	    for lineno, line in enumerate(f):
		print('+ Pid: {}, {}'.format(pid, line[:-1]))
		if lineno >= 0:
		    break
    except FileNotFoundError:
	print('- Pid: ' + pid)

def foo():
    proc_list = os.listdir('/proc')
    proc_set = set()
    for i in proc_list:
	if i.isdigit() != True:
	    continue
	proc_set.add(i)
    return proc_set

def bar(old_set):
    new_set = foo()
    plus = new_set - old_set
    minus = old_set - new_set
    if len(plus) > 0:
	for pid in plus:
	    print_pid(pid)
    if len(minus) > 0:
	for pid in minus:
	    print_pid(pid)
    return new_set

pid_set = foo()

while True:
    pid_set = bar(pid_set)
    sleep(0.1)