473,405 Members | 2,310 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,405 software developers and data experts.

SIGSEGV Handling

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

Thanks
Sep 21 '07 #1
5 7331
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
In the same program i need to catch the signal
Sep 21 '07 #3
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
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
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...
0
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...
7
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...
4
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
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() {...
0
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...
4
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....
5
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
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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,...
0
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...
0
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...
0
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...
0
tracyyun
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...
0
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...

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.