code: public static Channel forProcess(String name, ExecutorService execService, InputStream in, OutputStream out, OutputStream header, final Proc proc) throws IOException {
          ChannelBuilder cb = new ChannelBuilder(name,execService) {
              @Override
              public Channel build(CommandTransport transport) throws IOException {
                  return new Channel(this,transport) {
                      /**
                       * Kill the process when the channel is severed.
                       */
                      @Override
                      public synchronized void terminate(IOException e) {
                          super.terminate(e);
                          try {
                              proc.kill();
                          } catch (IOException x) {
                              // we are already in the error recovery mode, so just record it and move on
                              LOGGER.log(Level.INFO, "Failed to terminate the severed connection",x);
                          } catch (InterruptedException x) {
                              // process the interrupt later
                              Thread.currentThread().interrupt();
                          }
                      }
  
                      @Override
                      public synchronized void join() throws InterruptedException {
                          super.join();
                          // wait for the child process to complete, too
                          try {
                              proc.join();
                          } catch (IOException e) {
                              throw new IOError(e);
                          }
                      }
                  };
              }
          };
          cb.withHeaderStream(header);
  
          for (ChannelConfigurator cc : ChannelConfigurator.all()) {
              cc.onChannelBuilding(cb,null);  // TODO: what to pass as a context?
          }
  
          return cb.build(in,out);
      }
docs: Creates a channel that wraps a remote process, so that when we shut down the connection
  we kill the process.