Subject: How to kill a process launched using libssh2_channel_process_startup

How to kill a process launched using libssh2_channel_process_startup

From: Shawn Singh <>
Date: Wed, 27 May 2020 08:21:50 -0700


I've got a custom app that uses libssh2 to run a series of commands on a
There basically end up being 2 process trees.

1. The first tree... the user logging in and launching the app:
sshd->sshd [ priv ] -> sshd -> bash -> app

2. The second tree that's being created by the app:
sshd->sshd [ priv ] -> sshd -> bash -c exec 1>/dev/null; ... (several
commands, last one being a ruby program) -> ruby

The user does a control+c, which causes the app (in the first tree) to die;
however the 2nd tree is alive and well, which makes sense to me.

If I were on the command-line, I'd just kill the ruby process, and being
the last program in the list, would be last child, so the parent bash
process won't have anything else to execute, so the bash will go away, etc.

What I'm wondering... is there a way I can send my signal to a child
process in this example that ruby program to achieve the same effect as if
I were on the command-line?

If it helps, the call that is spawning the 2nd tree looks like:
libssh2_channel_process_startup(channel, "exec", sizeof("exec") - 1,
ecmd.c_str(), static_cast<unsigned int>(commandLength))

Once started, the process is polled using libssh2_channel_read_ex to read
data from the channel. I tried to send an eof to the channel; however,
learned that the EOF will cause the ssh session to terminate; however,
killing the parent doesn't affect the child (as should have been expected).

I've read online where one user back in '09 suggested sending ETX; however,
I'm not sure how to do that, and even if I do that, will that do what I



It is well that war is so terrible, otherwise we should grow too fond of
it. - Gen. R. E. Lee

Received on 2020-05-27