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 593051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:48:15+00:00 2026-05-13T15:48:15+00:00

Can child process use the ptrace system call to trace its parent? Os is

  • 0

Can child process use the ptrace system call to trace its parent?

Os is linux 2.6

Thanks.

upd1:
I want to trace process1 from “itself”. It is impossible, so I do fork and try to do ptrace(process1_pid, PTRACE_ATTACH) from child process. But I can’t, there is a strange error, like kernel prohibits child from tracing their parent processes

UPD2: such tracing can be prohibited by security policies. Which polices do this? Where is the checking code in the kernel?

UPD3: on my embedded linux I have no errors with PEEKDATA, but not with GETREGS:

child: getregs parent: -1
errno is 1, strerror is Operation not permitted 

errno = EPERM

  • 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-13T15:48:16+00:00Added an answer on May 13, 2026 at 3:48 pm

    This question really interested me. So I wrote some code to try it out.

    Firstly keep in mind, that when tracing a process, the tracing process becomes a parent for most purposes, except in name (i.e. getppid()). Firstly, a snippet of the PTRACE_ATTACH section of the manual is helpful:

       PTRACE_ATTACH
              Attaches to the process specified in pid,  making  it  a  traced
              "child"  of the calling process; the behavior of the child is as
              if it had done a PTRACE_TRACEME.  The calling  process  actually
              becomes the parent of the child process for most purposes (e.g.,
              it will receive notification of  child  events  and  appears  in
              ps(1)  output  as  the  child's parent), but a getppid(2) by the
              child will still return the PID of  the  original  parent.   The
              child  is  sent a SIGSTOP, but will not necessarily have stopped
              by the completion of this call; use  wait(2)  to  wait  for  the
              child to stop.  (addr and data are ignored.)
    

    Now here is the code I wrote to test and verify that you can in fact ptrace() your parent (you can build this by dumping it in a file named blah.c and running make blah:

    #include <assert.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/ptrace.h>
    
    int main()
    {
        pid_t pid = fork();
        assert(pid != -1);
        int status;
        long readme = 0;
        if (pid)
        {
            readme = 42;
            printf("parent: child pid is %d\n", pid);
            assert(pid == wait(&status));
            printf("parent: child terminated?\n");
            assert(0 == status);
        }
        else
        {
            pid_t tracee = getppid();
            printf("child: parent pid is %d\n", tracee);
            sleep(1); // give parent time to set readme
            assert(0 == ptrace(PTRACE_ATTACH, tracee));
            assert(tracee == waitpid(tracee, &status, 0));
            printf("child: parent should be stopped\n");
            printf("child: peeking at parent: %ld\n", ptrace(PTRACE_PEEKDATA, tracee, &readme));
        }
        return 0;
    }
    

    Note that I’m exploiting the replication of the parent’s virtual address space to know where to look. Also note that when the child then terminates, I suspect there’s an implicit detach which must allow the parent to continue, I didn’t investigate further.

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

Sidebar

Related Questions

In perl debugger I can use DB::get_fork_TTY() to debug both parent and child process
If you spawn a child process in ruby (using Kernel.system for example), can it
How can I detect parent process death in Linux OS? If in parent process
I want to start a child process and read its stderr, but so far,
On Linux, normally I use ptrace function to trace all syscall, and kill the
When creating a child process in C++ using Windows API, one can allow inheritance
Question: How can I determine all processes in the child's Process Tree to kill
In MDI application which event can the child Form class use to detect when
I have parent/child relationship set up via Node Reference. A Child record can have
My application has two node types: a parent node which can hold recursive child

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.