Skip to content

Instantly share code, notes, and snippets.

@piaoger
Created November 2, 2015 10:32
Show Gist options
  • Select an option

  • Save piaoger/afa5e91fa114ec7f7a91 to your computer and use it in GitHub Desktop.

Select an option

Save piaoger/afa5e91fa114ec7f7a91 to your computer and use it in GitHub Desktop.
isProcessRunning.js
// a signal of 0 can be used to test for the existence of a process.
var exec = require('child_process').exec
var tryKill
function isRunning(pid, cb) {
var err = null,
result = null;
if (typeof pid !== 'number') {
err = "pid must be number"
} else {
result = tryKill(pid)
}
if (err) {
return err
}
return result
}
function tryKillfunction(pid) {
var result
try {
result = process.kill(pid,0)
return result
} catch (e) {
return e.code === 'EPERM';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment