Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felixge/node-nix
Node.js bindings for non-portable *nix functions
https://github.com/felixge/node-nix
Last synced: about 2 months ago
JSON representation
Node.js bindings for non-portable *nix functions
- Host: GitHub
- URL: https://github.com/felixge/node-nix
- Owner: felixge
- License: mit
- Created: 2010-12-21T22:51:25.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2010-12-23T12:49:24.000Z (about 14 years ago)
- Last Synced: 2024-10-11T15:19:21.056Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 576 KB
- Stars: 28
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License
Awesome Lists containing this project
README
# node-nix
## Purpose
This is a collection of non-portable *nix functions.
Ryan has stated that he does not want anything in node that cannot be ported
to windows. So I have started this addon for *nix functions that are commonly
found in the standard libraries of other languages.Feel free to suggest additional functions via pull requests / issue tickets!
## Install
To install this package, simply run:
npm install nix
### Example
Using this module, forking a running node.js process is as simple as:
var nix = require('nix');
var pid = nix.fork();
if (pid == 0) {
// this is the child process, pid = 0
} else {
// this is the parent process, pid = child pid
}Calling this after creating and listening on a simple http/tcp server should
work as expected for most parts. That is, requests will be randomly
distributed to the new child and parent process by the kernel.However, if you plan on calling this during a tcp/http request, make sure that
you `destroy()` this stream in either the parent or the child. Otherwise
both of them will try to watch the socket, causing packets to randomly be
seen by either process.## API
### nix.fork();
A binding to [fork(2)](http://linux.die.net/man/2/fork).
Returns `0` for the child process and the pid of the child process for the
parent.This function will create a new child process that is an identical copy of the
parent process. All I/O watchers will be left in-tact, so you need to
understand what this means when calling this function during the runtime
phase of your program.This function is blocking and takes ~3-4ms per call in my benchmarks. Making
it non-blocking would be rather [stupid idea](http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2003-09/0672.html).**Warning:** Do not call this function from the repl on OSX, unless you want
to trigger a kernel panic.## License
node-nix is licensed under the MIT license.