I am running my Python script in the background in my Ubuntu machine (12.04) like this -
nohup python testing.py > test.out &
Now, it might be possible that at some stage my above Python script
can die for whatever reason.
So I am thinking to have some sort of cron agent
in bash shell script which can restart my above Python script automatically if it is killed for whatever reason.
Is this possible to do? If yes, then what's the best way to solve these kind of problem?
UPDATE:
After creating the testing.conf
file like this -
chdir /tekooz
exec python testing.py
respawn
I ran below sudo command to start it but I cannot see that process running behind using ps ax?
root@bx13:/bezook# sudo start testing
testing start/running, process 27794
root@bx13:/bezook# ps ax | grep testing.py
27806 pts/3 S+ 0:00 grep --color=auto testing.py
Any idea why px ax is not showing me anything? And how do I check whether my program is running or not?
This is my python script -
#!/usr/bin/python
while True:
print "Hello World"
time.sleep(5)