Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't ptrace child started with subprocess.Popen from other child #41

Open
cmlsharp opened this issue Jun 13, 2017 · 2 comments
Open

Can't ptrace child started with subprocess.Popen from other child #41

cmlsharp opened this issue Jun 13, 2017 · 2 comments

Comments

@cmlsharp
Copy link

cmlsharp commented Jun 13, 2017

I apologize if this is an ignorant question. I have a parent process which spawns two children and I need one of the children (created via multiprocessing) to be able to ptrace the other (started via subprocess.Popen) but I am recieving the permission error: ptrace.error.PtraceError: ptrace(cmd=16, pid=15151, 0, 0) error #1: Operation not permitted

Here is sample code that demonstrates what I am trying to do and the error I am encountering:

import multiprocessing
import subprocess
import time

import ptrace.debugger


def ptrace_test(pid):
    debugger = ptrace.debugger.PtraceDebugger()
    process = debugger.addProcess(pid, False)
    # Other stuff


child = subprocess.Popen("/usr/bin/ls")
proc = multiprocessing.Process(target=ptrace_test, args=(child.pid,))
proc.start()
proc.join()
@vstinner
Copy link
Owner

FYI I'm not working anymore on this project and ptrace remains a big mystery for me :-) Good luck to find the correct way to use ptrace :-D

@chrahunt
Copy link

chrahunt commented May 9, 2019

There are several reasons this can happen, see here.

If due to the YAMA feature (probably if on recent Ubuntu), then you can use prctl.set_ptracer in the tracee with the tracer pid and signal.pause() until the tracer attaches. You may be able to use the preexec_fn argument to Popen for this but there are a lot of warnings about it in the documentation - it may be better to start a multiprocessing.Process that creates the subprocess after the tracer attaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants