|
|
@@ -0,0 +1,19 @@
|
|
|
+/**
|
|
|
+ * 子进程程序:ProcessHandle 示例使用的固定程序。
|
|
|
+ * 启动后打印自身 pid 和 args,然后睡眠 30 秒,等待父进程完成 ProcessHandle 检查与销毁。
|
|
|
+ * 被 destroy() 后线程被中断退出,向标准错误打印提示。
|
|
|
+ */
|
|
|
+public class Main {
|
|
|
+ public static void main(String[] args) {
|
|
|
+ long pid = ProcessHandle.current().pid();
|
|
|
+ System.out.println("child: pid=" + pid);
|
|
|
+ System.out.println("child: args=" + java.util.Arrays.toString(args));
|
|
|
+ System.out.println("child: sleeping 30s, waiting for parent to inspect");
|
|
|
+ System.err.println("child: ready for ProcessHandle inspection");
|
|
|
+ try {
|
|
|
+ Thread.sleep(30_000L);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ System.err.println("child: interrupted, exiting");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|