Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

[NodeJS] kill子进程后,子进程执行的程序未退出

环境: win10 => CMD => node main.js

main.js:
    const { exec } = require('child_process')
    const child = exec(一些 CMD:如 git 批处理 /执行其他 node 脚本,子进程回调)
    global[child.pid] = child
    
    setTimeout(()=> child.kill(), 1000) 

问题:

某些情况下(如 git merge 存在冲突, 其他 node 脚本业务特定异常)
这些情况会执行 child.kill()
且发现 child 的 exit 事件会被触发
且发现 child 的 killed 是 true
但是,如 git 批处理依然会继续执行, node 脚本也未被中断退出

请问这该怎么处理


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...