You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running a command using execCommand method. Also I'm passing a onChannel ( clientChannel: ClientChannel) option as parameter to get client channel connection.
My issue is that I can't by any mean stop the command execution (simulating a CTRL-C during an execution).
To test this out, I run a command with execCommand then I close it, and after I check my running processes on my server it's still running there. I have to mannually kill them with kill {pid}.
Sorry for the very late reply. I tracked down why none of those worked:
close()/end(): without a PTY, OpenSSH leaves the command running when the channel closes. With pty: true, closing hangs up the terminal, which sends SIGHUP; that's why your workaround works. ping stopped anyway because it keeps writing output and dies with SIGPIPE once nobody reads it.
write('\x03'): without a PTY, Ctrl-C is just a byte on the command's stdin.
signal('INT'): ssh2 only sends signal requests while the channel's stdin is open, and execCommand closes stdin right away when you don't pass stdin. So nothing was sent.
v14 adds timeout and signal (an AbortSignal) options. They send the signal request properly, then close the channel:
Against OpenSSH 9.2, this stopped sleep 100, a while true shell loop and sh -c 'sleep 100; ...', including their child processes (sshd signals the process group). The default killSignal is TERM; use KILL for programs that ignore it.
Activity
dudu631 commentedon Mar 1, 2022
One thing I just found out:
The command I'm using invokes an executable file.
Example:
./executable arg1 arg2A command without an executable file like
ping, the close option works.Is there a way to kill the process of a executable file command, without grep and kill?
dudu631 commentedon Mar 1, 2022
Currently using a workaround:
Passing
execOptions: { pty: true }to execCommand params seems to makeclientChannel.close()work.Hoping to listen to more ideas on this.
steelbrain commentedon Nov 16, 2026
Sorry for the very late reply. I tracked down why none of those worked:
close()/end(): without a PTY, OpenSSH leaves the command running when the channel closes. Withpty: true, closing hangs up the terminal, which sends SIGHUP; that's why your workaround works.pingstopped anyway because it keeps writing output and dies with SIGPIPE once nobody reads it.write('\x03'): without a PTY, Ctrl-C is just a byte on the command's stdin.signal('INT'): ssh2 only sends signal requests while the channel's stdin is open, andexecCommandcloses stdin right away when you don't passstdin. So nothing was sent.v14 adds
timeoutandsignal(anAbortSignal) options. They send the signal request properly, then close the channel:Against OpenSSH 9.2, this stopped
sleep 100, awhile trueshell loop andsh -c 'sleep 100; ...', including their child processes (sshd signals the process group). The defaultkillSignalisTERM; useKILLfor programs that ignore it.Add timeout, signal and killSignal options to exec and execCommand (#465