Skip to content

benjaminwoods/tmbr

Repository files navigation

tmbr

Kill processes and process trees.

Travis CI Status

Simple use cases:

const tmbr = require('tmbr');

// Kill PID 1337 (using SIGTERM) and all of its children
tmbr(1337)

// Use SIGKILL instead
tmbr(1337, 'SIGKILL')

// Try to kill a stubborn process 3 times with SIGTERM,
// then if the process is still alive, send a SIGKILL
tmbr(
  1337, 'SIGTERM', {retries:2}
).catch(
  () => tmbr(1337, 'SIGKILL')
)

API

Table of Contents

tmbr

Asynchronously kill processes and process trees.

Parameters

  • p (child_process.ChildProcess | number) Child process or PID.
  • signal string Kill signal. (optional, default 'SIGTERM')
  • options Object Additional options. (optional, default {})
    • options.retries number How many times to retry killing each process.
    • options.recursive boolean Recursive kill.

Returns Promise<Object> Promise with information about the process tree.

tmbr/util

asyncKill

Asynchronous kill.

Silently resolves if ESRCH is returned from process.kill(pid, signal).

Parameters
  • pid number PID.

  • signal string Kill signal. (optional, default 'SIGTERM')

  • options Object Additional options. (optional, default {})

    • options.recursive boolean Recursive kill.
  • Throws any If pid is invalid.

Returns Promise<Object> Resolves if PID kill did not error, rejects otherwise.

killAndCheck

Kill process and check for PID afterwards.

Parameters
  • pid number PID.

  • signal string Kill signal. (optional, default 'SIGTERM')

  • options Object Additional options. (optional, default {})

    • options.recursive boolean Recursive kill.
  • Throws any If pid is invalid.

Returns Promise<Object> Resolves if PID kill was successful, rejects otherwise.

lagKill

Wait lag milliseconds, then run killAndCheck.

Parameters
  • pid number PID.

  • signal string Kill signal. (optional, default 'SIGTERM')

  • options Object Additional options. (optional, default {})

    • options.recursive boolean Recursive kill.
  • lag (optional, default 0)

  • Throws any If pid is invalid.

Returns Promise Resolves if PID kill was successful, rejects otherwise.

processExists

Process with PID exists.

Parameters

Returns boolean True if the PID exists, false otherwise.