gpt4 book ai didi

java - 查找进程是否在 Windows 中处于 Activity 状态

转载 作者:可可西里 更新时间:2023-11-01 09:23:46 33 4
gpt4 key购买 nike

简短版:

  • 在带有 PID 的 Windows 中,我的程序需要查明我的进程是否仍在运行/Activity 。

在 linux 中,我只需使用“grep pid”就可以完成所有操作,就像在 windows 中那样吗?


更长的版本:

我正在 Windows 上制作一个 php(7) 系统,它运行一个蓝牙 Java 服务器。我的系统通过命令行运行服务器并保存 PID:

    $command = 'java -jar app\InterfaceBluetooth.jar /k > storage\logs\bluetoothServerToten.txt';
$descriptorspec = array (
0 => array("pipe", "r"),
1 => array("pipe", "w")
);

if(is_resource($prog = proc_open("start /b " . $command, $descriptorspec, $pipes))){
$ppid = proc_get_status($prog)['pid'];
}// IF
else{
// error stuff
exit();
}// ELSE

$output = array_filter(explode(" ", shell_exec("wmic process get parentprocessid,processid | find \"$ppid\"")));
array_pop($output);
$pid = end($output);

所以,此时进程已启动并正在运行,我有 PID。

现在,重要的是用户可以确定服务器正在运行。在某种程度上,我的系统需要检查这个,这可以追溯到短版本。

不管怎样,php 7 函数、命令行或其他方式,只要我的系统能够发现它是否正在运行。

最佳答案

如果你只需要等同于ps aux | grep PID,尝试 tasklist/nh/fi "pid eq PID"

关于java - 查找进程是否在 Windows 中处于 Activity 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37255816/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com