I'm using Java exec to run bash script, but when I enter CTRL+C, the Java process will exit and also the sub processes, how can I keep child processes running after JVM is shut down?
String command = "ffmpeg -re -strict -2 -i video.mp4 -c:v copy -an -f rtp rtp://127.0.0.1:1234";
Utils.writeToFile("sub.sh", command);
new ProcessBuilder("parent.sh", "sub.sh").inheritIO()
.start().waitFor();
parent.sh:
#!/bin/bash
trap '' SIGINT SIGTERM SIGQUIT SIGHUP SIGTSTP
nohup "$@" &
I have read answers to similar questions here and here, e.g, start a parent bash script in that script run command using nohup, or using trap command to prevent signals, on my research, it works for example "tail -f somefile", but not for my use case "ffmpeg -params", please help, thank you.