Created
November 2, 2015 10:32
-
-
Save piaoger/afa5e91fa114ec7f7a91 to your computer and use it in GitHub Desktop.
isProcessRunning.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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