chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Wierd behaviour of process.


From: Graham Fawcett
Subject: Re: [Chicken-users] Wierd behaviour of process.
Date: Mon, 15 Jan 2007 13:29:39 -0500

On 1/14/07, Robin Lee Powell <address@hidden> wrote:
That made me think that doing a "wait" on the process *is* behaviour
I want, and I should do that.  However, process-wait throws an error
if the process has already exited, and I can't seem to trap it.  I
tried:
(condition-case (process-wait pid) (var () #t))
and
(with-exception-handler (lambda (x) #f) (lambda () (process-wait
pid)))
But in both cases it just errors out with:
Error: (process-wait) waiting for child process failed - No child
processes: 21505

You could define a variant of process-wait that throws no errors.
Perhaps it might help you to debug the problem. Here's the current
definition, from posixunix.scm:

 (define process-wait
   (lambda args
     (let-optionals* args ([pid #f] [nohang #f])
       (let ([pid (or pid -1)])
         (##sys#check-exact pid 'process-wait)
         (receive [epid enorm ecode] (##sys#process-wait pid nohang)
           (if (fx= epid -1)
               (posix-error #:process-error 'process-wait "waiting
for child process failed" pid)
               (values epid enorm ecode) ) ) ) ) ) )

(Note that ##sys#process-wait is defined in the same file.) You could
add a version that returns three #f values in the case of a failed
wait, instead of raising an error:

(define process-wait*
   (lambda args
     (let-optionals* args ([pid #f] [nohang #f])
       (let ([pid (or pid -1)])
         (##sys#check-exact pid 'process-wait)
         (receive [epid enorm ecode] (##sys#process-wait pid nohang)
           (if (fx= epid -1)
               (values #f #f #f)
               (values epid enorm ecode) ) ) ) ) ) )

A rigged demo:

#; 3> (process-wait 2)
Error: (process-wait) waiting for child process failed - No child processes: 2

#; 4> (process-wait* 2)
#f
#f
#f

You can't just drop this in an egg, though; the definintion of
##sys#process-wait is not public, and your compile will fail. Add it
to posixuinx.scm in your Chicken source tree, and then rebuild and
reinstall Chicken. That's a bit extreme, I suppose. :-) But perhaps a
build-guru on the list has a way to build this as a normal extension.

-- Graham




reply via email to

[Prev in Thread] Current Thread [Next in Thread]