NodeJS Processes Handle Signals Independently?

33 Views Asked by At

While dealing with an interactive process with NodeJS, I have encountered an issue when catching signals.

I am spawning and communicating with an interactive Prolog process (Ciao Prolog). When this process receives SIGTERM (or Ctrl+C), it shows a Prompt asking for a certain action to take:

Ciao 1.23-v1.21-952-g6b74c67928 (2024-03-06 14:34:25 +0100) [DARWINx86_64]
?- ^C
Ciao interruption (h for help)? h

Ciao interrupt options:
    a        abort           - cause abort
    c        continue        - do nothing
    d        debug           - start debugging
    t        trace           - start tracing
    e        exit            - cause exit
    @        command         - execute a command
    h        help            - get this list

When I spawn this process in a shell and then send the signal with NodeJS, for example:

Welcome to Node.js v20.11.1.
Type ".help" for more information.
> process.kill(PID, 'SIGTERM');

The Prolog process successfully handles the signal and prints the menu out.

However, when the process is spawned with NodeJS API:

const { spawn } = require('node:child_process');

const cproc = spawn('ciaosh', ['-i']);

cproc.stdout.on('data', (data) => console.log(data));

setTimeout(() => {
  process.kill(cproc.pid, 'SIGINT');
}, 3000);

The Prolog process just dies and does not handle the signal correctly.

0

There are 0 best solutions below