The script I use for my shutters has 400 line and handle several scenarios triggered by arguments at call, so I try to explain only in short.
When I start the script (by pimatic rule) it does it job. One of the first commands in it is to write its pid into a tmp file by using “echo $$”. This file exists as long as the script runs. The runtime can take up to 30 seconds. Most of this time will be spend to wait for the correct shutter end position (the script sleeps).
When it will be necessary to stop or I decide to move the shutters up during running down, maybe after 6 second I press the stop or up button (button device) in pimatic and the same script will be called via rule with the relevant stop or up argument. At the really beginning (before the script write its pid into the tmp file) it checks for a existing pid file. If this exists the content will be read and used to kill the found process pid.
When I don’t kill the process the script which starts the shutter movement is still alive and stops the shutters once more in the 24 second after the shutter where already stopped in the explained scenario (runtime 30s - 6s until press stop or up).
Unfortunately Jarolift can not be controlled easily directly be pimatic. So I handled it by my magic crazy script…