Sorry I haven't looked at this, but
my motto is don't use signal, use sigaction
for many reasons.
Padraig.
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 -----------
>
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!