package controller;
/*
*  Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;
import jvmmonitor.exceptions.MonitoringNotStartedException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointAuthenticationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException;
import org.wso2.carbon.databridge.agent.exception.DataEndpointException;
import org.wso2.carbon.databridge.commons.exception.TransportException;

import javax.management.MalformedObjectNameException;
import java.io.IOException;

public class Test {

    public static void main(String[] args) throws IOException,
            AttachNotSupportedException,
            MalformedObjectNameException,
            InterruptedException,
            MonitoringNotStartedException,
            DataEndpointAuthenticationException,
            DataEndpointAgentConfigurationException,
            TransportException,
            DataEndpointException,
            DataEndpointConfigurationException {

        Runtime.getRuntime().exec("java -jar /home/buddhi/work/wso2/automatic-anomaly-detection/Test/BadCode.jar");
        String pid = null;

        for (VirtualMachineDescriptor vmd : VirtualMachine.list()) {
            if (vmd.displayName().indexOf("BadCode.jar") != -1) {
                pid = vmd.id();
                System.out.println(vmd.id() + "\t" + vmd.displayName());
            }
        }

        new Controller().sendUsageData(pid);

        Runtime.getRuntime().exec("kill -9 " + pid);

    }
}

@@ -1944,17 +1944,17 @@
 tection/
-T
+t
 est/BadC
@@ -1982,19 +1982,17 @@
 ring pid
- = 
+=
 null;%0A%0A 
@@ -2073,17 +2073,16 @@
       if
- 
 (vmd.dis
@@ -2118,16 +2118,13 @@
 ar%22)
- 
 !=
- 
 -1)
- 
 %7B%0A  
@@ -2341,19 +2341,17 @@
 ill -9 %22
- + 
++
 pid);%0A%0A 

Add process killer