Re: occasional checking process is alive

From: Erick Gallesio <Erick.Gallesio_at_unice.fr>
Date: Thu, 16 Sep 1999 22:08:47 +0200 (CEST)

Paul.Emsley_at_chem.gla.ac.uk writes:

> Please excuse this newbie question:

No problem
>
> Preamble:
> I have a simple-minded STk GUI which creates input for a
> process. When the data are in an appropriate form, the STk
> program writes it to a file and starts a subprocess (which may
> or may not fail horribly).
>
> What I would like to do is every-so-often check to see if the
> process is still alive (pressumbably using (process-alive?
> *process-num*)). If it is not then do some action (such as
> (my-popup "Job terminated")). It would be good if I could check
> the exit status of the program and I could change the popup
> message appropriately. I'm guessing I need some sort of (after
> ..) or (tkwait ..) thing - but I don't see how to do it...
>
Yes you can do this using a procedure which re-launch itself if
the process is not terminated. Something like the following code
should do the job.

     (require "process")

     (define (check-process p)
       (format #t "Checking process ~S\n" p)
       (if (process-alive? p)
           (after 1000 (lambda () (check-process p)))
           ;; Process has finished
           (let ((status (process-exit-status p)))
             (format #t "Process exit with status ~S\n" status))))

     (define p (run-process "emacs"))
     (check-process p)


Hope it helps.



                -- Erick
Received on Thu Sep 16 1999 - 22:27:03 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST