Re: Implementing Time-outs in IDL [message #7703] |
Sat, 04 January 1997 00:00 |
Phil Williams
Messages: 78 Registered: April 1996
|
Member |
|
|
Steve wrote:
> If the daemon server is off-line the spawn command hangs. Is there a way
> in IDL to cause a command to time-out? I would like my program to continue
> executing if the spawn command does not return a result in X seconds.
>
> Thanks, Steve
Why not first run spawn to ping the machine or check the active
processes for the daemon. Here's checkhost which will check to see if a
host is awake.
function checkhost, host, packets
; Uses spawn to ping host to check to see status. Tested w/ IRIX5.3
; results will need to be parsed differently on different systems.
; The results from ping -q -c packets host:
; PING www6.yahoo.com (204.71.177.71): 56 data bytes
;
;
; ----www6.yahoo.com PING Statistics----
; 10 packets transmitted, 10 packets received, 0% packet loss
; round-trip min/avg/max = 83/84/85 ms
;
; IDL> print,checkhost('www.yahoo.com')
; 1
on_error, 1
if n_elements(packets) eq 0 then packets = 10
;--- spawn a ping to check the host status
cmd = "ping -q -c " + strtrim(packets,2) + " " +host
spawn,["/bin/sh", "-c", cmd],/noshell,results
;--- Get info line for packets transmitted / received
which = strpos(results, 'packets')
found = where(which ne -1, count)
if count eq 0 then message, 'No ping info found for '+host
info = results(found(0))
;--- Now parse the info string
comma = strpos(info, ',')
transString = strmid(info,0,comma(0))
info = strmid(info,comma(0)+1,strlen(info))
comma = strpos(info, ',')
receivedString = strmid(info,0,comma(0))
percentString = strmid(info,comma(0)+1,strlen(info))
;--- Decide whether host is alive on the percent
p = strpos(percentString, '%')
percent = fix(strmid(percentString, 0, p))
if percent gt 10 then return, 0 else return, 1
end
--
/*********************************************************** ********/
Phil Williams, Ph.D.
Research Instructor
Children's Hospital Medical Center "One man gathers what
Imaging Research Center another man spills..."
3333 Burnet Ave. -The Grateful Dead
Cincinnati, OH 45229
email: williams@irc.chmcc.org
URL: http://scuttle.chmcc.org/~williams/
/*********************************************************** ********/
|
|
|
Re: Implementing Time-outs in IDL [message #7704 is a reply to message #7703] |
Sat, 04 January 1997 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
In article <XXX-0301972303470001@biad27.uthscsa.edu>, XXX (Steve) writes:
|> If the daemon server is off-line the spawn command hangs. Is there a way
|> in IDL to cause a command to time-out? I would like my program to continue
|> executing if the spawn command does not return a result in X seconds.
Probably the best thing would be to rewrite your spawned command so that
you can start it in the background, piping the results to a file for
retrieval by IDL. I.e.,
spawn,"daemon > daemon.out &"
wait,10
<read file daemon.out>
Stein Vidar H. Haugan
|
|
|