Linux Prevents Repeated Timing Tasks

  linux, question

Under linux, a scheduled task is started and a script is executed at intervals. However, this script may last for a long time with uncertain time.

In addition, this script can be triggered manually through the background management interface.

The problem has arisen. How can we prevent the child from repeating the task? That is to say, when new tasks come, the old ones need to be stopped.

How?

Usually, linux init script will generate a pid file when starting a program, which is used to store the pid of the program and facilitate the kill operation when stopping the program.

Similarly, your timed task script can also generate a pid file and delete this file when the task is completed. At the beginning of the task, judge whether the file is present or not. If so, you can choose to quit or kill if the previous task is not finished.