1

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.

6
  • 2
    Just a comment about pgrep youtube-dl + kill -TSTP. This would be much better written as pkill -TSTP youtube-dl. Commented Jan 27, 2021 at 9:43
  • kill -CONT should work (and, of course, pkill -CONT youtube-dl as well). Commented Jan 27, 2021 at 9:50
  • 1
    @berndbausch Try it with e.g. top, or any other command. Sending CONT to it will not put it back into the foreground of the interactive shell where it was started. Commented Jan 27, 2021 at 10:16
  • @Kusalananda I tried it with top and 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. top reads from the terminal, which causes problems when running in the background. Since youtube-dl is unlikely to require terminal input or running in the foreground, SIGCONT should work in this particular case. Commented Jan 27, 2021 at 11:12
  • 1
    If you prefix your youtube-dl command with setsid it will run in a new terminal session so you can kill it with -stop and -cont without the change in state being seen by the shell. Commented Jan 29, 2021 at 12:51

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.