File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\util\ProcessTreeKiller.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.util;
25
26 import hudson.EnvVars;
27 import hudson.util.ProcessTree.OSProcess;
28
29 import java.util.Map;
30
31 /**
32 * Kills a process tree to clean up the mess left by a build.
33 *
34 * @author Kohsuke Kawaguchi
35 * @since 1.201
36 * @deprecated as of 1.315. Use {@link ProcessTree}.
37 */
38 public final class ProcessTreeKiller {
39 /**
40 * Short for {@code kill(proc,null)}
41 *
42 * @deprecated Use {@link OSProcess#killRecursively()}
43 */
44 public void kill(Process proc) throws InterruptedException {
45 kill(proc,null);
46 }
47
48 /**
49 * In addition to what {@link #kill(Process)} does, also tries to
50 * kill all the daemon processes launched.
51 *
52 * <p>
53 * Kills the given process (like {@link Process#destroy()}
54 * but also attempts to kill descendant processes created from the given
55 * process.
56 *
57 * <p>
58 * In addition, optionally perform "search and destroy" based on environment
59 * variables. In this method, the method is given a
60 * "model environment variables", which is a list of environment variables
61 * and their values that are characteristic to the launched process.
62 * The implementation is expected to find processes
63 * in the system that inherit these environment variables, and kill
64 * them all. This is suitable for locating daemon processes
65 * that cannot be tracked by the regular ancestor/descendant relationship.
66 *
67 * <p>
68 * The implementation is obviously OS-dependent.
69 *
70 * @param proc
71 * Process to be killed recursively. Can be null.
72 * @param modelEnvVars
73 * If non-null, search-and-destroy will be performed.
74 * @deprecated Use {@link ProcessTree#killAll(Map)} and {@link OSProcess#killRecursively()}
75 */
76 public void kill(Process proc, Map<String, String> modelEnvVars) throws InterruptedException {
77 ProcessTree pt = ProcessTree.get();
78 if(proc!=null)
79 pt.get(proc).killRecursively();
80 if(modelEnvVars!=null)
81 pt.killAll(modelEnvVars);
82 }
83
84 /**
85 * Short for {@code kill(null,modelEnvVars)}
86 * @deprecated Use {@link ProcessTree#killAll(Map)}
87 */
88 public void kill(Map<String, String> modelEnvVars) throws InterruptedException {
89 kill(null,modelEnvVars);
90 }
91
92 /**
93 * Creates a magic cookie that can be used as the model environment variable
94 * when we later kill the processes.
95 *
96 * @deprecated Use {@link EnvVars#createCookie()}
97 */
98 public static EnvVars createCookie() {
99 return EnvVars.createCookie();
100 }
101
102 /**
103 * Gets the {@link ProcessTreeKiller} suitable for the current system
104 * that JVM runs in, or in the worst case return the default one
105 * that's not capable of killing descendants at all.
106 */
107 public static ProcessTreeKiller get() {
108 return new ProcessTreeKiller();
109 }
110 }
111