command-line

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

command-line

Post by newdep »

Hi Lutz,

I dont want to be nagging ;-)

Is it possible to return the SIG_DFL to the ctrlC handler if the
(command-line nil) is activated?

That way a newlisp program can create its own signal-handler by
calling the (signal SIGINT handler) but currently the ctrlC signal handler
of newlisp is in the way it seems...

PS: or im doing something wrong inside newlisp ;)

Regards, Norman.
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

At this moment when (command-line nil) the CtrlC handler will simply return, preventing the application from beeing shut down with CtrlC. If I put SIG_DFL in this case the application would simply exit. I am not sure if that is a good Idea? Shouldn't (command-line nil) preventing this?

Related to your other question, I just finished a timer/alarm handler for newLISP which can be used as timer and also as a simple general signalling faciility for SIGALRM. I have an example for the timer and signal application in the manual of the upcoming 8.5.2 development release on Friday.

But it seems you are specifically interested in customizing the SIGINT handler? Or do you mean signals in general?

Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

Hi Lutz,

timer/alarm! Intresting issue !!!

Actualy im trying to ctach all signals that could
intercept the newlisp program when its running,
but i try it again with that nice timer/alarm handler ;-)
Im currious!

PS: Will the timer/alarm handler be thread based or forked?

Regards, Norman.

PS2: If you are looking for a good Thread library? Small, fast !
here is one that could be intresting for newlisp ->

---
Protothreads are extremely lightweight stackless threads designed for severely memory constrained systems, such as small embedded systems or wireless sensor network nodes. Protothreads provide linear code execution for event-driven systems implemented in C. Protothreads can be used with or without an underlying operating system.

Protothreads provide a blocking context on top of an event-driven system, without the overhead of per-thread stacks. The purpose of protothreads is to implement sequential flow of control without complex state machines or full multi-threading.
---

http://www.sics.se/~adam/pt/

---
-- (define? (Cornflakes))

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Here are the 2 peogram snippetds from the upcoming 8.5.2 with user defined timer/SIGALRM handler, no threads required:

Code: Select all

; define a one-second ticker

(define (ticker) 
    (println (date)) (timer 'ticker 1)) ;

> (ticker)
Tue Apr 12 20:44:48 2005       ; first execution of ticker
ticker                         ; return value from ticker
> Tue Apr 12 20:44:49 2005     ; first timer event
Tue Apr 12 20:44:50 2005       ; second timer event ...
Tue Apr 12 20:44:51 2005
Tue Apr 12 20:44:52 2005
Tue Apr 12 20:44:53 2005
Tue Apr 12 20:44:54 2005
Tue Apr 12 20:44:55 2005
The following shows a threaded application, where the child thread signals to the parent, timer is used without the timeout value using 0.

Code: Select all

#!/usr/bin/newlisp

# signal a parent process

(import "libc.so" "getpid")
(import "libc.so" "kill")

(constant 'SIGALRM  14)

(define (alarm) (println "ring... ring...") (set 'done true))

(timer 'alarm 0)
(set 'parent (getpid))

(fork (begin (sleep 2000) (kill parent SIGALRM)))
(println "started child ...")

; do something until alarm
(while (not done) (sleep 300) (println "."))

(exit)
In the second example the 'timer' function is just used to define a handler for the SIGALRM signal. The application will print 5 or 6 dots then receive the signal , leave the 'while' loop and exit.

Lutz

ps: everything Linux/Unix only

Locked