I am using the following Java code to execute a MySQL command that imports data from a source file:
String command = String.format("%s -h %s -P%s -u%s -p%s -D %s < %s", mysqlCommand, ip, port, username, password, dbName, sourceFile);
logger.info("[ProcessCommandUtil] run, command:{}", command);
ProcessBuilder processBuilder = new ProcessBuilder("bash", "-c", command);
After starting the process, I attempt to forcefully stop it using process.destroyForcibly();. However, when I log into the machine and use the top command to inspect running processes, I notice that the mysql process is still running. It takes approximately 5 to 6 minutes for the process to actually end.
I would like to ask the StackOverflow community why process.destroyForcibly(); does not immediately terminate the mysql command and how I can ensure that the mysql process is terminated as soon as I call process.destroyForcibly();.