Use os.kill(pid, 0) to check process

There is a standard way to check if a process is running if you have its pid: just try to kill it with signal 0

An error is returned if process is not running, and it does nothing if it is