This function is compatible with the following targets:
|
|
#include <signal.h>
void (*signal(int sig, void (*func)(int)))(int);Parameters:
Parameters for this facility are:
The sig argument is the signal number associated with the signal handling function. The signals defined in signal.h are listed in "signal.h Signal descriptions".
The func argument is the signal handling function. This function is either programmer-supplied or one of the pre-defined signal handlers described in "Signal function handling arguments".
Return: See Also:Example of signal() usage:#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void userhandler(int);
void userhandler(int sig)
{
char c;
printf("userhandler!\nPress return.\n");
/* wait for the return key to be pressed */
c = getchar();
}
int main(void)
{
void (*handlerptr)(int);
int i;
handlerptr = signal(SIGINT, userhandler);
if (handlerptr == SIG_ERR)
printf("Can't assign signal handler.\n");
for (i = 0; i < 10; i++) {
printf("%d\n", i);
if (i == 5) raise(SIGINT);
}
return 0;
}
Output:
0
1
2
3
4
5
userhandler!
Press return.
6
7
8
9
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000