From: Greg Menke
Subject: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <m3ptm8hu82.fsf@europa.pienet>
I'm using open-pipe to fork an ssh client which logs into a remote
machine and periodically returns some statistics which my program
processes.  That part is working OK, but I've not found a way to kill
the client when I close the stream.  If I simply close the stream, the
ssh client is left running as a child of the Lispworks image.  When I
exit Lispworks, the client is orphaned.  I suppose I could track down
the pid and sigterm it, but that sounds too horrible for words.

I know its more appropriate to ask Xanalys support, but being in the
middle of a hack-fest over the weekend, I was hoping someone might be
able to give me a quick hint.

Thanks,

Greg

From: Harri Haataja
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <pan.2003.05.25.02.32.51.260985@cs.helsinki.fi>
Greg Menke wrote:

> I'm using open-pipe to fork an ssh client which logs into a remote
> machine and periodically returns some statistics which my program
> processes.  That part is working OK, but I've not found a way to kill
> the client when I close the stream.  If I simply close the stream, the
> ssh client is left running as a child of the Lispworks image.  When I
> exit Lispworks, the client is orphaned.  I suppose I could track down
> the pid and sigterm it, but that sounds too horrible for words.
> 
> I know its more appropriate to ask Xanalys support, but being in the
> middle of a hack-fest over the weekend, I was hoping someone might be
> able to give me a quick hint.

How about logging out normally if that is possible. Something like sending
^C^D (intr eof) to a unix program/session/shell. If the program run at the
other end (shell in normal login) dies, the connection closes.
From: Greg Menke
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <m3he7jisgj.fsf@europa.pienet>
"Harri Haataja" <·············@cs.helsinki.fi> writes:

> Greg Menke wrote:
> 
> > I'm using open-pipe to fork an ssh client which logs into a remote
> > machine and periodically returns some statistics which my program
> > processes.  That part is working OK, but I've not found a way to kill
> > the client when I close the stream.  If I simply close the stream, the
> > ssh client is left running as a child of the Lispworks image.  When I
> > exit Lispworks, the client is orphaned.  I suppose I could track down
> > the pid and sigterm it, but that sounds too horrible for words.
> > 
> > I know its more appropriate to ask Xanalys support, but being in the
> > middle of a hack-fest over the weekend, I was hoping someone might be
> > able to give me a quick hint.
> 
> How about logging out normally if that is possible. Something like sending
> ^C^D (intr eof) to a unix program/session/shell. If the program run at the
> other end (shell in normal login) dies, the connection closes.

The ssh process is subordinate to the Lispworks process, which is a
CAPI app that spawns off one or more ssh connections that it uses to
collect data.  I have to be able to open and close the connections as
required- its not good enough to leave them orphaned.

I've tried (write-char (code-char 3) ..) followed by a finish-output
which appears to have no effect.

Gregm
From: Nils Goesche
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <87n0hbxj93.fsf@darkstar.cartan>
Greg Menke <··········@toadmail.com> writes:

> "Harri Haataja" <·············@cs.helsinki.fi> writes:
> 
> > How about logging out normally if that is possible. Something
> > like sending ^C^D (intr eof) to a unix
> > program/session/shell. If the program run at the other end
> > (shell in normal login) dies, the connection closes.
> 
> The ssh process is subordinate to the Lispworks process, which
> is a CAPI app that spawns off one or more ssh connections that
> it uses to collect data.  I have to be able to open and close
> the connections as required- its not good enough to leave them
> orphaned.
> 
> I've tried (write-char (code-char 3) ..) followed by a
> finish-output which appears to have no effect.

This seems to work here:

(defun junk ()
  (with-open-stream (s (sys:open-pipe "ssh -T sdf-eu.org" :direction :io))
    (write-line "ls" s)
    (write-line "exit" s)
    (force-output s)
    (loop for line = (read-line s nil) while line do
          (write-line line))))

Can't you do something like that?

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Greg Menke
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <m3smr3ru8v.fsf@europa.pienet>
Nils Goesche <···@cartan.de> writes:

> Greg Menke <··········@toadmail.com> writes:
> 
> > "Harri Haataja" <·············@cs.helsinki.fi> writes:
> > 
> > > How about logging out normally if that is possible. Something
> > > like sending ^C^D (intr eof) to a unix
> > > program/session/shell. If the program run at the other end
> > > (shell in normal login) dies, the connection closes.
> > 
> > The ssh process is subordinate to the Lispworks process, which
> > is a CAPI app that spawns off one or more ssh connections that
> > it uses to collect data.  I have to be able to open and close
> > the connections as required- its not good enough to leave them
> > orphaned.
> > 
> > I've tried (write-char (code-char 3) ..) followed by a
> > finish-output which appears to have no effect.
> 
> This seems to work here:
> 
> (defun junk ()
>   (with-open-stream (s (sys:open-pipe "ssh -T sdf-eu.org" :direction :io))
>     (write-line "ls" s)
>     (write-line "exit" s)
>     (force-output s)
>     (loop for line = (read-line s nil) while line do
>           (write-line line))))
> 
> Can't you do something like that?

