[ILUG] Signal handling thing
Jason Corcoran.
jason at jcorcoran.net
Wed Jun 26 11:08:07 IST 2002
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The code work's fine for me ( Redhat 7.3)
Jason.
On Wed 26 Jun 2002 10:57, David Neary wrote:
> Hi all,
>
> This is kind of puzzling me - I'm sure I've done stuff similar to
> this a million tomes, but I'm having trouble getting this
> working. Can anyone see what I'm doing wrong here?
>
> Basically I'm expecting signal 42 (MYSIG) to be raised an
> indefinite number of times, until I raise SIGINT in the usual
> manner. But I'm getting a system "Real-time signal 10" message,
> and the program exits, after the first call (presumably, when my
> sign-handler's called a second time). Any idea why? Something
> idiotic I'm missing?
>
> Cheers,
> Dave.
>
> ------- test_signal.c ------------
>
> #include <signal.h> /* Signal stuff */
> #include <stdlib.h> /* exit() */
> #include <errno.h>
> #include <stdio.h> /* fprintf() */
>
> enum custom_sigs{
> MY_SIG=42
> }; /* Name signals - just out of habit. */
>
> void custom_signal(int sig)
> {
> fprintf(stderr, "My signal got raised. It's signal number %d.\n", sig);
> }
>
> void interrupt(int sig)
> {
> fprintf(stderr, "Received a SIGINT signal - quitting\n");
> exit(0);
> }
>
> int main(void)
> {
> if(signal(SIGINT, interrupt) == SIG_ERR)
> {
> perror("Signal attach failed!!!\n");
> exit(1);
> }
>
> if(signal(MY_SIG, custom_signal) == SIG_ERR)
> {
> perror("Custom signal attach failed!!!\n");
> exit(1);
> }
>
> while(1)
> raise(MY_SIG); /* To break the loop, interrupt (Ctrl-C) */
>
> return 0;
> }
>
> ------- EOF -----------
- --
regards,
Jason
____________________________
Jason Corcoran.
email : Jason at Jcorcoran.net
WWW: http://www.jcorcoran.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE9GYqbhK52UnYOJxARAkAZAKCsbIljFQvo+y5tFUAoMeoyH1e7dACfdWhf
WoDPTT+heCx+iIFjPUf43/U=
=sFHG
-----END PGP SIGNATURE-----
________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs SkyScan
service. For more information on a proactive anti-virus service working
around the clock, around the globe, visit http://www.messagelabs.com
________________________________________________________________________
More information about the ILUG
mailing list