如果 input 流接收到 SIGTSTP 时没有注册 'SIGTSTP' 事件监听器,则 Node.js 进程将被发送到后台。

当使用 fg(1p) 恢复程序时,则将触发 'pause''SIGCONT' 事件。 这些可用于恢复 input 流。

如果 input 在进程发送到后台之前暂停,则不会触发 'pause''SIGCONT' 事件。


rl.on('SIGTSTP', () => {
  // 这将覆盖 SIGTSTP 
  // 并且阻止程序进入后台。
  console.log('Caught SIGTSTP.');

Windows 不支持 'SIGTSTP' 事件。

The 'SIGTSTP' event is emitted when the input stream receives a <ctrl>-Z input, typically known as SIGTSTP. If there are no 'SIGTSTP' event listeners registered when the input stream receives a SIGTSTP, the Node.js process will be sent to the background.

When the program is resumed using fg(1p), the 'pause' and 'SIGCONT' events will be emitted. These can be used to resume the input stream.

The 'pause' and 'SIGCONT' events will not be emitted if the input was paused before the process was sent to the background.

The listener function is invoked without passing any arguments.

rl.on('SIGTSTP', () => {
  // This will override SIGTSTP and prevent the program from going to the
  // background.
  console.log('Caught SIGTSTP.');

The 'SIGTSTP' event is not supported on Windows.