avatar
How to timeout a process# Java - 爪哇娇娃
t*i
1
I have a process p = Runtime.getRuntime().exec("some programe). After a
timeout(say t), I need to stop this process if it haven't finish running.
What's the nice way to do that?
Thanks!
avatar
g*e
2
check javadoc. I believe it must be there.

【在 t**i 的大作中提到】
: I have a process p = Runtime.getRuntime().exec("some programe). After a
: timeout(say t), I need to stop this process if it haven't finish running.
: What's the nice way to do that?
: Thanks!

avatar
f*g
3

No way from Java. But you can call native function/command to halt
your process.

【在 t**i 的大作中提到】
: I have a process p = Runtime.getRuntime().exec("some programe). After a
: timeout(say t), I need to stop this process if it haven't finish running.
: What's the nice way to do that?
: Thanks!

avatar
t*i
4
Thanks!
Now I found out I can't tell if the process's status after t. If I do
p.exitValue(), it throws IllegalThreadException. If I do p.waitFor(), it
ignores my timing while loop. What I did in my code is:
while (System.currentTimeMillis() - startTime < t)
{
if (p.waitFor() == 0)
break;
}
Could you advise?
Thanks!

【在 f*****g 的大作中提到】
:
: No way from Java. But you can call native function/command to halt
: your process.

avatar
g*e
5
p.destroy()

【在 t**i 的大作中提到】
: Thanks!
: Now I found out I can't tell if the process's status after t. If I do
: p.exitValue(), it throws IllegalThreadException. If I do p.waitFor(), it
: ignores my timing while loop. What I did in my code is:
: while (System.currentTimeMillis() - startTime < t)
: {
: if (p.waitFor() == 0)
: break;
: }
: Could you advise?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。