Print process chains and command lines:

#!/usr/bin/env python3

import sys,os,os.path

pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]

class Pid:
    def __init__(self,pid,cmdline,status,**kw): = pid
        self.cmdline = cmdline
        self.status = status
    def __getattr__(self,a):
        if a in self.status:
            return self.status[a]
            raise AttributeError(a)

def pdetails(x):
    # take a pid, get cmdline and status
    d = {}
        c = open("/proc/{}/cmdline".format(x)).read()
        s = open("/proc/{}/status".format(x)).read()
        cc = c.split("\000")
        a = s.strip().split("\n")
        for y in a:
            i,j = y.split(":")
            j = j.strip()
            d[i] = j
        return Pid(x,cc,d)
        return None

pidds = list(map(pdetails,pids))
pidds = list(filter(lambda t: t is not None, pidds))
pidd = { t for t in pidds}

import re
for x in sys.argv[1:]:
    print("Finding {}".format(x))
    r = re.compile(x)
    for y in pidds:
        n = y.Name
            print("Found pid: {}, name: {} for: {}".format(,n,x))
            t =
            while t in pidd:
                z = pidd[t]
                print("{:>6d}: {}".format(int(," ".join(z.cmdline)))
                t = z.PPid
            print("Done chain for pid: {}\n".format(
    print("Done finding {}\n".format(x))