LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Catch signals C++ (https://www.linuxquestions.org/questions/programming-9/catch-signals-c-159071/)

moyacuba 03-17-2004 03:00 PM

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

Mohsen 03-17-2004 10:37 PM

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;
}


moyacuba 03-18-2004 12:28 PM

Thanx
It solve my problem..:-)


All times are GMT -5. The time now is 02:07 PM.