How to monitor a python process and restart it upon abnormal termination
<p>Assume that there is a <code>task.py</code>,breaking due to memory overflow.How can i monitor this and restart it?</p>

<pre><code>import time
while(1):
    print('.')
    # simulate breaks
    time.sleep(2)
    exit(0)
</code></pre>

<p>Thanks</p>

<p>If it actually runs out of memory it should get <a href="https://www.kernel.org/doc/gorman/html/understand/understand016.html" rel="nofollow">OOM killed</a>. If you have another process which restarts it continuously (for example <code>while true; do /path/to/my_script.py; done</code>) it should get up and running again immediately.</p>

python linux bash