Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6580197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:59:45+00:00 2026-05-25T15:59:45+00:00

I am using ptrace to trace a child process. It works perfectly well when

  • 0

I am using ptrace to trace a child process. It works perfectly well when the child process exit normally. But if it exit abnormally, the program get into an infinite loop in-spite of using the macro WIFSIGNALED(&status). Here is sample child process:

try.c

int main()
   {
      int a=5/0;
   }

And here is tracing program

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/user.h>
#include <sys/syscall.h>   /* For SYS_write etc */
#include <sys/reg.h>
#include <signal.h>
int main()
{   
    pid_t child;
    long orig_eax, eax;
    int status,insyscall = 0;
    child = fork();
    if(child == 0)
    {
            ptrace(PTRACE_TRACEME, 0, NULL, NULL);
            execl("./try", "try", NULL);
    }
    else
    {
        siginfo_t sig;
        memset(&sig,0,sizeof(siginfo_t));
        while(1)
        {
            wait(&status);
            if(WIFSIGNALED(status))
            {
                printf("Exiting due to signal\n");
                exit(0);
            }
            if(WIFEXITED(status))
                break;
            orig_eax = ptrace(PTRACE_PEEKUSER,child, 4 * ORIG_EAX, NULL);
            printf("system call number=%ld\n",orig_eax);
            if(insyscall == 0)
            {
                      /* Syscall entry */
                      insyscall = 1;
                      printf("In sys call\n");
            }
            else 
            {
               /* Syscall exit */
                 eax = ptrace(PTRACE_PEEKUSER,child, 4 * EAX, NULL);
                 printf("System call returned with %ld\n", eax);
                 insyscall = 0;
             }
            ptrace(PTRACE_SYSCALL,child, NULL, NULL);
        }
    }
    return 0;
}

Why the signal is not being detected which otherwise works when ptrace is not used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:59:46+00:00Added an answer on May 25, 2026 at 3:59 pm

    When you ptrace a process, wait will return for any state change. One of those is when the process is about to receive a signal. Your wait will return before the signal is delivered to the child. You need to use PTRACE_CONT to allow the signal to be delivered to the child, if that’s what you want to happen.

    Why does it work this way? Well remember, ptrace’s main purpose is to be used in implementing debuggers. If you didn’t get a chance to intercept signals such as SIGSEGV, the debugger couldn’t stop and let you examine the seg fault before the process was torn down.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the C# Facebook SDK 5.0.3 everything works fine whit the client.Get(/me). But when
Using NSDateComponents I know how to get the day component, but this gives me
as per Using ptrace to write a program supervisor in userspace , I'm attempting
on a Linux machine, I am using ptrace with the PTRACE_SINGLESTEP parameter to count
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using the HTML5 File API I can get the Binary String representation of a
Using NLTK and WordNet , how do I convert simple tense verb into its
Using jQuery, how do I get the value from a textbox and then load
using java and jna I call a fonction : trace(potrace_ bitmap_s) struct potrace_bitmap_s {
I've been trying to use the system call ptrace (using the PTRACE_SINGLESTEP macro) to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.