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

Post Reply
brid.surapol
Posts: 156
Joined: 11 Apr 2013, 11:43

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

Post by brid.surapol »

https://stackoverflow.com/questions/192 ... -as-daemon

Code: Select all

setsid ./myscript.sh >/dev/null 2>&1 < /dev/null &
brid.surapol
Posts: 156
Joined: 11 Apr 2013, 11:43

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

Post 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.
Post Reply

Return to “การใช้งาน Linux”