Linux???????????????
???????????? ???????[ 2016/3/14 15:40:52 ] ?????????????? Linux
????“???????”??daemon?????????????е?????daemon????
?????????????ν???? Web ????????????????
????????????????
????Web???д?ú????????????????????????????С?
???????????????????????????????????Node???server.js?????6?С?
????var http = require('http');
????http.createServer(function(req?? res) {
????res.writeHead(200?? {'Content-Type': 'text/plain'});
????res.end('Hello World');
????}).listen(5000);
???????????????????????
????$ node server.js
?????????????????????????????????? 5000 ????????????????????????д?????????????????????????????
??????????????????????????????daemon?????????????service???????????????????
??????????????????????
?????????????????????????”??????”??foreground job???????????????д????????????????????????????????????????
?????????????????????????????”???????”??background job????
????$ node server.js
?????????????β?????????&?????????????”???????”???????????????е?”??????”???”???????”?????????ctrl + z????????bg?????y?????????”???????”??????У???
????“???????”?????????
??????е?? session ????????????????stdout??????????stderr????????????????????????????????????????????????
?????????е?? session ????????stdin?????????????????????????????????????????????????????У?halt????
?????????????”???????”??”??????”?????????????????????б?????????????к???????????????????????????????
????????SIGHUP???
???????”???????”??????????????????????????????????????? session ???”???????”??????????У?
????Linux?????????????
????????????? session
????????? session ????SIGHUP???
????session ??SIGHUP???????????????
????????????SIGHUP??????????
??????????????????????”??????”?????? session ??????????????????????SIGHUP????
?????????”???????”?????????SIGHUP????
???????? Shell ??huponexit???????????
????$ shopt | grep huponexit
????????????????????huponexit?????????
?????????Linux?????????????????off????????session ?????????????SIGHUP??????”???????”???????????????”???????”???????? session ????????
???????disown ????
???????”???????”???”???????”?????????????е?????huponexit??????????????on????
???????????????????disown??????????????????”???????”?б??jobs???????????????????????”???????”??????????б???У?session ???????????????SIGHUP????
????$ node server.js
???????????????????server.js??????????”???????”?б??????????jobs??????????????????棬??????????????
????disown???÷??????
????# ??????????????е???????
????$ disown
????# ?????????????е???????
????$ disown -r
????# ??????к??????
????$ disown -a
????# ????????????????????????????SIGHUP???
????$ disown -h
????# ????jobId????????????????
????$ disown %2
????$ disown -h %2
?????塢??? I/O
???????disown?????????????????????????? session ?????????????????I/O?н???????????????
???????????????????????????????С?
????var http = require('http');
????http.createServer(function(req?? res) {
????console.log('server starts...'); // ???????
????res.writeHead(200?? {'Content-Type': 'text/plain'});
????res.end('Hello World');
????}).listen(5000);
????????????????????????disown???
????$ node server.js
?????????????? session??????5000???????????????
???????????”???????”???? I/O ??????? session??disown??????и??????????”???????”??д??? I/O????????????????????????????????С?
?????????????????????”???????”???? I/O ?????????
????$ node server.js > stdout.txt 2> stderr.txt
??????????????У?????????????????
????????nohup ????
???????б?disown?????????????nohup??
????$ nohup node server.js
????nohup?????server.js???????????????
???????SIGHUP??????????????
??????????????y??????????????κ??????????????????
?????????????????????????nohup.out??
??????????nohup???????????????????????? session ???????
???????nohup????????????????”???????”????????????&?????
???????Screen ?????? Tmux ????
??????????·????? terminal multiplexer ????????????????????????棬??????session??????????? Screen ????? Tmux ???
??????????????? session ???棬???????? session?????????????? session ?????????????????? session?????????????μ????????????????????????? session??
????Screen ???÷??????
????# ?????? session
????$ screen
????$ node server.js
???????????ctrl + A??ctrl + D?????????? session?????????????????′ε????????л????
????$ screen -r
???????????????? session??????????????????
????$ screen -S name
????# ?л???? session
????$ screen -r name
????$ screen -r pid_number
????# ?г????? session
????$ screen -ls
?????????????? session?????????л??????????ctrl + c??ctrl + d??
????Tmux ?? Screen ????????????????????÷??????
????$ tmux
????$ node server.js
????# ?????????session
????$ tmux detach
????????tmux detach???????????????Ctrl + B??d ?????????????? session??
????# ?′ε??????????????????з???session
????$ tmux attach
????????????? session????????? session ????????
????# ??? session
????$ tmux new -s session_name
????# ?л?????? session
????$ tmux attach -t session_name
????# ?г????? session
????$ tmux list-sessions
????# ?????? session?????????? session
????$ tmux detach
????# ?????? session
????$ tmux kill-session -t session-name
???????Node ????
???????? Node ????????????????????????????Щ????????????????forever??nodemon ?? pm2??
????forever ???????????????????????????????????
????# ????????????
????$ forever server.js
????# ?????????????
????$ forever start app.js
????# ?????????
????$ forever stop Id
????# ??????????
????$ forever restart Id
????# ???????????????????б?????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11