[英]java JShell kill java process
Created a sample.jsh
file with below code使用以下代码创建了一个
sample.jsh
文件
while(true){}
Now i ran below command现在我在命令下运行
jshell sample.jsh
It internally creates 2 process one is jshell process and another one is java process and java process is taking 100% cpu utilization.它在内部创建 2 个进程,一个是 jshell 进程,另一个是 java 进程和 java 进程占用 100% 的 CPU 利用率。
How to kill java process after some timeout?超时后如何杀死 java 进程?
Note: All above steps will done by programatically not manually, so i can kill jshell process after certain time because jshell command ran by my code, but java process created by jshell so i unable to kill by programatically.注意:以上所有步骤都将通过编程而不是手动完成,所以我可以在一段时间后杀死 jshell 进程,因为 jshell 命令由我的代码运行,但是 java 进程由 jshell 创建,所以我无法以编程方式杀死。
While you don't mention your OS, at least on Linux and probably other *nix you can use:虽然您没有提及您的操作系统,但至少在 Linux 和其他您可以使用的 *nix 上:
https://github.com/opsengine/cpulimit https://github.com/opsengine/cpulimit
if you're concerned about cpu limits.如果您担心 CPU 限制。
Else, I think you're looking at a cron
job to periodically kill processes...否则,我认为您正在寻找一项定期终止进程的
cron
作业...
Thread selfdestruct = new Thread() {
private long startTime = System.currentTimeMillis();
public void run() {
while(true) {
// Set time here
if(System.currentTimeMillis() - startTime > 1000) {
System.exit(0);
}
yield();
}
}
};
selfdestruct.start();
// your actual payload goes here
while(true) {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.