Created a sample.jsh
file with below code
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.
How to kill java process after some timeout?
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.
While you don't mention your OS, at least on Linux and probably other *nix you can use:
https://github.com/opsengine/cpulimit
if you're concerned about cpu limits.
Else, I think you're looking at a cron
job to periodically kill processes...
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) {}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.