sorry about the terse code snippet.... 

Basically, I have an SSH tunnel that is controlled by another
process and I want to tell when that ssh tunnel is closed.

(I have both the PID for this SSH tunnel process and the port #
of the local side of the tunnel)

I am checking for closed tunnels 2 ways:

1)  if the process is <defunct> 

(i realize that the code I wrote doesnt quite illustrate 
  this 2nd part... sorry)

2)  if netstat -an | grep localhost:(port#) shows no
    output, then I know that the localhost port is no longer
    listening, hence the tunnel is closed.

I guess my question is 2 part:  

1) Id like to know if theres a better way to do this
2) Is it really horribly expensive to do this with sys calls?




-----Original Message-----
From: Kipp, James [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 29, 2001 9:52 AM
To: 'Matt Weatherford'; [EMAIL PROTECTED]
Subject: RE: System calls in perl for "ps" and "netstat" - less
expensive way?


Hi Matt

Can you describe a little bit what U are trying to do or include more  of
the code. Depending on what U are trying to do, there may be less expensive
alternatives

Thanks
Jim
>
> 
> 
> 
> From PERL, I have been doing some system calls like this:
> (see * lines) 
> 
> 
> *  my $procentry=`ps -ef | grep -v grep | grep $self->{pid} `;
>   chomp $procentry;
> 
>   $self->debug(1, "Procentry: [$procentry]");
>     if ($procentry =~ /\<defunct\>/ ) {
>        $self->debug(1, " <--- closed ssh tunnel. Tunnel proc 
> defunct");
>        $tunnelok=0;
>     }
> 
> *  my $nstat=`netstat -an | grep '127.0.0.1' `;
>   chomp $nstat;
> 
>   $self->debug(1, "NStat: [$nstat]");
>     if (!$nstat) {
>        $self->debug(1, " <--- closed ssh tunnel. Netstat 
> result empty");
>        $tunnelok=0;
>     }
> 
> 
> Is this really computationally expensive?
> (I already know this makes my code not portable)
> 
> Im not calling these very often, is there a better way to do this?
> 
> thanks,
> 
> Matt
> 

Reply via email to