20.12.2018, 10:13
Hi
I see this code potentially dangerous. I think there is small but still chance you hit a different running process with the same PID after LM restart. Isn't there more "clean" solution? Mutexes, semaphores etc?
How about adding new function script.NumActive() which returns number of parallel running instances of the same script? And call this function in the loop cycle after sleep and exit the cycle after the returned value is bigger than 1?
I see this code potentially dangerous. I think there is small but still chance you hit a different running process with the same PID after LM restart. Isn't there more "clean" solution? Mutexes, semaphores etc?
How about adding new function script.NumActive() which returns number of parallel running instances of the same script? And call this function in the loop cycle after sleep and exit the cycle after the returned value is bigger than 1?
Code:
tpid = storage.get('PID:' .. _SCRIPTNAME)
if tpid == nil then
pid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
else
pid = os.getpid()
storage.set('PID:' .. _SCRIPTNAME, pid)
os.kill(tpid, signal.SIGKILL)
end
LM5Lp, firmware: 2018.08.22 and 2021.12.15, FlashSYS v2, ARMv7 Processor rev 5 (v7l), kernel 4.4.151 and 4.4.259