As the topic, I attempt to use ProcessBuilder to handle a subprocess, finally it works.
But I do wanna more feature of the subprocess, for instance, the time of subprocess running, the memory a subprocess consumed. If the running time or consumed memory of this subprocess exceeds the range that one customized, then destroy it immediately.
Is that possible, or else only jni can do it? thanks in advance.
One option is to use another process (started in another thread). This other process, either vmstat or tasklist, depending on the OS, can be called constantly to get a read on the first process. If the resource limits are violated, it can inform the first thread, which can kill the process.
Before you even think of going near Process or ProcessBuilder you need to find the classic article by Michael Daconta: here. RpocessBuilder makes it a bit easier, but the principals in Daconta are unchanged.
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad: