# manager-process

> Gets the manager process in a multi-processing application.

Latest version **0.1.5** (published 2021-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install manager-process
pnpm add manager-process
yarn add manager-process
bun add manager-process
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2021-03-29 |
| First published | 2018-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 7.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Ayon Lee |
| Maintainers | hyurl |
| Keywords | multi-processing, manager-process |

## Links

- npm: https://www.npmjs.com/package/manager-process
- Repository: https://github.com/hyurl/manager-process
- Homepage: https://github.com/hyurl/manager-process#readme
- Issues: https://github.com/hyurl/manager-process/issues
- npm.io page: https://npm.io/package/manager-process

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [argv-split](https://npm.io/package/argv-split.md) ^2.0.1
- [find-process](https://npm.io/package/find-process.md) ^1.4.4

## Recent versions

- 0.1.5 (latest) — 2021-03-29
- 0.1.4 — 2019-07-18
- 0.1.3 — 2019-04-07
- 0.1.2 — 2018-11-08
- 0.1.1 — 2018-11-08
- 0.1.0 — 2018-11-08

## README

# Manager Process

In multi-processing scenario, it's better to handle some operations in just one 
process, rather than repeatedly running them in all processes. If you  you have 
all control of the master process, you can just put the code in the master 
process. However, you don't have control, e.g. using [PM2](https://pm2.io), you 
need a way to find out which process should run the specific program. Such a 
process, I call it the **Manager** process.

## Example

```javascript
const manager = require("manager-process");

(async () => {
    var _manager = await manager.getManager();
    var processes = await manager.getAllProcesses();
    var pid = await manager.getManagerPid();
    var isManager = await manager.isManager();

    if (isManager) {
        // TODO...
    }

    // This is the same
    if (pid === process.pid) {
        // TODO...
    }

    console.log(_manager);
    // {
    //  pid: number,
    //  ppid?: number,
    //  uid?: number;
    //  gid?: number;
    //  name: string;
    //  cmd: string;
    // }

    console.log(processes);
    // Array<{
    //  pid: number,
    //  ppid?: number,
    //  uid?: number;
    //  gid?: number;
    //  name: string;
    //  cmd: string;
    // }>
})();
```

---
_Source: https://npm.io/package/manager-process · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
