【问题标题】:Nodejs forked child process exits immediately with status code 8Nodejs fork 子进程立即退出,状态码为 8
【发布时间】:2015-01-20 06:07:26
【问题描述】:

每次子进程以 状态码 8 退出时,我都会分叉子进程,并且出于某种奇怪的原因。我做了一堆谷歌搜索,试图弄清楚什么是状态码 8 以及在 Ubuntu 中可能导致这种奇怪行为的原因,但没有运气。我了解到 Node.js 甚至不使用退出状态代码 8,所以我非常有信心它不是 V8。我尝试在不同但相同的 Ubuntu 服务器上执行相同的代码,它运行良好。请注意,我在此服务器上使用负载平衡器。我不确定是什么导致了这个问题。

以下是规格:

  • 节点:v0.10.25
  • 分销商 ID:Ubuntu
  • 说明:Ubuntu 14.04
  • LTS 版本:14.04

这是分叉的子进程(就像我说的那样)

process.on('消息',函数(数据){ console.log('TEST BOT SAYS HELLO' + process.pid) var fs = 要求('fs') fs.writeFile('message.txt', 'abc', function(err, data) { 如果(错误){ 返回控制台.log(错误); } 控制台.log(数据); }); });

编辑: 堆栈跟踪中没有其他错误。任何解决这个问题的线索都会有所帮助!

这是子进程的启动方式:

功能 testChildProcess() { console.log('测试子进程') var testBot = childProcess.fork(require.resolve("./../../bots/testBot")); testBot.send({ 数据:'你好' }); testBot.on('exit', function(code, other) { console.log('子进程退出,退出代码'+代码+'其他'); }); testBot.on('error', function(code) { console.log('子进程 ERRED 退出代码 ' + code); 返回下一个跟踪器(); }); } testChildProcess()

加法: 该应用程序使用运行 https://github.com/yyx990803/pod 在后台使用 pm2

https://github.com/Unitech/pm2 将应用程序作为守护进程启动。

我测试了生成子进程并生成子进程工作得很好......

child.js

变种测试=函数(){ console.log('TEST BOT SAYS HELLO' + process.pid) var fs = 要求('fs') fs.writeFile('./message.txt', 'abc', function(err, data) { 如果(错误){ 返回控制台.log(错误); } 控制台.log(数据); }); } 测试();

父.js

功能 testChildProcess() { 控制台.log(process.cwd()); var ls = childProcess.exec('node '+process.cwd()+'/bots/testBot', function(error, stdout, stderr) { 如果(错误){ console.log(error.stack); console.log('错误代码:' + error.code); console.log('收到的信号:' + error.signal); } console.log('stdout: ' + 标准输出); console.log('stderr: ' + stderr); }); ls.on('退出', function(code) { console.log('子进程退出,退出码' + code); }); }

解决方案: 以防其他人遇到此问题。我设法通过将静默设置为 true 来解决问题。

var testBot = childProcess.fork(require.resolve("./../../bots/testBot"),[],{silent:true});

【问题讨论】:

  • 可能是 errno 8: #define ENOEXEC 8 /* 执行格式错误 */
  • 你是如何启动你的子进程的?
  • 嗨,乔,感谢您的帮助。我用我用来启动子进程的脚本更新了评论。
  • 您在工作和非工作服务器上对testBot 的权限是什么?
  • 乔,出于绝望,我在工作服务器上应用程序的整个根目录上完成了 chmod -R 777 ./* 。仍然得到神秘的退出状态码 8。

标签: node.js ubuntu ubuntu-14.04 child-process


【解决方案1】:

解决方案:如果其他人遇到此问题,我设法将silent 设置为 true。

var testBot = childProcess.fork(require.resolve("./../../bots/testBot"),[],{silent:true});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 2020-07-03
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    相关资源
    最近更新 更多