1

I am running the following command in a loop (without notable memory leaks) as a cPanel user:

nohup php ~/www/app/console.php run clean 1> /dev/null 2> ~/www/logs/run_clean.log &

But when I exit SSH, the command always stops. When I do a htop as root, I can't see the process running.

If I don't exit the SSH for days, for instance, the process will continue running fine!

What is wrong? Is not expected for the command I have posted to run in the background without interruption?

Mat
  • 1,536
  • 1
  • 17
  • 21
  • 3
    Just put it into a `screen` or `tmux` session. It's reliable and easier than to fiddle with `nohup` and I/O redirection. – Sven Apr 19 '14 at 08:40
  • @SvW What if I need another `screen` session? The previous one will not be closed? – Gabriel Santos Apr 19 '14 at 08:44
  • 1
    No, it will not be closed. You can have multiple screen sessions with multiple windows open for each. Read about how `screen` works. It's a godsend and about the most useful tool for remote work next to `ssh`. – Sven Apr 19 '14 at 08:49
  • @SvW Worked fine! (: – Gabriel Santos Apr 19 '14 at 08:56

1 Answers1

2

The command might detect its stdin being closed at logout. Try redirecting it from /dev/null:

nohup php ~/www/app/console.php run clean 1> /dev/null 2> ~/www/logs/run_clean.log  </dev/null &
jlliagre
  • 8,691
  • 16
  • 36