[英]Node.js completely remove file in a running script
I have a Node.js
script that is running in a while (true)
fashion and watches directories for certain files and removes them using unlink
API
:我有一个
Node.js
脚本,它以一段while (true)
方式运行并监视某些文件的目录并使用unlink
API
删除它们:
fs.unlinkSync(path);
The files are not created by Node
process, but as POSIX
documentation about unlink
says, files are not removed from disk until process is closed, thus lsof
will list them as (deleted)
and tied to node
process.这些文件不是由
Node
进程创建的,但正如关于unlink
的POSIX
文档所说,文件在进程关闭之前不会从磁盘中删除,因此lsof
会将它们列为(deleted)
并绑定到node
进程。
My script is some kind of a "watchdog"
, so how would I go to removing those files and cleaning up disk space without restarting the Node
process itself?我的脚本是某种
"watchdog"
,那么我将如何 go 在不重新启动Node
进程本身的情况下删除这些文件并清理磁盘空间?
Thanks!谢谢!
I would try child_process
:我会尝试
child_process
:
const { execSync } = require('child_process');
execSync(`rm ${filePath}`)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.