1.4.10 • Published 4 months ago

find-process v1.4.10

Weekly downloads
521,461
License
MIT
Repository
github
Last release
4 months ago

find-process

Node.js CI js-standard-style

With find-process, you can:

  • find the process which is listening specified port
  • find the process by pid
  • find the process by given name or name pattern

We have covered the difference of main OS platform, including Mac OSX, Linux, Windows and Android (with Termux).

CLI

Install find-process as a CLI tool:

$ npm install find-process -g

Usage:

  Usage: find-process [options] <keyword>


  Options:

    -V, --version      output the version number
    -t, --type <type>  find process by keyword type (pid|port|name)
    -p, --port         find process by port
    -h, --help         output usage information

  Examples:

    $ find-process node          # find by name "node"
    $ find-process 111           # find by pid "111"
    $ find-process -p 80         # find by port "80"
    $ find-process -t port 80    # find by port "80"

Example:

image

Node API

You can use npm to install:

$ npm install find-process --save

Usage:

const find = require('find-process');

find('pid', 12345)
  .then(function (list) {
    console.log(list);
  }, function (err) {
    console.log(err.stack || err);
  })

Synopsis

Promise<Array> find(type, value, [options])

Arguments

  • type the type of find, support: port|pid|name
  • value the value of type, can be RegExp if type is name
  • options this can either be the object described below or boolean to just set strict mode
    • options.strict the optional strict mode is for checking port, pid, or name exactly matches the given one. (on Windows, .exe can be omitted)
    • options.logLevel set the logging level to trace|debug|info|warn|error. In practice this lets you silence a netstat warning on Linux.

Return

The return value of find-process is Promise, if you use co you can use yield find(type, value) directly.

The resolved value of promise is an array list of process ([] means it may be missing on some platforms):

[{
  pid: <process id>,
  ppid: [parent process id],
  uid: [user id (for *nix)],
  gid: [user group id (for *nix)],
  name: <command/process name>,
  bin: <execute path (for *nix)>,
  cmd: <full command with args>
}, ...]

Example

Find process which is listening port 80.

const find = require('find-process');

find('port', 80)
  .then(function (list) {
    if (!list.length) {
      console.log('port 80 is free now');
    } else {
      console.log('%s is listening port 80', list[0].name);
    }
  })

Find process by pid.

const find = require('find-process');

find('pid', 12345)
  .then(function (list) {
    console.log(list);
  }, function (err) {
    console.log(err.stack || err);
  });

Find all nginx process.

const find = require('find-process');

find('name', 'nginx', true)
  .then(function (list) {
    console.log('there are %s nginx process(es)', list.length);
  });

Find all nginx processes on Linux without logging a warning when run as a user who isn't root.

const find = require('find-process');

find('name', 'nginx', {strict: true, logLevel: 'error'})
  .then(function (list) {
    console.log('there are %s nginx process(es)', list.length);
  });

Contributing

We're welcome to receive Pull Request of bugfix or new feature, but please check the list before sending PR:

  • Coding Style Please follow the Standard Style
  • Documentation Add documentation for every API change
  • Unit test Please add unit test for bugfix or new feature

License

MIT

@dysolix/hasagichrome-devtools-devicespioneer-cosmos-tx-ingesterdiscord-self-bots-ez@dxos/xbox-dashboardmenlolab-runner@honeyworks/holochain-corecopydistpdxdeploy-v3.1.3@byteinspire/cli@infinitebrahmanuniverse/nolb-findopensea-submarine-v2git-repo-blog-generator@everything-registry/sub-chunk-1669@fed123/fe-plugin-monitortailchat-clixhyabunny-selfbot-v13spoktest-ugs-asset-gen-avite-postgresvisopvcr-cli@coasys/ad4m-test@commonshost/server@cuties/process@conneryn/cli-bundle@conneryn/cli-tmp@perspect3vism/ad4m-testjdescottes-jest-dev-serverjest-dev-serverjsyncdjest-process-manageriotsphere-clikatsu-sbkhala-nodeutilslbry-sdk-node@hotfusion/gatewaypdxdeployssj-v13.jssourcescapetyzxbsultra-pwa-asset-generatortoad-servertor-mgrturbowatch@aragon/aragen@arcblock/forge-cli@applitools/execution-grid-tunnel@atrilabs/commands@atrilabs/commands-builder@athenadevops/cli@athenadevops/remote@aiot-toolkit/emulator@albertoielpo/kk-cli@axetroy/kp@afternun/jest-dev-server@c6o/cli@chrissong/simo-utils@churchonline/proxy@abtnode/router-provider@davidkhala/nodeutils@dengwenlong/dwl-coreyio-coreyaml2solanawebpack-port-collectorzionbox-desktopzionbox-mirrorzionbox-service@fdnpm/fd-module-cli@dxos/signal@editframe/editframe-js@gswl/startup@guseyn/cutie-process@hankts/shopify-cli-kit@hashed-alejandro/afloat-client@http2/server@gaarutyunov/pwa-asset-generator@krenaldi/learnstorybook-design-system-template@langhuihui/monica@lockerpm/desktop-service@laraboot-io/cli@lanz1/v-money3@itayn-fireberry-org/itayn-test@lightprotocol/cli@lightprotocol/zk-compression-cli@maxbo/free-port@mgutz/task@microsoft/inshellisense@mozilla/jest-dev-server@mashroom/mashroom-utils@needle-tools/helper@node-sc2/core@e11/libraries@elgato/cli@max_alieksieiev/react-pdf-viewer-root@meese-enterprises/file-syncer@mcsb/watch@mikojs/worker@mina-tools/cli@mina-tools/core
1.4.10

4 months ago

1.4.9

4 months ago

1.4.8

4 months ago

1.4.6

3 years ago

1.4.7

3 years ago

1.4.5

4 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago