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 10:05 AM
tracing shary Linux 1 02-04-2007 06:33 AM
Tracing the GPU usage solea SUN Solaris 0 08-01-2005 03:40 AM
[FreeBSD] ptrace( ) - Device busy Driver High Level Programming 5 01-31-2003 10:34 AM
Tracing a terminal alex blanco UNIX for Advanced & Expert Users 2 04-08-2002 07:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-02-2008
vpraveen84 vpraveen84 is offline
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 03:50 PM..
  #2 (permalink)  
Old 06-02-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0