blob: 210d831667a6e1c608b22b886b999994f1f586b7 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
ohair2283b9d2010-05-25 15:58:33 -07002 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
duke6e45e102007-12-01 00:00:00 +00003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
ohair2283b9d2010-05-25 15:58:33 -070019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
duke6e45e102007-12-01 00:00:00 +000022 */
23
24/*
25 * @test
26 * @bug 6474073
27 * @summary Make sure zombies don't get created on Unix
28 * @author Martin Buchholz
29 */
30
31import java.io.*;
32
33public class Zombies {
michaelm5ac8c152012-03-06 20:34:38 +000034
35 static final String os = System.getProperty("os.name");
36
37 static final String TrueCommand = os.startsWith("Mac OS")?
38 "/usr/bin/true" : "/bin/true";
39
duke6e45e102007-12-01 00:00:00 +000040 public static void main(String[] args) throws Throwable {
41 if (! new File("/usr/bin/perl").canExecute() ||
42 ! new File("/bin/ps").canExecute())
43 return;
44 System.out.println("Looks like a Unix system.");
45 final Runtime rt = Runtime.getRuntime();
46
47 try {
48 rt.exec("no-such-file");
49 throw new Error("expected IOException not thrown");
50 } catch (IOException _) {/* OK */}
51
52 try {
53 rt.exec(".");
54 throw new Error("expected IOException not thrown");
55 } catch (IOException _) {/* OK */}
56
57 try {
michaelm5ac8c152012-03-06 20:34:38 +000058 rt.exec(TrueCommand, null, new File("no-such-dir"));
duke6e45e102007-12-01 00:00:00 +000059 throw new Error("expected IOException not thrown");
60 } catch (IOException _) {/* OK */}
61
michaelm5ac8c152012-03-06 20:34:38 +000062 rt.exec(TrueCommand).waitFor();
duke6e45e102007-12-01 00:00:00 +000063
64 // Count all the zombies that are children of this Java process
65 final String[] zombieCounter = {
66 "/usr/bin/perl", "-e",
67 "exit @{[`/bin/ps -eo ppid,s` =~ /^ *@{[getppid]} +Z$/mog]}"
68 };
69
70 int zombies = rt.exec(zombieCounter).waitFor();
71 if (zombies != 0) throw new Error(zombies + " zombies!");
72 }
73}