I'm using open-pipe to read the output of kstat on a Sun machine.
kstat is run in iterative mode so it generates its output once a
second.  The following is what I invoke in open-pipe;

ssh -x <hostname> "kstat -p <modulename> -i 1"

  If I could find a way to terminate it, then kstat would exit,
ssh would return and everything would be fine.  Sending a ctrl-c char
on a bidirectional pipe doesn't seem to do it.  I don't know a whole
lot about job control in this context.  I'll try the ssh connection
first, then start kstat in a second step.

Gregm
From: Nils Goesche
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <87isrzjcf3.fsf@darkstar.cartan>
Greg Menke <··········@toadmail.com> writes:

> Nils Goesche <···@cartan.de> writes:
> 
> > This seems to work here:
> > 
> > (defun junk ()
> >   (with-open-stream (s (sys:open-pipe "ssh -T sdf-eu.org" :direction :io))
> >     (write-line "ls" s)
> >     (write-line "exit" s)
> >     (force-output s)
> >     (loop for line = (read-line s nil) while line do
> >           (write-line line))))
> > 
> > Can't you do something like that?
> 
> I'm using open-pipe to read the output of kstat on a Sun machine.
> kstat is run in iterative mode so it generates its output once a
> second.  The following is what I invoke in open-pipe;
> 
> ssh -x <hostname> "kstat -p <modulename> -i 1"
> 
>   If I could find a way to terminate it, then kstat would exit,
> ssh would return and everything would be fine.  Sending a
> ctrl-c char on a bidirectional pipe doesn't seem to do it.  I
> don't know a whole lot about job control in this context.  I'll
> try the ssh connection first, then start kstat in a second
> step.

Ok, how about this, then:

(defparameter *junk-stream* nil)

(defun junk ()
  (with-open-stream (s (setq *junk-stream*
                             (sys:open-pipe "ssh -T sdf-eu.org /arpa/c/cartan/bin/kstat"
                                            :direction :io)))
    (loop for line = (read-line s nil) while line do
          (write-line line))))

(defun stop-it ()
  (sys:call-system (format nil "kill ~D" (sys:pipe-pid *junk-stream*))))

Regards,
-- 
Nils G�sche
Ask not for whom the <CONTROL-G> tolls.

PGP key ID #xD26EF2A0
From: Greg Menke
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <m3brxqig9q.fsf@europa.pienet>
Nils Goesche <···@cartan.de> writes:

> Greg Menke <··········@toadmail.com> writes:
> 
> > Nils Goesche <···@cartan.de> writes:
> > ssh -x <hostname> "kstat -p <modulename> -i 1"
> > 
> >   If I could find a way to terminate it, then kstat would exit,
> > ssh would return and everything would be fine.  Sending a
> > ctrl-c char on a bidirectional pipe doesn't seem to do it.  I
> > don't know a whole lot about job control in this context.  I'll
> > try the ssh connection first, then start kstat in a second
> > step.
> 
> Ok, how about this, then:
> 
> (defparameter *junk-stream* nil)
> 
> (defun junk ()
>   (with-open-stream (s (setq *junk-stream*
>                              (sys:open-pipe "ssh -T sdf-eu.org /arpa/c/cartan/bin/kstat"
>                                             :direction :io)))
>     (loop for line = (read-line s nil) while line do
>           (write-line line))))
> 
> (defun stop-it ()
>   (sys:call-system (format nil "kill ~D" (sys:pipe-pid *junk-stream*))))
> 


Perfect!  Its a bit Unixy, but it'll do nicely.

Thanks,

Gregm
From: Harri Haataja
Subject: Re: Lispworks open-pipe, terminating the child process
Date: 
Message-ID: <pan.2003.05.25.23.24.52.94443@cs.helsinki.fi>
Nils Goesche wrote:
> Greg Menke <··········@toadmail.com> writes:
>> 
>> I'm using open-pipe to read the output of kstat on a Sun machine. kstat
>> is run in iterative mode so it generates its output once a second.  The
>> following is what I invoke in open-pipe;
>> 
>> ssh -x <hostname> "kstat -p <modulename> -i 1"
>> 
>>   If I could find a way to terminate it, then kstat would exit,
>> ssh would return and everything would be fine.  Sending a ctrl-c char
>> on a bidirectional pipe doesn't seem to do it.  I don't know a whole
>> lot about job control in this context.  I'll try the ssh connection
>> first, then start kstat in a second step.

Some ssh clients (at least openssh) also accept cu-style commands, so
sending ~. after an enter/lf causes ssh itself to quit.

Try ~? in aninteractive session for a brief help.

Not sure if you can use this either, but there's yet another idea.