for (i = 0; i < 1030; i++)
{
var fs = require("fs")
var spawn = require("child_process").spawn
var log = fs.openSync("./program.log", "a")
var child = spawn("./program", [], {detached: true, stdio: ["ignore", log, log]})
child.unref()
}
我对进程1024的计数打开文件有ulimit,执行后此代码有ENOENT错误
我可以增加对其他值的限制,但在这种情况下,我不再需要日志文件描述符。如何将这个fd传递给spawn后取出它?
答案 0 :(得分:0)
ENOENT表示文件/目录不存在。这并不意味着您打开了太多文件。当打开太多文件时发生的错误是EMFILE。
但是,ENOENT不应该这样:
var log = fs.openSync("./program.log", "a")
如果文件不存在,应该创建一个文件。
错误发生在子进程或父进程中?子进程是否使用任何文件?
根据open(2)男人:
ENOENT O_CREAT is not set and the named file does not exist. Or, a
directory component in pathname does not exist or is a
dangling symbolic link.
ENOENT pathname refers to a nonexistent directory, O_TMPFILE and one
of O_WRONLY or O_RDWR were specified in flags, but this kernel
version does not provide the O_TMPFILE functionality.
您的错误应该是第二种选择,因为您的openSync调用将创建该文件。
当前文件夹中有./program
吗?
答案 1 :(得分:0)
关闭(日志)