Qt Creator, ptrace: Operation not permitted. What is the permanent solution?
While debugging C++
code in Qt creator I get the following error
ptrace: Operation not permitted.
Could not attach to the process. Make sure no other debugger traces this process.
Check the settings of
/proc/sys/kernel/yama/ptrace_scope
For more details, see /etc/sysctl.d/10-ptrace.conf
Here a temporary solution is found: Receiving error while trying to debug in QtProject
-
temporary solution (won't survive a reboot):
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
But it is difficult to run the same code in terminal every time when I start my PC to use Qt.
What is the permanent solution for this?
Solution 1:
If running Ubuntu,
The recommended way to enable the needed ptrace kernel setting (hinted by qtcreator) is to edit /etc/sysctl.d/10-ptrace.conf
sudo vim /etc/sysctl.d/10-ptrace.conf
Then change
kernel.yama.ptrace_scope = 1
to
kernel.yama.ptrace_scope = 0
Save,
then apply:
$ sudo sysctl --system -a -p|grep yama
kernel.yama.ptrace_scope = 0
run
man sysctl
for more info.
Solution 2:
I got the answer.
Go to the location
/etc
with root privilege.Find the file
rc.local
.- Open it in a text editor like gedit and add the following code there
echo 0 | tee /proc/sys/kernel/yama/ptrace_scope
Restart your pc and you can see the debugger working perfectly.
Solution 3:
I found the answer that works for me on ubuntu in below link and the credit goes to dstzcxr
https://askubuntu.com/a/501271/395583
Just uncheck (or check - run - uncheck if it is for some reason unchecked) the box "Run in terminal" in "Projects" (on the left bar) - "Run" tab - "Run" section.