-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba20926
commit 28cf672
Showing
3 changed files
with
48 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
java-api/src/java9/java/xyz/wagyourtail/jvmdg/j9/stub/java_base/J_L_Process.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package xyz.wagyourtail.jvmdg.j9.stub.java_base; | ||
|
||
import xyz.wagyourtail.jvmdg.util.Utils; | ||
import xyz.wagyourtail.jvmdg.version.Stub; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.stream.Stream; | ||
|
||
public class J_L_Process { | ||
private static final MethodHandles.Lookup IMPL_LOOKUP = Utils.getImplLookup(); | ||
|
||
@Stub | ||
public static J_L_ProcessHandle toHandle(Process process) throws Throwable { | ||
long pid = (long) IMPL_LOOKUP.findGetter(process.getClass(), "pid", int.class).invoke(process); | ||
return J_L_ProcessHandle.of(pid).get(); | ||
} | ||
|
||
@Stub | ||
public static J_L_ProcessHandle.Info info(Process process) throws Throwable { | ||
return toHandle(process).info(); | ||
} | ||
|
||
@Stub | ||
public static Stream<J_L_ProcessHandle> children(Process process) throws Throwable { | ||
return toHandle(process).children(); | ||
} | ||
|
||
@Stub | ||
public static Stream<J_L_ProcessHandle> descendants(Process process) throws Throwable { | ||
return toHandle(process).descendants(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
testing/downgrade/src/main/java/xyz/wagyourtail/downgradetest/TestProcessHandle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
package xyz.wagyourtail.downgradetest; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class TestProcessHandle { | ||
|
||
public static void main(String[] args) { | ||
public static void main(String[] args) throws IOException { | ||
ProcessHandle currentProcessHandle = ProcessHandle.current(); | ||
System.out.println(currentProcessHandle.pid() == ManagementFactory.getRuntimeMXBean().getPid()); | ||
List<String> lst = Arrays.asList(currentProcessHandle.info().arguments().get()); | ||
System.out.println(lst.subList(lst.size() - 3, lst.size())); | ||
|
||
ProcessBuilder pb; | ||
// check if windows | ||
if (System.getProperty("os.name").toLowerCase().contains("windows")) { | ||
pb = new ProcessBuilder("timeout", "1"); | ||
} else { | ||
pb = new ProcessBuilder("sleep", "1"); | ||
} | ||
Process p = pb.start(); | ||
currentProcessHandle.children().map(e -> String.join(" ", e.info().arguments().get())).forEach(System.out::println); | ||
p.toHandle().onExit().thenAccept(e -> System.out.println(e.info().commandLine())); | ||
// Thread.sleep(1); | ||
} | ||
} |