Signal handling in C++

E

E.T. Grey

Hi,

I am trying to handle signals (SIGTERM, SIGILL and SIGABRT) in my C++ code.

I have member functions defined as follows:

/* Hack to allow signal handling */
void BaseProcess::proc_death_catcher( int not_used ) {
proc_terminate() ;
}


In my initialization code for class BaseProcess, I set up the handlers
as follows:

signal(SIGTERM, proc_death_catcher);
signal(SIGILL, proc_death_catcher);
signal(SIGABRT, proc_death_catcher);


When I compile the code, I get the following error:

error C2664: 'signal' : cannot convert parameter 2 from 'void (int)' to
'void (__cdecl *)(int)'


The error appears to suggests that the calling convention is different
from what was expected.

If this inference is correct, it leads to a number of other questions:

1). What is the recommended way (i.e. best practise) to call a C
callback function from a class?

2). Do different instances of the class call into the same code (ala
static method) - or is the same copy of the callback used for all
instances of the class?

3). Is the answer to question 2 was that the same copy is used - then
this approach (calling C callbacks from C++ classes) is likely to be
thread *unsafe*. True?
 
R

Rolf Magnus

E.T. Grey said:
1). What is the recommended way (i.e. best practise) to call a C
callback function from a class?

See the FAQ to this newsgroup. Look at section 33 and especially question
33.2 "How do I pass a pointer-to-member-function to a signal handler, X
event callback, system call that starts a thread/task, etc?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top