# Listen for SIGINT and SIGTERM Events in a ZX Script

DevFeed: [Listen for SIGINT and SIGTERM Events in a ZX Script](<https://devfeed.tech/articles/listen-for-sigint-and-sigterm-events-in-a-zx-script-21823.md>)

Original publisher: [Read original article](<https://www.thepolyglotdeveloper.com/blog/2023/01/listen-sigint-sigterm-events-zx-script/>)

Author: Nic Raboy

Published: 2023-01-06T21:00:00Z

Content type: tutorial

Language: en

Sources: [Nic Raboy](<https://devfeed.tech/sources/nic-raboy.md>)

Topics: [Tutorial](<https://devfeed.tech/topics/tutorial.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [build](<https://devfeed.tech/tags/build.md>), [capture](<https://devfeed.tech/tags/capture.md>), [cleanup](<https://devfeed.tech/tags/cleanup.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [event](<https://devfeed.tech/tags/event.md>), [event-listeners](<https://devfeed.tech/tags/event-listeners.md>), [events](<https://devfeed.tech/tags/events.md>), [graceful-shutdown](<https://devfeed.tech/tags/graceful-shutdown.md>), [infinite](<https://devfeed.tech/tags/infinite.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [linux](<https://devfeed.tech/tags/linux.md>), [long-running](<https://devfeed.tech/tags/long-running.md>), [macos](<https://devfeed.tech/tags/macos.md>), [node-js](<https://devfeed.tech/tags/node-js.md>), [permissions](<https://devfeed.tech/tags/permissions.md>), [process](<https://devfeed.tech/tags/process.md>), [script](<https://devfeed.tech/tags/script.md>), [signal](<https://devfeed.tech/tags/signal.md>), [zx](<https://devfeed.tech/tags/zx.md>)

## AI overview

The excerpt describes using JavaScript signal listeners in a ZX script to handle shutdown of a long-running process. It requires ZX, Node.js 16 or later, and Unix (macOS) or Linux; the author notes the first part may work on Windows, while sending signals from the host may differ. The example simulates a long-running process with a 100-second sleep and presents SIGTERM as a graceful shutdown request where cleanup logic can run. The excerpt ends before showing the listener implementation or explaining SIGINT.

## Source excerpt

Have you ever needed to handle signal events within your ZX script? For example, what happens if you need to handle a graceful shutdown of your long-running or infinite-running script? Or what happens... The post Listen for SIGINT and SIGTERM Events in a ZX Script appeared first on The Polyglot Developer.