Browse files

initial commit

  • Loading branch information...
0 parents commit 3f029c3312dc16028c1c3a3827a3d1e3f984b2cb @coolaj86 committed Feb 10, 2011
Showing with 64 additions and 0 deletions.
  1. +16 −0 README.md
  2. +16 −0 example/pid-test.js
  3. +20 −0 lib/pid.js
  4. +12 −0 package.json
16 README.md
@@ -0,0 +1,16 @@
+pid
+===
+
+Install
+
+ npm install pid
+
+Usage
+
+ var pider = require('pid');
+
+ pider('node-pid'); // /tmp/node-pid.pid -- puts in /tmp with ext .pid by default
+
+ pider('./node-pid'); // ./node-pid
+
+ pider('/var/run/node-pid.pid'); // /var/run/node-pid.pid -- if you have permissions
16 example/pid-test.js
@@ -0,0 +1,16 @@
+(function () {
+ "use strict";
+
+ var exec = require('child_process').exec,
+ pider = require('pid');
+
+ pider('node-pid-test');
+ pider('./node-pid-test2');
+ pider('./node-pid-test3.pid');
+ pider('node-pid-test4.pid');
+ setTimeout(function () {
+ exec("ls ./ /tmp | grep node", function (err, stdout, stderr) {
+ console.log(stdout);
+ });
+ }, 100);
+}());
20 lib/pid.js
@@ -0,0 +1,20 @@
+(function () {
+ "use strict";
+
+ var fs = require('fs');
+
+ module.exports = function (path) {
+ if (!/\//.test(path)) {
+ if (!/\.pid/.test(path)) {
+ path += '.pid';
+ }
+ path = '/tmp/' + path;
+ }
+
+ fs.writeFile(path, process.pid.toString() + '\n');
+ process.on('exit', function () {
+ fs.unlink(path);
+ });
+ };
+
+}());
12 package.json
@@ -0,0 +1,12 @@
+{
+ "name" : "pid",
+ "description" : "Creates a pid file.",
+ "url" : "http://github.com/coolaj86/node-pid/",
+ "keywords" : ["util", "pid"],
+ "author" : "AJ ONeal <coolaj86@gmail.com>",
+ "contributors" : [],
+ "dependencies" : [],
+ "lib" : "lib",
+ "main" : "./lib/pid",
+ "version" : "1.0.0"
+}

0 comments on commit 3f029c3

Please sign in to comment.