Peter wrote:
> thread1 open a channel and then run command(such as ping) as I
> mentioned above. And thread2 open another channel run command
> such as "killall ping" to terminate the command.

Besides the mutex, consider what happens when your program runs two
or more times using the same account on a remote server.

If you need reliable remote process management then you must
implement a service which does this for you, that runs on the remote
server. SSH does not solve that problem for you, you have to do that
yourself.