Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-12-2004, 12:54 AM   #1
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,168

Rep: Reputation: 45
catching signals

Hi...there do u know how is it possible to handle some signals in my programs in Linux?

I have a ncurse based application and i want when a user press the ctrl+c the application shows an appropriate message....
Do u have som links for starting reading?
Old 07-12-2004, 02:13 AM   #2
Registered: Nov 2003
Posts: 35

Rep: Reputation: 15
Use the 'signal' system call.

signal(sighandler, signalname);

sighandler is the function that should be invoked when ur process recieves the function signal name. but remember to write sighandler without () i.e., don't write it as,

signal(sighandler(), signalname);

cos signal expects a function pointer. except SIGKILL, all the signals can be caught. read "unix network programming" by richard stevens for details.
Old 07-12-2004, 09:57 AM   #3
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
Here's an example:
#include <stdio.h>
#include <signal.h>

void sigint_handler(int num)
  puts("You pressed CTRL-c!");

int main(void)
  signal(SIGINT, sigint_handler);


  return 0;
Just run the program and hit ENTER to exit it. Before you hit enter try hitting CTRL-c a few times.
Old 11-16-2007, 06:05 AM   #4
Registered: Nov 2007
Posts: 31

Rep: Reputation: 15
It would be better to use sigaction.
struct sigaction sig1;
sig1.sa_handler = mysigaction // mysigaction is a function
sigaction(SIGALRM,&sig1,NULL); //execute mysigaction() when SIGALRM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
catching a keypress on X MD3 Programming 0 02-14-2005 03:07 PM
Bash signal catching meblost Programming 3 11-22-2004 08:38 PM
Catching a Hacker... Shr00mBoXx Linux - Security 14 06-30-2004 10:59 PM
Catching first letter. TheRealDeal Linux - General 1 03-28-2004 09:50 PM
Catching a signal? kalleanka Programming 6 02-12-2004 10:44 AM

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration