我使用forever
包来运行我的Node.js脚本。 (不是网络服务器)。然而,因为它,我有内存泄漏,甚至停止所有流程后,我的记忆依然采取:永久节点(npm包)服务器上的内存泄漏
[email protected]:~# forever stopall
info: No forever processes running
[email protected]:~# forever list
info: No forever processes running
[email protected]:~# free -lm
total used free shared buffers cached
Mem: 11721 6900 4821 5 188 1242
Low: 11721 6900 4821
High: 0 0 0
-/+ buffers/cache: 5469 6252
Swap: 0 0 0
另外提一下,有一个从剧本没有内存泄漏时,没有永远本地运行。我在Ubuntu服务器上运行它。如果我现在重新启动服务器:
[email protected]:~# reboot
Broadcast message from [email protected]
(/dev/pts/0) at 3:19 ...
The system is going down for reboot NOW!
我的RAM将重获自由:
[email protected]:~# free -lm
total used free shared buffers cached
Mem: 11721 1259 10462 5 64 288
Low: 11721 1259 10462
High: 0 0 0
-/+ buffers/cache: 905 10816
Swap: 0 0 0
我也想提一提的是,当我的脚本完成它是做什么(和它最终不会)我有db.close
和process.exit
调用,以确保从我的脚本一侧杀死所有东西。但是,即使在RAM被拿走之后。现在我知道永远会在死亡后再次运行该脚本。所以我的问题是:
- 如何永远告诉不要再次执行脚本,如果它完成?
- 我该如何正确地停下来,以便在我停止后不需要任何RAM?
我为此永远使用包的原因是因为我的脚本需要很多时间来做它做的事情,而且我的SSH会话会结束,所以我会以普通方式运行节点脚本。
你可能喜欢使用'top'和'htop'命令来查看您的RAM和CPU的使用,然后你可以杀死进程 –
@ArifKhan但是我真的不希望手动终止进程。我正在寻找一种“永远”包裹来杀死它不再使用的东西。 – Kunok