JDK9新特性-改进进程管理 API
2021-01-14 11:10
标签:zone 本机 null pareto 快照 退出 source onexit 进程终止 ProcessHandle 类 范例 JDK9新特性-改进进程管理 API 标签:zone 本机 null pareto 快照 退出 source onexit 进程终止 原文地址:https://www.cnblogs.com/zhuxiaopijingjing/p/12268097.html
import
java.time.ZoneId;
import
java.util.stream.Stream;
import
java.util.stream.Collectors;
import
java.io.IOException;
public
class
ProcessHandleTester {
public
static
void
main(String[] args)
throws
IOException {
// Windows 有效
ProcessBuilder pb =
new
ProcessBuilder(
"notepad.exe"
);
String np =
"Not Present"
;
Process p = pb.start();
ProcessHandle.Info info = p.info();
System.out.printf(
"Process ID : %s%n"
, p.pid());
System.out.printf(
"Command name : %s%n"
, info.command().orElse(np));
System.out.printf(
"Command line : %s%n"
, info.commandLine().orElse(np));
System.out.printf(
"Start time: %s%n"
,
info.startInstant().map(i -> i.atZone(ZoneId.systemDefault())
.toLocalDateTime().toString()).orElse(np));
System.out.printf(
"Arguments : %s%n"
,
info.arguments().map(a -> Stream.of(a).collect(
Collectors.joining(
" "
))).orElse(np));
System.out.printf(
"User : %s%n"
, info.user().orElse(np));
}
}
[[url=mailto:yufei
@www
.twle.cn]yufei
@www
.twle.cn[/url] java9]$ javac ProcessHandleTester.java && java ProcessHandleTester
Process ID :
5800
Command name : C:\Windows\System32\notepad.exe
Command line : Not Present
Start time:
2017
-
11
-04T21:
35
:
03.626
Arguments : Not Present
User: administrator
文章标题:JDK9新特性-改进进程管理 API
文章链接:http://soscw.com/index.php/essay/41743.html