@@ -0,0 +1,2866 @@
+package com.cisco.oss.tools;%0A%0Aimport lombok.extern.slf4j.Slf4j;%0Aimport org.springframework.beans.factory.annotation.Value;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport javax.annotation.PostConstruct;%0Aimport java.io.BufferedReader;%0Aimport java.io.InputStreamReader;%0Aimport java.util.concurrent.TimeUnit;%0A%0A/**%0A * Created by Yair Ogen (yaogen) on 10/07/2017.%0A */%0A@Component%0A@Slf4j%0Apublic class PacketDumperSelfDestruct %7B%0A%0A    @Value(%22$%7BLISTEN_PID%7D%22)%0A    private String listenPid;%0A%0A    private int SLEEP = 30;%0A%0A    @PostConstruct%0A    public void init()%7B%0A        Thread packetDumperSelfDestruct  = new Thread(()-%3E%7B%0A%0A            while (true)%7B%0A%0A                try %7B%0A                    if(!isStillAllive())%7B%0A                        System.exit(0);%0A                    %7D%0A                %7D catch (Exception e) %7B%0A                    log.warn(%22problem checking if listen pid: %7B%7D is still running. error: %7B%7D%22, listenPid, e.toString());%0A                %7D finally %7B%0A                    try %7B%0A                        TimeUnit.SECONDS.sleep(SLEEP);%0A                    %7D catch (InterruptedException e) %7B%0A                        log.trace(e.toString());%0A                    %7D%0A                %7D%0A%0A            %7D%0A%0A        %7D,%22PacketDumperSelfDestruct%22);%0A%0A        packetDumperSelfDestruct.setDaemon(false);%0A        packetDumperSelfDestruct.start();%0A%0A%0A    %7D%0A%0A    public boolean isStillAllive() %7B%0A        String OS = System.getProperty(%22os.name%22).toLowerCase();%0A        String command = null;%0A        if (OS.indexOf(%22win%22) %3E= 0) %7B%0A            log.debug(%22Check alive Windows mode. Pid: %5B%7B%7D%5D%22, listenPid);%0A            command = %22cmd /c tasklist /FI %5C%22PID eq %22 + listenPid + %22%5C%22%22;%0A        %7D else if (OS.indexOf(%22nix%22) %3E= 0 %7C%7C OS.indexOf(%22nux%22) %3E= 0) %7B%0A            log.debug(%22Check alive Linux/Unix mode. Pid: %5B%7B%7D%5D%22, listenPid);%0A            command = %22ps -p %22 + listenPid;%0A        %7D else %7B%0A            log.warn(%22Unsuported OS: Check alive for Pid: %5B%7B%7D%5D return false%22, listenPid);%0A            return false;%0A        %7D%0A        return isProcessIdRunning(listenPid, command); // call generic implementation%0A    %7D%0A%0A    private boolean isProcessIdRunning(String pid, String command) %7B%0A        log.debug(%22Command %5B%7B%7D%5D%22,command );%0A        try %7B%0A            Runtime rt = Runtime.getRuntime();%0A            Process pr = rt.exec(command);%0A%0A            InputStreamReader isReader = new InputStreamReader(pr.getInputStream());%0A            BufferedReader bReader = new BufferedReader(isReader);%0A            String strLine = null;%0A            while ((strLine= bReader.readLine()) != null) %7B%0A                if (strLine.contains(%22 %22 + pid + %22 %22)) %7B%0A                    return true;%0A                %7D%0A            %7D%0A%0A            return false;%0A        %7D catch (Exception ex) %7B%0A            log.warn(%22Got exception using system command %5B%7B%7D%5D.%22, command, ex);%0A            return true;%0A        %7D%0A    %7D%0A%0A%0A%0A%0A%7D%0A

add support to kill dumper if listen pid is dead