473,326 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Signal handling in C++

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?
Oct 14 '05 #1
1 6799
E.T. Grey wrote:
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?"

Oct 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lionel van den Berg | last post by:
Hi all, I'm trying to do some signal handling using the csignal library but I can't find and specific examples for C++. The signal function as defined in C takes a parameter that is the signal...
2
by: lpw | last post by:
I have dilligently reviewed FAQ-lite Section 3.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." The only...
3
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/...
4
by: Eric Boutin | last post by:
Hi ! currently reading C docs, I think I'm reading docs about the stdc lib, but I'm not shure.. it talks about signals, does *all* OS implement the signal function, and use it well ? I mean.. I...
7
by: Stanley S | last post by:
Hi, Are Signal Handling part of ANSI C? I am not able to find any reference of Sig Handling in Stephen Prata's "C Primer Plus". The usage of signals is to trap errors I guess. (It looks...
10
by: subramanian | last post by:
Consider the following code: segment violation is deliberately generated to catch the SIGSEGV signal. The handler for this signal, namely SIGSEGV_handler, is called. However after the handler is...
2
by: hg | last post by:
Hi, I posted an equivalent question earlier ... but am still not sure: I currently (under Linux) have a program that uses Queue.put (raw_input('')) in a signal handler and Queue.get() in the...
3
by: vijay.db | last post by:
Hi Group, Running DB2 V8.2 Fxpack 9 in AIX 5.2, I get the following error frequently and my instance is stopped...collected some info like: the signal received is 11 which is SEGMENTATION...
1
by: 32Alpha | last post by:
Hi, first post here. First off, this IS a homework assignment for an operating systems class, but the question isn't "how do i do the assignment" but "why is my particular implementation not...
0
by: Marcin Krol | last post by:
Right, I didn't realize before that Python interpreter has its own signal handling routines. Now I am able to handle signals in Python code, but it still barfs on exit: import time import...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.