Andrew Bashtannik Andrew Bashtannik - 9 days ago 5
Linux Question

How to run infinitely script in background on Linux?

I have a PHP script with infinite loop. I need this script running forever. So, I run

php /path/to/script.php > /dev/null &


And it works in background in my current user's security context. But when I close terminal window (log off), of course, CentOS Linux kills my program.

I see two guesses: run from a different user in background or make a daemon. I need help in each situation.

Thanks a lot!

Answer

nohup is your friend.

nohup command &