#!/usr/bin/env python3 import os from subprocess import call from sys import argv, stderr, stdin, stdout, version_info def parpid(pid): pid=str(pid) if not int(pid): return None fn='/proc/'+pid+'/status' with open(fn) as s: for line in s: a,b = line.split()[:2] if a=='PPid:': return b def dopids(pid): pid=str(pid) pids=[pid] while pid: pid=int(pid) pid=parpid(pid) if not int(pid): return pids pids.append(str(pid)) def main(args): s=None this=os.getpid() if len(args)>1: for arg in argv[1:]: s=dopids(arg) else: s=dopids(os.getpid()) # print(' '.join(s)) cmd=['ps'] for p in s: call(cmd+[p]) cmd[1:2]=['h'] return 0 if __name__ == '__main__': if version_info.major < 3: BrokenPipeError = IOError try: result=main(argv) stdout.flush() except BrokenPipeError: result = 99 except KeyboardInterrupt: print('') result = 98 if result is 0 or result is None or result is True: exit(0) if result is 1 or result is False: exit(1) if isinstance(result,str): print(result,file=stderr) exit(2) try: exit(int(result)) except ValueError: print(str(result),file=stderr) exit(3) except TypeError: exit(4) # EOF