[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


signal

Set signal handling

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <signal.h>
void (*signal(int sig, void (*func)(int)))(int);
Parameters:

Parameters for this facility are:

sig  
int  
A number associated with the signal handling function  
func  
void *  
A pointer to a signal handling function  

Remarks:

The signal() function returns a pointer to a signal handling routine that takes an int value argument.

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".

When it is raised, a signal handler's execution is preceded by the invocation of signal(sig, SIG_DFL). This call to signal() effectively disables the user's handler. It can be reinstalled by placing a call within the user handler to signal() with the user's handler as its function argument.

Return:

signal() returns a pointer to the signal handling function set by the last call to signal() for signal sig. If the request cannot be honored, signal() returns SIG_ERR.

See Also:

"raise"

"abort"

"atexit"

"exit"

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