I am trying to solve the problem given in pause youtube-dl when network is disconnected and resume when it is connected again
To stop and resume process, I have taken guideline from How to suspend and resume processes
The problem is, the following works:
processid=$(pgrep youtube-dl) kill -TSTP $processid When I run the above script, The terminal running youtube-dl shows:
zsh: suspended youtube-dl % jobs [1] + suspended youtube-dl I have to go to the terminal and type the following command to continue the process:
% fg %1 [1] + continued youtube-dl How to resume processes from a script instead of going to the terminal and typing a command?
Just for the sake of being thorough, If I run tail -f ~/.xsession-errors, I can pause it from the script using kill -TSTP $processid and resume it using kill -CONT $processid. It does not invoke the job control.
pgrep youtube-dl+kill -TSTP. This would be much better written aspkill -TSTP youtube-dl.kill -CONTshould work (and, of course,pkill -CONT youtube-dlas well).top, or any other command. SendingCONTto it will not put it back into the foreground of the interactive shell where it was started.topand confirmed what you said. However, I then tried it with this snippet:( while :; do echo $i; sleep 2; i=$((i+1)); done )also running in the foreground, and that could be stopped and continued with SIGTSTP and SIGCONT, respectively, although it was continued in the background.topreads from the terminal, which causes problems when running in the background. Sinceyoutube-dlis unlikely to require terminal input or running in the foreground, SIGCONT should work in this particular case.setsidit will run in a new terminal session so you can kill it with-stopand-contwithout the change in state being seen by the shell.