Created
January 11, 2020 07:50
-
-
Save tthtlc/c21dc0fde2d59b5dfa4feddd88e97aaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
def get_children(pid): | |
if (len(pid)==0) or pid is None: | |
return | |
child_pid_procfs="/proc/" + pid + "/task/" + pid + "/children" | |
out = subprocess.Popen(['cat', child_pid_procfs], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
childstr,err=out.communicate() | |
childlist=childstr.rstrip().split(" ") | |
if len(childlist[0])==0: | |
return None | |
return childlist | |
def enum_proc(pidlist): | |
if pidlist is None or (len(pidlist))==0: | |
return | |
for pid in pidlist: | |
childlist=get_children(pid) | |
if childlist is None: | |
continue | |
print(childlist) | |
enum_proc(childlist) | |
pid=sys.argv[1] | |
childlist=get_children(pid) | |
print(childlist) | |
enum_proc(childlist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment