Page 1 of 1

วิธี run bash script เป็น daemon

Posted: 18 Nov 2020, 10:14
by brid.surapol
https://stackoverflow.com/questions/192 ... -as-daemon

Code: Select all

setsid ./myscript.sh >/dev/null 2>&1 < /dev/null &

Re: วิธี run bash script เป็น daemon

Posted: 18 Nov 2020, 10:15
by brid.surapol
in bash (and most other shells) this is stdin/stderr/stdout redirection. The > /dev/null (same as 1>/dev/null) redirects stdout (which is file descriptor 1) to /dev/null. The 2>&1 means redirect all stderr (file descriptor 2) to file descriptor 1, which is already redirected to /dev/null. The </dev/null attaches /dev/null to stdin (fd 0). All of these let the script detach from all current input/output sources, and reattach to /dev/null.