The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
tracing in linux shary Shell Programming and Scripting 2 02-04-2007 07:05 AM
tracing shary Linux 1 02-04-2007 03:33 AM
Tracing the GPU usage solea SUN Solaris 0 07-31-2005 11:40 PM
[FreeBSD] ptrace( ) - Device busy Driver High Level Programming 5 01-31-2003 07:34 AM
Tracing a terminal alex blanco UNIX for Advanced & Expert Users 2 04-08-2002 03:24 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-02-2008
Registered User
 

Join Date: Jun 2008
Posts: 8
Tracing self process using ptrace()

Kindly correct me if any of the foll is wrong:

I want to trace the current process from the C program itself which I think can be done using

ptrace(PTRACE_ATTACH,getpid(),0,0);

I would like to get control back after a segmentation fault, or arithmetric exception (i.e. all signals that end in a core dump).

If I do something like this, it doesn't work :

Code:
int status;
//other code
....
....
ptrace(PTRACE_ATTACH,getpid(),0,0);
int a=99,b=0,c;
c = a/b;
wait(&status);
if(WIFSIGNALED(status)) printf("Got control after exception");
How do I do the above ? I do not want to create a child process to monitor the signals. My aim is to create a single process solution.

Thank you, in advance.

Last edited by vpraveen84; 06-02-2008 at 11:50 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 06-02-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
A couple problems with this.
1. It can't be done if you service the segmentation violation
properly as a fatal error.
2.If invalid memory has been accessed and overwritten
causing the kernel to send sigsegv the program is in an
unstable state and should exit.
Further operations are no longer trustworthy as many critical
memory locations may have been altered.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0