How to use the kill function from process

Find comprehensive JavaScript process.kill code examples handpicked from public code repositorys.

161
162
163
164
165
166
167
168
169
170
function checkProcess (pid) {
  if (!pid) {
    return false;
  }
  try {
    nodeProcess.kill(pid, 0);
    return true;
  } catch (err) {
    // there is no such a process...
    return false;
fork icon70
star icon587
watch icon21

+ 5 other calls in file

26
27
28
29
30
31
32
33
34
35
    app.listen(3000);
}
// 当主进程被终止时,关闭所有工作进程
process.on('SIGTERM', function () {
    for (var pid in workers) {
        process.kill(pid);
    }
    process.exit(0);
});
require('./test')
fork icon227
star icon379
watch icon28

+ 5 other calls in file

224
225
226
227
228
229
230
231
232
233
234
    'lsof',
    ['-i', ':8080', '-t'],
    null,
    (printOutput = false)
  );
  if (serverPid) kill(serverPid, 'SIGKILL');
  console.log(green, 'Terminated the test demo');
};


const checkTestResult = (result) => {
fork icon149
star icon230
watch icon0

+ 5 other calls in file

451
452
453
454
455
456
457
458
459
460
461
  }
}


async function kill_process(pid, init_new) {
  console.log(`terminating process with pid ${pid}`)
  process.kill(pid, "SIGTERM")
  try {
    await new Promise(resolve => setTimeout(resolve, 1000))
    //check if still running
    process.kill(pid, 0)
fork icon10
star icon77
watch icon0

+ 4 other calls in file

14
15
16
17
18
19
20
21
22
23
24


function fileMarkov (path) {
    fs.readFile(path, 'utf8', (err, data) => {
        if (err) {
            console.log(`error reading ${path}`, err)
            process.kill(1);
        }
        else {
            runMarkov(data);
        }
fork icon0
star icon0
watch icon0