Skip to content
Process Watch Dog Java Library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Process Watch Dog

Java library for watching (and killing) processes.

Watch Dog thread runs only when there are same active processes to watch.

       .-------------.       .    .   *       *   
      /_/_/_/_/_/_/_/ \         *       .   )    .
     //_/_/_/_/_/_// _ \ __          .        .   
    /_/_/_/_/_/_/_/|/ \.' .`-o                    
     |             ||-'(/ ,--'                    
     |             ||  _ |                        
     |             ||'' ||                        
     |_____________|| |_|L                     hjm


  • Java 6


Copy the Maven dependency into your Maven project:


Watch a Process

Create a Watch Dog object:

ProcessWatchDog watchDog = new ProcessWatchDog();

Create a process and watch it by the Watch Dog:

ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Process p = pb.start();, 1000); // kill the process after 1 sec

Watch another process by the same Watch Dog:

pb = new ProcessBuilder("otherCommand");
Process p2 = pb.start();, 2000); // kill the second process after 2 secs

Unwatch a Process

Unwatch a process if you don't care any longer:


Keep a Process Alive

Normally, a process should be killed only after a timeout of inactivity. To tell the Watch Dog that the process is still active a heartbeat must be sent.

Send a heartbeat explicitly to reset the timeout:


Send a heartbeat automatically with every read byte:

p =, 1000);    // reassign the `WatchedProcess` object to the process reference

InputStream is = p.getInputStream();
int b;
while ((b = != -1) {
    // heartbeat is sent implicitly with every successful call of `read()` 

Alternatively, send a heartbeat explicitly via WatchedProcess object:

WatchedProcess wp =, 1000);    // use the returned watched process object

Release Changes


Watched process with a heartbeat.

  • WatchedProcess class added.
  • heartBeat(Process) method added to the ProcessWatchDog class.


Initial version.


Apache License, Version 2.0

You can’t perform that action at this time.