Hi all,
In my current project I am using signals for error handling. Since I
cannot show full code, I have just shown important piece of code which
is relevant.
void sigsegenv()
{
printf("\n\n ********** F D S Message ***********\n\n");
printf("\n\n ********** S E G M E N T A T I O N F A U L T
inside F D S ***********\n\n");
exit(-1);
}
int main(void)
{
............
...........
signal ( SIGSEGV ,sigsegenv);
...........
...........
}
I think this might give some idea about what is happening.
My signal handler is not catching SIGSEGV always. Some time it is
catching sometimes not. Please let me know what am I doing wrong 13 17557
In article <11**********************@o13g2000cwo.googlegroups .com>,
<va******@rediffmail.com> wrote: In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant.
void sigsegenv() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n"); exit(-1); }
int main(void) { ........... .......... signal ( SIGSEGV ,sigsegenv); .......... .......... }
You cannot use printf() inside a signal handler.
In standard C, other than calling exit, resetting the signal handler,
or a *very* small number of other things, all you can do is set
a volatile variable of sig_atomic_t .
I think this might give some idea about what is happening. My signal handler is not catching SIGSEGV always. Some time it is catching sometimes not. Please let me know what am I doing wrong
What evidence have you found that the handler is not catching SIGSEGV ?
If it is just that the printf() are not occuring, then you might
be encountering the restrictions on what you can do in a handler.
--
All is vanity. -- Ecclesiastes
Walter Roberson wrote: You cannot use printf() inside a signal handler.
In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t .
Could you please tell me about restrictions on signal handlers or where
I can find more info about restrictions on signal handlers?
Thanks,
Madhav.
Madhav said: Walter Roberson wrote: You cannot use printf() inside a signal handler.
In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t . Could you please tell me about restrictions on signal handlers
He just did.
or where I can find more info about restrictions on signal handlers?
That's the whole thing.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
> In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t .
Can I invoke longjmp in signal handler?
Actually, In our project we have to return status to the scheduler(Some
what like scheduler) which will execute our program. The scheduler is
in JAVA. The values I should return is 0 (if everything is fine) or
50(warning, If not a very serious error has occurred) or 99(If some
serious error has occurred like segmentation fault).I was thinking to
use longjmp inside signal handler and jump to main and then return
appropriate error status. What evidence have you found that the handler is not catching SIGSEGV ?
Programming terminated due to segmentation fault. va******@rediffmail.com said: In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t . Can I invoke longjmp in signal handler?
Not with well-defined behaviour, no.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Richard Heathfield wrote: va******@rediffmail.com said:
In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t . Can I invoke longjmp in signal handler?
Not with well-defined behaviour, no.
Is it possible to return certain value to the calling program from
signal handler?My aim is to exit gracefully and to return the
predefined values to the scheduler, which invokes my program.Note that
scheduler is coded using JAVA.
OK, let me put it in a better eay. This is what happens in our project
JAVA progam calls list of C programs. C programs should return the
status(0, 50 or 100) to JAVA. I somehow want to return the status to
JAVA program if there is a segmentation fault. I don't want to exit
from signal handler
.. va******@rediffmail.com said: Richard Heathfield wrote: va******@rediffmail.com said:
>> In standard C, other than calling exit, resetting the signal handler, >> or a *very* small number of other things, all you can do is set >> a volatile variable of sig_atomic_t . >> > Can I invoke longjmp in signal handler?
Not with well-defined behaviour, no. Is it possible to return certain value to the calling program from signal handler?
No. Signal handlers have the form void handler(int); and thus do not return
a value. You can, however, use the signal handler to modify a file scope
object of type sig_atomic_t.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Richard Heathfield wrote: va******@rediffmail.com said:
Richard Heathfield wrote: va******@rediffmail.com said:
> In standard C, other than calling exit, resetting the signal handler, > or a *very* small number of other things, all you can do is set > a volatile variable of sig_atomic_t . > Can I invoke longjmp in signal handler? Not with well-defined behaviour, no. Is it possible to return certain value to the calling program from signal handler?
No. Signal handlers have the form void handler(int); and thus do not return a value. You can, however, use the signal handler to modify a file scope object of type sig_atomic_t.
I think he meant return a value to the program that invoked his C
program, not return a value in to his program. If I read him right, then
calling exit from within the signal handler might be the way to go,
although whether doing exit(99) is valid is system dependant.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Walter Roberson wrote: In article <11**********************@o13g2000cwo.googlegroups .com>, <va******@rediffmail.com> wrote:
In my current project I am using signals for error handling. Since I cannot show full code, I have just shown important piece of code which is relevant.
void sigsegenv() { printf("\n\n ********** F D S Message ***********\n\n"); printf("\n\n ********** S E G M E N T A T I O N F A U L T inside F D S ***********\n\n"); exit(-1); }
int main(void) { ........... .......... signal ( SIGSEGV ,sigsegenv); .......... .......... }
You cannot use printf() inside a signal handler.
In standard C, other than calling exit, resetting the signal handler, or a *very* small number of other things, all you can do is set a volatile variable of sig_atomic_t .
Calling exit() in a signal handler is impermissible.
Perhaps you mean _Exit(), a function introduced in C99;
see 7.14.1.1/5. Handlers for signals that were generated
by raise() or abort() are not subject to these restrictions;
handlers for all other signals must respect them.
--
Eric Sosman es*****@acm-dot-org.invalid va******@rediffmail.com wrote:
# Can I invoke longjmp in signal handler?
Your program is in a fragile state when the signal handler
is called, and it might not be possible to recover and
continue. On some systems, you can run the program in a
separate process; if it fails, it can report failure and
then exit with recovery. The caller monitors the process
and captures the result or error status.
--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD Ma************@web.de wrote: Could you please tell me about restrictions on signal handlers or where I can find more info about restrictions on signal handlers?
Please look at the list of async-signal-safe functions. See section "2.4.3 Signal Actions" from the document " 2.4 Signal Concepts". http://www.opengroup.org/onlinepubs/...l#tag_02_04_03 http://en.wikipedia.org/wiki/Signal_%28computing%29
The above links are Posix, not C. I can't remember the OP saying that
this was only for Posix systems, and if it was then this would be the
wrong group.
A better place to look would be the C standard, a draft of the latest
version being freely available if you search for n1124.pdf.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
> A better place to look would be the C standard, a draft of the latest version being freely available if you search for n1124.pdf. http://www.open-std.org/jtc1/sc22/wg...1997/N1124.pdf
This document (ISO/IEC 9899:TC2 Committee Draft - May 6, 2005
WG14/N1124) contains the following wording.
Page 20, section "5.2.3 Signals and interrupts":
"...
Functions shall be implemented such that they may be interrupted at any
time by a signal, or may be called by a signal handler, or both, with
no alteration to earlier, but still active, invocations' control flow
(after the interruption), function return values, or objects with
automatic storage duration.
...."
Page 167, section "7.1.4 Use of library functions":
"...
The functions in the standard library are not guaranteed to be
reentrant and may modify objects with static storage duration.
....
161) Thus, a signal handler cannot, in general, call standard library
functions.
...."
There are more descriptions about signal handling in the sections 7.14
and 7.26.6. But the term "async-signal-safe function" is not used in
the specification. I suggest to look at other information sources for
better understanding of the topic "async-signal safety".
- Multithreaded Programming Guide http://docs.sun.com/app/docs/doc/816...w#compat-ix626 http://docs.sun.com/app/docs/doc/816...view#gen-ix561
- http://serpentine.com/blog/threads-faq/signals.html
- http://en.wikipedia.org/wiki/Reentrant http://en.wikipedia.org/wiki/SIGSEGV
Regards,
Markus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: rh0dium |
last post by:
Hi all,
I don't understand the signal module. I guess I understand what it
does in principle but I can't figure out how to use it to timeout an
external rsh command after a 5 seconds. Does...
|
by: LeTubs |
last post by:
Hi
I'm not sure if this is correct ...place to post but here goes
This is what i'm trying to do, I want to write a signal / alarm handler
( I don't know which hence the posting here, as once I...
|
by: manochavishal |
last post by:
Why would a signal handler cannot in general call standard library
functions.
I have read whats is said in Standard but needs an explaination on that
as i couldn't uunderstand it.
Thanx in...
|
by: Sven |
last post by:
Hi,
I found a strange behaviour when using the time() function from time.h.
Sometimes when it is called, it does not show the correct time in
seconds, but an initial value. This time seem to be...
|
by: Marco |
last post by:
Hi,
In C, a signal handler function has only one parameter, that is signal number.
But in Python(import signal), a signal handler function has two
parameters, the first is signal number, the...
|
by: stalex |
last post by:
Hi all,
I wrote the following code since I want to try using a decorator to
install signal handler:
## The test.py script
#################
import os
import time
import signal
|
by: comedeyboy19 |
last post by:
Hi!
i am writing a program in C that is a reservation maker. it supposed to ask if you wanna get first class or business class, and rest i have to finish. seats 1-5 are for first class, and seats...
|
by: Udai Kiran |
last post by:
Hi all
Iam having trouble with signal handler. Where will the execution
return after invoking a signal handler when that particular signal is
recieved? will return to the point where we register...
|
by: thagor2008 |
last post by:
Is the behaviour of throwing exceptions in a unix signal handler
defined?
eg:
void sighandler(int sig)
{
... do something
throw myobj;
}
|
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...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |