Download SICStus Prolog User`s Manual
Transcript
Chapter 9: Mixing C and Prolog
243
typedef void SP_SigFun (int);
SP_SigFun SP_signal (int sig, SP_SigFun fun);
SP_signal returns SP_SIG_ERR on error. On success, SP_signal returns some unspecified
value different from SP_SIG_ERR.
If fun is one of the special constants SP_SIG_IGN or SP_SIG_DFL, then one of two things
happens. If a signal handler for sig has already been installed with SP_signal, then the
SICStus OS-level signal handler is removed and replaced with, respectively, SIG_IGN or
SIG_DFL. If a signal handler has not been installed with SP_signal, then SP_signal does
nothing and returns SP_SIG_ERR.
A signal handler installed by a foreign resource should be uninstalled in the deinit function
for the foreign resource. This is to prevent the handler in the foreign resource from being
called after the code of the foreign resource has been unloaded (e.g. by unload_foreign_
resource/1).
The following two functions were used prior to SICStus 3., but are obsolete now:
SP_SigFun SP_reinstall_signal (int sig, SP_SigFun)
void SP_continue(void)
[Obsolescent]
[Obsolescent]
they are no-ops.
The following piece of C code illustrates these facilities. The function signal_init() installs the function signal_handler() as the primary signal handler for the signals SIGUSR1
and SIGUSR2. That function invokes the predicate user:prolog_handler/1 as the actual
signal handler, passing the signal number as an argument to the predicate.
SP_pred_ref event_pred;
static int signal_event(void *handle)
{
int signal_no = (int) handle;
SP_term_ref x=SP_new_term_ref();
int rc;
SP_put_integer(x, signal_no); /* Should not give an error */
rc = SP_query(event_pred, x);
if (rc == SP_ERROR && SP_exception_term(x))
SP_raise_exception(x);
/* Propagate any raised exception */
return rc;
}
static void signal_handler(int signal_no)
{
SP_event(signal_event, (void *)signal_no);
/* The two calls below are for SICStus 3.8 compatibility */
Related documents
SICStus Prolog User`s Manual
SICStus Prolog User`s Manual
SICStus Prolog User`s Manual
Barry's Prolog Reference Manual & User Guide
Tilburg University ConceptBase.cc User Manual
WCX Series XYR 6000 Valve Position Sensor
User manual
SICStus Prolog User's Manual
A user's guide to functional diversity indices
Sec - SICStus Prolog 3
Wheeled Stair Climber N 911 - 912 - 913 YACK instruction
section “Command line editing” in the SICStus Prolog Release Notes