public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* trapping key press using signals
@ 2006-02-06 12:47 pdn
  2006-02-06 17:36 ` Ram Gupta
  2006-05-26  4:50 ` Bharti
  0 siblings, 2 replies; 3+ messages in thread
From: pdn @ 2006-02-06 12:47 UTC (permalink / raw)
  To: linux-kernel


Hi,
        How do i catch the signals generated by keypress using signals.



"SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 2005 conducted by the BUSINESS TODAY - Mercer - TNS India"

                           SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: trapping key press using signals
  2006-02-06 12:47 trapping key press using signals pdn
@ 2006-02-06 17:36 ` Ram Gupta
  2006-05-26  4:50 ` Bharti
  1 sibling, 0 replies; 3+ messages in thread
From: Ram Gupta @ 2006-02-06 17:36 UTC (permalink / raw)
  To: pdn; +Cc: linux-kernel

On 2/6/06, pdn <preetham@sasken.com> wrote:
>
> Hi,
>         How do i catch the signals generated by keypress using signals.

Why do you need to catch keypress. Keypress generates interrupts which
are controlled by linux kernel. Then it transmits this character(s) to
the application. Hypothetically it is possible to setup some callback
with kernel so that whenver there is a keypress it handles it & then
invokes the call back. But I doubt if it is done currently.

Regards
Ram Gupta

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: trapping key press using signals
  2006-02-06 12:47 trapping key press using signals pdn
  2006-02-06 17:36 ` Ram Gupta
@ 2006-05-26  4:50 ` Bharti
  1 sibling, 0 replies; 3+ messages in thread
From: Bharti @ 2006-05-26  4:50 UTC (permalink / raw)
  To: linux-kernel


Hi,

       With reference to your question : How to catch signals generated by 
key press using signals i would like to share a piece of code which will 
help you understand  the concept more easily.

There are basically 3 ways to send singnals to Processes:
1.Using the keyboard : Like Ctrl-C , this causes the system to send an INT 
signal (SIGINT) to the running process by default it causes the process to 
immediately  terminate. Another one is Ctrl-Z  (SIGTSTP) which causes the 
process to suspend execution and Ctrl-\ (SIGABRT) which does the same as 
Ctrl-C but gives us some better flexibility.
Here is the piece of code snippet that causes the progeam to print the 
string "Testing Code to understand" when a user presses Ctrl-C:

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<signal.h>
void catch_int(sig_num)
{
   /* re-set the signal handler again to catch_int, for next time*/
signal(SIGINT,catch_int);
printf("Testing Code to understand\n");
fflush(stdout);
}

int main(int argc,char* argv[])
{
/*set the INT (Ctrl-C) signal handler to 'catch_int' */
signal(SIGINT,catch_int);
/*now,lets get into an infinite loop of doing nothing.*/
for(;;)
     pause();
}

The pause() system call causes the process to halt execution, until a signal 
is received. It is suerly  better than a 'busy wait' infinite loop.


2. Sending signals from the command Line: Like Kill
 kill-<signal><PID>
If no signal name or number is specified, by default TERM signal is sent to 
the process.
3. Using Susyem Calls:  This way of generating signals is acheived by using 
Kill system call (normal of sending a signal from one process to another).

Bye,
Bharti.

"pdn" <preetham@sasken.com> wrote in message 
news:ds7ggl$jc4$1@ncc-m.sasken.com...
> Hi,
>        How do i catch the signals generated by keypress using signals.
>
> 



"SASKEN RATED Among THE Top 3 BEST COMPANIES TO WORK FOR IN INDIA - SURVEY 2005 conducted by the BUSINESS TODAY - Mercer - TNS India"

                           SASKEN BUSINESS DISCLAIMER
This message may contain confidential, proprietary or legally Privileged information. In case you are not the original intended Recipient of the message, you must not, directly or indirectly, use, Disclose, distribute, print, or copy any part of this message and you are requested to delete it and inform the sender. Any views expressed in this message are those of the individual sender unless otherwise stated. Nothing contained in this message shall be construed as an offer or acceptance of any offer by Sasken Communication Technologies Limited ("Sasken") unless sent with that express intent and with due authority of Sasken. Sasken has taken enough precautions to prevent the spread of viruses. However the company accepts no liability for any damage caused by any virus transmitted by this email

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-05-26  4:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-06 12:47 trapping key press using signals pdn
2006-02-06 17:36 ` Ram Gupta
2006-05-26  4:50 ` Bharti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox