Skip to content

Instantly share code, notes, and snippets.

@dstyle0210
Created January 5, 2023 02:04
Show Gist options
  • Select an option

  • Save dstyle0210/cab187db662aaa4012240a940873112f to your computer and use it in GitHub Desktop.

Select an option

Save dstyle0210/cab187db662aaa4012240a940873112f to your computer and use it in GitHub Desktop.
[node] pid을 이용해서 node로 발생시킨 자식프로세스 닫기(연결끊기)
// 참고 : https://velog.io/@dev2820/nodejs%EC%9D%98-%EC%9E%90%EC%8B%9D%ED%94%84%EB%A1%9C%EC%84%B8%EC%8A%A4
const { spawn } = require("child_process");
const makeChildProcess = () => {
const child = spawn("커멘드",{
detached:true,
stdio:"ignore"
});
console.log( child.pid ); // (1) 나중에 닫을려고 일단 꺼내보기
child.unref(); // 자식프로세스와 연결끊기(부모프로세스 종료)
}
const closeChildProcess = () => {
process.kill(pid); // (1) 에서 본 pid 입력해서 넣으면 동작
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment