npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nozombie

v1.1.0

Published

track pocesses and make sure they die when they are supposed to

Downloads

125

Readme

npm npm mac ubuntu windows

nozombie

Easy pid tracking and killing. No more zombie processes left alive!

Easy to use

child_process

const nozombie = require( 'nozombie' )
const nz = nozombie()

const spawn = childProcess.spawn( ... )
nz.add( spawn.pid ) // child will be killed when parent (process.pid) dies

puppeteer

const nozombie = require( 'nozombie' )
const nz = nozombie()

const browser = await puppeteer.launch( opts )
const child = browser.process()
nz.add( child.pid ) // child (and descendants) ill be killed when parent (process.pid) dies

time to live

const nozombie = require( 'nozombie' )
const nz = nozombie()

const spawn = childProcess.spawn( ... )
const FIVE_MINUTES_MS = 1000 * 60 * 5

// child will be killed when parent (process.pid) dies or 5 minutes have passed
nz.add( { pid: spawn.pid, ttl: FIVE_MINUTES_MS } )

// to update/refresh the ttl just add the same process pid again with a new ttl
nz.add( { pid: spawn.pid, ttl: FIVE_MINUTES_MS } ) // update ttl

namespace

const nozombie = require( 'nozombie' )
const nz = nozombie()

const SCRAPE_INTERVAL = 1000 * 60 * 3

setTimeout( scapeData, 0 )
function scapeData () {
	const browser = await puppeteer.launch( opts )
	const child = browser.process()

	const namespace = 'scrape-data'

	// kill all children with this namespace
	nz.kill( namespace )

	// won't be killed as it was added after the kill call
	nz.add( { pid: child.pid, name: namespace } )

	// do something
	setTimeout( scapeData, SCRAPE_INTERVAL )
}

About

Track child pid's and kill them off when parent process dies.

Why

To help keep track of pid's that need to be killed off and not leave running for too long.

For who?

For those wanting a simple way prevent zombies.

How

By spawning a detached, stdio ignored, unref'ed subprocess to keep track of pids.

Once it notices that a parent pid has died, it will go into a killing rampage of children pid's.

If all children are killed or after ~15 seconds it will suicide. Regardless if some children pid's remain alive.

Killing attempts happen about every ~1second when a children is doomed to death. A children is doomed under the following circumstances: 1. main parent process dies 2. a named parent process dies with the same name as the children 3. ttl expires 4. nz.kill() is called 5. nz.kill( name:string ) of children with that name is called

The subprocess reads the relevent pid's from a shared temporary file the main parent process creates before spawning the subprocess. The subprocess will clean up this temporary file before it kills itself.

NOTE!

Killing children isn't guaranteed. When a child is doomed, it is usually killed within a few seconds. If a child is not killed by its 10th attempt (within ~10-15 seconds), it will be considered immortal, ignored and removed silently.

API

const nozombie = require( 'nozombie' )

const nz = nozombie()
	// spawns (or returns already existing) detached subprocess api

nz.add( pid )
	// pid: number
	// add pid to be killed when parent process dies

nz.add( opts )
	// opts.pid: number
	// opts.name: string (optional)
	// opts.ttl: number (optional)
	// add pid that will be killed when the ttl expires or can be manually
	// killed by its name

nz.kill()
	// kill all children that were added up until this point (order of add/kill matters)

nz.kill( name )
	// name: string
	// kill all children that match this name up until this point (order of add/kill matters)

// advanced usecase -- you probably don't need this
nozombie.spawn( { main_parent_pid: number } )
	// spawn a new subprocess api and set its main_parent_pid manually
	// main_parent_pid defaults to process.pid

Similar

tree-kill ps-list.

Test

npm test