thanks, But I was talking about kernel code.
From: ÀÓ±Ù½Ä <invain@xxxxxxxxx>
To: "Talib Alim" <talibalm@xxxxxxxxxxx>,<kernelnewbies@xxxxxxxxxxxx>
Subject: Re: signal handling
Date: Sat, 13 May 2006 10:04:23 +0900
type "#> kill -l [enter]" , you can see many signals list.
and, diesire to reference belows. for signal understanding.
ctrl + c ======> SIGINT
ctrl + z ======> SIGTSTOP
--" #> gcc -o signal.o signal.c
"------------------------------------------------------------
#include <stdio.h> /* standard I/O functions */
#include <unistd.h> /* standard unix functions, like getpid() */
#include <signal.h> /* signal name macros, and the signal() prototype */
/* first, define the Ctrl-C counter, initialize it with zero. */
int ctrl_c_count = 0;
#define CTRL_C_THRESHOLD 5
/* the Ctrl-C signal handler */
void catch_int(int sig_num)
{
sigset_t mask_set; /* used to set a signal masking set. */
sigset_t old_set; /* used to store the old mask set. */
/* re-set the signal handler again to catch_int, for next time */
signal(SIGINT, catch_int);
/* mask any further signals while we're inside the handler. */
sigfillset(&mask_set);
sigprocmask(SIG_SETMASK, &mask_set, &old_set);
/* increase count, and check if threshold was reached */
ctrl_c_count++;
if (ctrl_c_count >= CTRL_C_THRESHOLD) {
char answer[30];
/* prompt the user to tell us if to really exit or not */
printf("\nRealy Exit? [y/N]: ");
fflush(stdout);
gets(answer);
if (answer[0] == 'y' || answer[0] == 'Y') {
printf("\nExiting...\n");
fflush(stdout);
exit(0);
}
else {
printf("\nContinuing\n");
fflush(stdout);
/* reset Ctrl-C counter */
ctrl_c_count = 0;
}
}
/* restore the old signal mask */
sigprocmask(SIG_SETMASK, &old_set, NULL);
}
/* the Ctrl-Z signal handler */
void catch_suspend(int sig_num)
{
sigset_t mask_set; /* used to set a signal masking set. */
sigset_t old_set; /* used to store the old mask set. */
/* re-set the signal handler again to catch_suspend, for next time */
signal(SIGTSTP, catch_suspend);
/* mask any further signals while we're inside the handler. */
sigfillset(&mask_set);
sigprocmask(SIG_SETMASK, &mask_set, &old_set);
/* print the current Ctrl-C counter */
printf("\n\nSo far, '%d' Ctrl-C presses were counted\n\n",
ctrl_c_count);
fflush(stdout);
/* restore the old signal mask */
sigprocmask(SIG_SETMASK, &old_set, NULL);
}
int main(int argc, char* argv[])
{
/* set the Ctrl-C and Ctrl-Z signal handlers */
signal(SIGINT, catch_int);
signal(SIGTSTP, catch_suspend);
/* enter an infinite loop of waiting for signals */
for ( ;; )
pause();
return 0;
}
----------------------------------------------------------------
----- Original Message -----
From: "Talib Alim" <talibalm@xxxxxxxxxxx>
To: <kernelnewbies@xxxxxxxxxxxx>
Sent: Saturday, May 13, 2006 2:20 AM
Subject: signal handling
> Some of the functions in my kernel module can sleep, for these functions
I
> have following code
>
> if (signal_pending(current))
> {
> set_current_state(TASK_RUNNING);
> *errno = EINTR;
> return(something);
> }
>
> The problem is that even if I do ctrl-Z on the key board, abouve code
> returns and user process stops.
>
> What is the correct way of handling this ? should I check for specified
> signals, e.g. man 7 signal says that following signal should kill the
> process and some of them shuold also do core
>
> SIGHUP
> SIGINT
> SIGQUIT
> SIGILL
> SIGABRT
> SIGFPE
> SIGKILL
> SIGSEGV
> SIGPIPE
> SIGALRM
> SIGTERM
> SIGUSR1
> SIGUSR2
>
> _________________________________________________________________
> Don?t just search. Find. Check out the new MSN Search!
> http://search.msn.click-url.com/go/onm00200636ave/direct/01/
>
>
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive: http://mail.nl.linux.org/kernelnewbies/
> FAQ: http://kernelnewbies.org/faq/
>
>
>
>
>
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/