# ntsuspend

> Suspend and resume processes on Windows

Latest version **1.0.2** (published 2021-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install ntsuspend
pnpm add ntsuspend
yarn add ntsuspend
bun add ntsuspend
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-06-21 |
| First published | 2020-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 11 |
| Author | Federico Carboni |
| Maintainers | federicocarboni |
| Keywords | windows, win32, suspend, pause, resume, process |

## Links

- npm: https://www.npmjs.com/package/ntsuspend
- Repository: https://github.com/FedericoCarboni/node-ntsuspend
- Homepage: https://github.com/FedericoCarboni/node-ntsuspend#readme
- Issues: https://github.com/FedericoCarboni/node-ntsuspend/issues
- npm.io page: https://npm.io/package/ntsuspend

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-06-21
- 1.0.1 — 2021-02-07
- 1.0.0 — 2020-11-04
- 0.2.0-alpha.0 — 2020-10-31
- 0.1.1-alpha.0 — 2020-10-14
- 0.1.0-alpha.1 — 2020-10-12

## README

# NtSuspend
Suspend and resume processes on Windows using `NtSuspendProcess()` and
`NtResumeProcess()`. This is a Node.js only module, it won't run in any
browser or other JavaScript environments.

This project includes TypeScript declarations.

Feel free to ask anything by opening an issue on GitHub.

**Only NodeJS 10.x or higher is supported**

## Install
The library can be installed from NPM or from GitHub:

`npm i ntsuspend`

`npm i FedericoCarboni/node-ntsuspend`

To use it in your project you can `import` or `require()` it.

```ts
import { suspend, resume } from 'ntsuspend';
```
```ts
const { suspend, resume } = require('ntsuspend');
```

**Note:** Make sure to use this package as an optional dependency if you want to
support multiple operating systems. Optional imports in ESM can be achieved with
top-level `await`, still unavailable in LTS releases, and dynamic `import` or by
using [`createRequire()`](https://nodejs.org/dist/latest-v12.x/docs/api/modules.html#modules_module_createrequire_filename).

```ts
if (process.platform === 'win32') {
  const ntsuspend = await import('ntsuspend');
  // ... use ntsuspend
}
```

```ts
import { createRequire } from 'module';

if (process.platform === 'win32') {
  const ntsuspend = createRequire(import.meta.url)('ntsuspend');
  // ... use ntsuspend
}
```

In CommonJS `require()` can already be used conditionally.

```ts
if (process.platform === 'win32') {
  const ntsuspend = require('ntsuspend');
  // ... use ntsuspend
}
```

## Usage
The package exports `suspend()` and `resume()`, they take the process' PID and
return `true` on success, `false` otherwise.

```ts
if (!suspend(pid))
  console.log('Could not suspend process');
if (!resume(pid))
  console.log('Could not resume process');
```

If you are using Node.js' child processes the process id can be obtained by using [`subprocess.pid`](https://nodejs.org/api/child_process.html#child_process_subprocess_pid).
**Note:** make sure that you're passing the actual process id to ntsuspend; the `ChildProcess` instance returned by `child_process.exec` is a handle to the shell not to the actual subprocess. Use `child_process.spawn` and make sure that the `shell` option is disabled.
See [#3](https://github.com/FedericoCarboni/node-ntsuspend/issues/3).

```ts
const subprocess = spawn('executable');
if (!suspend(subprocess.pid))
  console.log('Could not suspend process');
```

**Note:** If you're not on Windows `suspend()` and `resume()` will be `undefined`.

## Disclaimer
This library uses `NtSuspendProcess()` and `NtResumeProcess()` from `NTDLL`, these functions are not
officially documented on MSDN; they have been consistently available since Windows XP, but are not
guaranteed to work in the future.

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