+ ########################
+ #Collect all process (must change for a more intelligent way)
+ ppid = []
+ pids = []
+ avoid_pids = "ps axjf | awk '{print $1,$2}'"
+ (out, err), proc = self.execute(avoid_pids)
+ if len(out) != 0:
+ for line in out.strip().split("\n"):
+ parts = line.strip().split(" ")
+ ppid.append(parts[0])
+ pids.append(parts[1])
+
+ #Collect all process below ssh -D
+ tree_owner = 0
+ ssh_pids = []
+ sshs = "ps aux | grep 'sshd' | awk '{print $2,$12}'"
+ (out, err), proc = self.execute(sshs)
+ if len(out) != 0:
+ for line in out.strip().split("\n"):
+ parts = line.strip().split(" ")
+ if parts[1].startswith('root@pts'):
+ ssh_pids.append(parts[0])
+ elif parts[1] == "-D":
+ tree_owner = parts[0]
+
+ avoid_kill = []
+ temp = []
+ #Search for the child process of the pid's collected at the first block.
+ for process in ssh_pids:
+ temp = self.search_for_child(process, pids, ppid)
+ avoid_kill = list(set(temp))
+
+ if len(avoid_kill) > 0:
+ avoid_kill.append(tree_owner)
+ ########################
+