根据process进程id判断进程是否存在,Java
List<Long> pids = new ArrayList<>();
ProcessHandle.allProcesses()
.limit(1000)
.forEach(new Consumer<ProcessHandle>() {
@Override
public void accept(ProcessHandle processHandle) {
pids.add(processHandle.pid());
}
});
boolean alive = false;
for (long l : pids) {
if (l == pid) {
alive = true;
break;
}
}