chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] question about signal handler


From: Valentyn Kamyshenko
Subject: Re: [Chicken-users] question about signal handler
Date: Sun, 06 Oct 2002 15:56:27 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Felix:

Thank you for the answer.

The program was just an illustration (with "sleep" being just the simplest case). What I really needed was to be able to stop child process and make some cleanup when the parent receives the signal. The straightforward analog of the code below written in C works as expected. In Scheme, I tried also to kill the child explicitely by PID from the signal handler - does not work. My impression is that signal handling is delayed somehow untill the child process finishes.

felix wrote:

Hello,

it appears that on my system the signal handling is performing in a
very strange way.

In my understanding, the program below, being compiled and started,
should print "hello" and exit when I send it the SIGHUP signal. It
does not. Instead, it prints "hello" when the "sleep" is finished
(either after 30 secs or being killed). I tried also
process-run/process-wait combination - with a similar result.

Will be very appreciated for your help.

OS:          various x86 Linux'es
Compilation: csc -o signal_test signal_test.scm

;===== signal_test.scm ======
(declare (uses posix)
       (interrupts-enabled))
(set-signal-handler! signal/hup (lambda (s) (display "hello\n") (exit)))
(system "sleep 30")
;============================



The problem here is that, by evaluating (system "sleep 30"), you
dont't really send the current process to sleep, but a different
one (spawned by the shell). You can see this is you enter
"signal_test &" at the shell and look at the list of running processes
with "ps". To make your code work, you have to invoke the `sleep'
function directly:

(define sleep (foreign-lambda int "sleep" int))

(sleep 30)

(The newest CVS version of Chicken has `sleep()' (posix library unit))


cheers,
felix










reply via email to

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