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
we are registering for, and a second parameter that is the function to call.
What I want to do is specify the function to call as a function of an
instance of "this" class e.g.
void Class::signalHa ndler( int signal ){}
void Class::someFunc tion( ) {
signal( SIGINT, this.signalHand ler );
}
Obviously this is wrong because it complains about signalHandler not
being a type.
How do I achieve this in C++? Can I achieve this in C++?
Thanks,
Lionel. 2 3936
* Lionel van den Berg: 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 we are registering for, and a second parameter that is the function to call.
What I want to do is specify the function to call as a function of an instance of "this" class e.g.
void Class::signalHa ndler( int signal ){}
void Class::someFunc tion( ) { signal( SIGINT, this.signalHand ler ); }
Obviously this is wrong because it complains about signalHandler not being a type.
How do I achieve this in C++? Can I achieve this in C++?
You don't. 'signal' is generally incompatible with C++. AFAIK the only
things you can reliably do in a handler are (1) to terminate, (2) to do
nothing, or (3) set a global flag of type 'volatile sig_atomic_t', and the
standard notes in particular that a signal handler using exception handling
is likely to have problems.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
> Obviously this is wrong because it complains about signalHandler not being a type.
How do I achieve this in C++?
You can't register member functions as a signal handler. Obviously so,
because "this" points to a specific instance of your class with its
associated class data. When your signal is raised, how does it know what
"this" to supply?
class member functions and function pointers are incompatibile.
What you can register is a static class function, because a static class
function is not tied to any specific instance of a class.
static class functions and function pointers can be compatible.
Stephen Howe This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 suggestion on how to deliver
a signal to an object is to do it via a global variable and a wrapper
function, a technique that is generally a Bad Idea (due to the usage of a
global variable). I understand that this ng is dedicated to the discussion
of...
|
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.*/
signal(SIGINT,crash);
signal(SIGBUS,crash);
signal(SIGSEGV,crash);
This part works. Those signals cause the "crash.c" module to
run and get rid of the lock. Is there a standard way to also print
|
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 know Unixes do it, but what
about windows ? does it implements all SIG* signal promptly ?
Thanks !
-Eric Boutin
|
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 similiar to
the concept of try-catch to me.) It seems to relate more to nix OS. Are
signals handling part of Windows too?
|
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
finished, control does not return to the printf statement in main()
which is present after the strcpy statement. Instead Segmentation
violation error message is printed in Redhat Linux and the program is
aborted. In VC++, the SIGSEGV_handler is...
| |
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 main/only thread.
It works but I want to know if it is legal / what type of synchro API I have
the right to use in a signal handler.
|
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 VIOLATION ERROR...after
that I'm getting the entry as DIA0505I Execution of a component signal
handling function has begun, so my query is what does the DIA05051
actally mean..
My diag log entry is as follows:
|
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 working".
I've searched the forums here, but could not find anything particular to my problem, Googling and the linux manual pages haven't been much help either.
What the program is supposed to do is create a very simple shell (that sits atop the...
|
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 signal
import sys
def userBreak(sigNum, execFrame):
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |