1

Is it possible to have an application containerized in a Docker container and then to create a new process at runtime? I have something like this:

launchProcess() {
  Runtime runtime = Runtime.getRuntime();
  String launchProgramCommand = "some command that launches a program";
  Process process = runtime.exec(launchProgramCommand);
}
Cosmin
  • 68
  • 2
  • 5

1 Answers1

1

It is technically possible but you will have some issues.

When the docker container is stopped your main application exits but the external processes will not necessarily exit gracefully. If you want them to exit gracefully you will have to implement a shutdown hook and use the Process.waitFor to wait until the external process has terminated. In alternative you could destroy the external processes with Process.destroy which is Java implementation dependent.

You could also obtain the pid of the process (How to get a process id of exe running through java program) and send the apropiate signal to terminate it with the kill command.

b0gusb
  • 4,283
  • 2
  • 14
  • 33