Thread: Signals

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    21

    Cool Signals

    I am trying to work out how to detect a ctrl c, if the ctrl c is detected in the child the child of the parent will exit and return to the parent currently running a command line. I have tried to use signal handlers, but need some help.

    Much help will be much appreciated.

    --
    Thanks
    it01y2

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    26
    Trace the SIGINT signal by writing the signal handler.
    Example
    --------
    Code:
    void sig_handler()
    {
     --- /*handling SIGINT*/
     ---
    }
    int main()
    {
     signal(SIGINT,sig_handler);/*Call the function sig_handler whenever ctrl-c get pressed.*/
    .
    .
    .
    }
    Last edited by kiruthika; 02-22-2010 at 09:59 PM.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    37
    The signal function is used to catch the signal. And by that u can change the behaviour of the signal by your own functions. When you are giving ctrl+c at that time interrupt signal will be generated. That is SIGINT. when this signal is caught you may wish to do some actions. Have those actions in a function and you can use like follows

    signal (SIGINT, signal_handler_function);

    Note: include the header file signal.h in your code.
    Thanks!

  5. #5
    Registered User
    Join Date
    Nov 2008
    Location
    INDIA
    Posts
    64

    sigaction

    signal function is for just handle the signal.If you want to play with signals use sigaction system call.

    man sigaction

    It has some special flags to use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question about signals handling
    By smoking81 in forum Linux Programming
    Replies: 10
    Last Post: 10-01-2008, 03:38 PM
  2. kill & stop signals
    By ssharish2005 in forum C Programming
    Replies: 6
    Last Post: 02-18-2008, 02:04 AM
  3. advanced c-programming pipes, signals..
    By bandersen in forum C Programming
    Replies: 2
    Last Post: 02-23-2003, 10:19 AM
  4. keyboard capturing
    By xlnk in forum Linux Programming
    Replies: 4
    Last Post: 01-31-2003, 01:02 PM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-22-2002, 12:30 AM