public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Bharti" <bhartig@sasken.com>
To: linux-kernel@vger.kernel.org
Subject: Re: trapping key press using signals
Date: Fri, 26 May 2006 10:20:59 +0530	[thread overview]
Message-ID: <e561fo$f9p$1@ncc-t.sasken.com> (raw)
In-Reply-To: ds7ggl$jc4$1@ncc-m.sasken.com


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

      parent reply	other threads:[~2006-05-26  4:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='e561fo$f9p$1@ncc-t.sasken.com' \
    --to=bhartig@sasken.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox