Signals

This is a discussion on Signals within the C Programming forums, part of the General Programming Boards category; I am trying to work out how to detect a ctrl c, if the ctrl c is detected in the ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 08: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, 01:04 AM
  3. advanced c-programming pipes, signals..
    By bandersen in forum C Programming
    Replies: 2
    Last Post: 02-23-2003, 09:19 AM
  4. keyboard capturing
    By xlnk in forum Linux Programming
    Replies: 4
    Last Post: 01-31-2003, 12:02 PM
  5. queued signals problem, C programming related
    By Unregistered in forum Linux Programming
    Replies: 3
    Last Post: 01-21-2002, 11:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21