LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-17-2004, 03:00 PM   #1
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Rep: Reputation: 0
Catch signals C++


I have some books that talk about signals and they reference functions like:

sigaction()
and structs with the same name:
struct sigaction{...}

then I read the man page about signal and i had saw references to functions like:

sighandler_t signal(int signum, sighandler_t handler);

that is on RH 9
but in RH 7 i read:

void (*signal(int signum, void (*sighandler)(int)))(int);

the question:

Who know how to make signal treatments on C++ avoiding those things??
On Perl I can do it... How can I do it in c++??

thanx
moya
 
Old 03-17-2004, 10:37 PM   #2
Mohsen
Member
 
Registered: Feb 2003
Location: Iran
Distribution: Solaris 10
Posts: 201

Rep: Reputation: 30
No problem!
Just put a "void myfunc (int)" as a function pointer in the second place of the fucnction signal.
for example
Code:
void my_sig_handler (int a) {
    printf ("Signal TERMINATE has been handled!\n");
}
/*...*/
int main () {
    signal (SIGINT,  my_sig_handler); /* this line will redirect ctrl+c signal to your function */
    return 0;
}
 
Old 03-18-2004, 12:28 PM   #3
moyacuba
LQ Newbie
 
Registered: Mar 2004
Location: Cuba
Posts: 6

Original Poster
Rep: Reputation: 0
Thanx
It solve my problem..:-)
 
  


Reply


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 signals alaios Programming 3 11-16-2007 05:05 AM
!!! about signals !!! b2na Programming 4 02-04-2005 12:34 AM
!! about signals !!! b2na General 1 01-03-2005 04:37 PM
Signals Speek Programming 2 12-24-2004 04:58 AM
trap signals AMMullan Programming 3 10-19-2003 04:31 PM


All times are GMT -5. The time now is 11:26 PM.

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