signal

Installs/removes a signal handler.

Available in:

Apps (win) Apps (char) Reportwriter RPC Standalone PL
X X X X X

Syntax

void signal(signal[,trigger])
int         signal
code        trigger

Description

Installs or removes a signal handler. If no trigger parameter is given, then any existing signal handler for that signal is removed. If trigger is given, then it will be excuted whenever the process receives a signal interrupt. This function is similar to its POSIX counterpart.
signal specifies the signal number.

trigger (optional) specifies the code to execute when the signal is received.

Notes

By using escape() in the trigger code, you can exit any wait state that you may be in.

Example

{
int     i,j;
trigger t1 = { printf("Signal caught/escaping"); escape(); };
trigger t2 = { printf("Signal caught/returning"); };

i = to_int(prompt("Enter signum: "));

/*****************************************************************************/
/* Set the handler.                                                          */
/*****************************************************************************/
for (j=0;j<3;j++) {
  if (trap({
     signal(i,t1);
     prompt("Let's wait (" ^^ j ^^ ") escape ... ");
     }));
  }

/*****************************************************************************/
/* If you get the signal now, the process will exit.                         */
/*****************************************************************************/
signal(i);
prompt("Let's wait ... no signal handler");

/*****************************************************************************/
/* Set the handler.                                                          */
/*****************************************************************************/
signal(i,t2);

for (j=0;j<3;j++) {
  prompt("Let's wait (" ^^ j ^^ ") return ... ");
  }

printf("All done");
}