6

When using gdb to attach to the process. It shows

Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.

As root I use echo 0 >/proc/sys/kernel/yama/ptrace_scope; then it shows:

bash: /proc/sys/kernel/yama/ptrace_scope: Read-only file system

How can I fix this problem? The content of /etc/sysctl.d/10-ptrace.conf is kernel.yama.ptrace_scope = 0

2
  • Can you try attaching that process with sudo?. And for the Read-only system you just remount your rootfs using sudo mount -o remount,rw / and then try.
    – Thushi
    Aug 7, 2015 at 8:39
  • What kind of installation are you working on? Is this some kind of virtualized environment? Aug 7, 2015 at 22:30

2 Answers 2

6

In docker you can now use the --privileged option, see https://docs.docker.com/engine/reference/commandline/exec/

docker exec --privileged -ti <container> bash

In privileged mode, gdb just works without any modifications to ptrace_scope.

0
0

To use a more granular approach, cap_add can also be used. The flag that works for me is SYS_PTRACE. This works in the CLI and in docker-compose files. For swarm you need to have at least Docker 20.10.0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .