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