473,674 Members | 3,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SIGSEGV Handling

ilikesuresh
47 New Member
Hi,
please any one explain how to handle sigsegv signal with example.....

Thanks
Sep 21 '07 #1
5 7337
ruskalym
65 New Member
Hi!

How would you like to handle it?

Do you want to catch it inside a program you wrote or to catch another program's signal?
Sep 21 '07 #2
ilikesuresh
47 New Member
In the same program i need to catch the signal
Sep 21 '07 #3
ruskalym
65 New Member
Here is a tiny code listing that catches the SIGSEGV signal :

Expand|Select|Wrap|Line Numbers
  1. void my_action(int sig)
  2. {
  3.    printf("Caught signal\n");
  4. }
  5.  
  6. int main()
  7. {
  8.    struct sigaction sa;
  9.  
  10.    memset(&sa, 0, sizeof(struct sigaction));
  11.    sa.sa_handler = my_action;
  12.    sigemptyset(&sa.sa_mask);
  13.    sigaction(SIGSEGV, &sa, NULL);
  14.  
  15.    while (1);
  16.  
  17.    return 0;
  18. }
We first create a sigaction structure and set its handler to my_action.

If a SIGSEGV is caught after the sigaction() call, my_action() will be called.

However, the program will crash or call my_action() in an infinite loop if the SIGSEGV originates from program's memory violation.
Sep 21 '07 #4
janardhan reddy
1 New Member
Hi,

Need assistance regarding SIGSEGV handling.

I tried the above example and suprisingly program enters into infinite loop in signal handler function.

I want the control to come back to main from my_action() api without killing the program. Is it possible ? If possible please send me the answer.

Thanks,
Regards,
Janardhan.
Feb 26 '08 #5
SIGSEGV is a synchronous signal. That mean it happens as part of current executing instruction. In general we do not handle SIGSEGV. If you provide your handler for these, handler will be executed and then your faulted instruction is tried again. This is where asynchronous signals differ. This is expected behavior.
Oct 15 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1273
by: Dieter Maurer | last post by:
Python 2.3.3, Linux 2.4.x: It looks as if a SIGSEGV in a thread of a multi threaded application does not kill the complete process under some circumstances but only one thread (unrelated to the original SIGSEGV). Although documented this way, this is arguably the wrong behaviour for SIGSEGV (and some other signals that indicate program failure).
0
3536
by: Paffko | last post by:
What are the possibilities of getting SIGBUS and SIGSEGV errors in the following scenario? There is a program (C/C++/Pro*C) that was running fine under HP-UX 11.x and Oracle8i (8.1.6). Oracle database was upgraded to Oracle9i (9.2.0). The source code, including the project libraries, was re-compiled with 64-bit HP-UX C/C++ compiler options, the Pro*C code was pre-compiled with Oracle9i precompiler, and linked with 64-bit Oracle9i...
7
8970
by: USUN_TO | last post by:
Hi, i got problem when i bind in this way: local_addr.sin_family = AF_INET; local_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); local_addr.sin_port = htons(CLIENT_PORT); i can easly bind port without any SIGSEGV (segmentation fault) but MSDN wrote:
4
9203
by: junky_fellow | last post by:
what is the difference between signals SIGBUS and SIGSEGV ? when does an application program receive SIGBUS and in which cases SIGSEGV ? thanx in advance for any help ...
13
17685
by: vashwath | last post by:
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");
0
1497
by: Nancy | last post by:
Hi, I'm running 2.4 Python. I have an extension program that calls C funcs. Actually I have a C prog that calls python that calls C. In a python to C function call I get a SIGSEGV and this stack trace. I have print statements that show it made it into the C extension function, and within there its crashing with this trace. gdb also puts up a popup that says Python/ceval.c No such file or directory. Thanks.
4
3084
by: subirs | last post by:
Hi, I am encountering SIGSEGV if I am opeing and closing a file in a do-while loop. i am including the part of the code where I have used fscanf. ----------------------------------------------------------------- FILE *save; do { save=fopen("Settings/iwrite.dat","r");
5
6469
by: Joakim Hove | last post by:
Hello, in my application I have a typedefed struct: typedef struct { double d1; int i1; /* I have simplified the object here. */ } data_ptr_type;
1
2000
by: krazedkid | last post by:
I am trying to get my code to handle SIGSEGV multiple times, it will handle one of them but then nothing else. void sigHandler( int signum ) { if ( signum == SIGSEGV ) { printf("got a signal...\n"); } } int main( int argc, char ** argv ) { signal(SIGSEGV, sigHandler);
0
8509
marktang
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...
0
8856
jinu1996
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...
1
8652
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6269
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
5737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4256
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...
0
4456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2855
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2107
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.