使用shelljs创建了一个子进程
!/usr/bin/env node
require('/usr/local/lib/node_modules/shelljs/global');
fs = require("fs");
var child=exec("sudo mongod &",{async:true,silent:true});
function on_exit(){
console.log('Process Exit');
child.kill("SIGINT");
process.exit(0)
}
process.on('SIGINT',on_exit);
process.on('exit',on_exit);
Run Code Online (Sandbox Code Playgroud)
子进程仍在运行..杀死父进程后
我在使用TerminateProcess. 我调用这个函数,进程仍然存在(在任务管理器中)。这段代码被多次调用,多次启动相同的 program.exe,这些进程在任务管理器中,我认为这并不好。实际上一直在创建两个进程:program.exe和conhost.exe。
我真的很感激任何帮助。
这是代码:
STARTUPINFO childProcStartupInfo;
memset( &childProcStartupInfo, 0, sizeof(childProcStartupInfo));
childProcStartupInfo.cb = sizeof(childProcStartupInfo);
childProcStartupInfo.hStdInput = hFromParent; // stdin
childProcStartupInfo.hStdOutput = hToParent; // stdout
childProcStartupInfo.hStdError = hToParentDup; // stderr
childProcStartupInfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
childProcStartupInfo.wShowWindow = SW_HIDE;
PROCESS_INFORMATION childProcInfo; /* for CreateProcess call */
bOk = CreateProcess(
NULL, // filename
pCmdLine, // full command line for child
NULL, // process security descriptor */
NULL, // thread security descriptor */
TRUE, // inherit handles? Also use if STARTF_USESTDHANDLES */ …Run Code Online (Sandbox Code Playgroud)