Run a C++ program in Clion as root

匆匆过客 提交于 2020-01-12 14:22:32

问题


I'm trying to run a program written in C++ by using CLion v1.2 as super user. Anyone here knows how to run it as superuser? I'm using CMake.


回答1:


I solved this by remote debugging on local machine. I run gdbserver with root privileges and connected to it from CLion.

To start gdbserver sudo gdbserver :port myapp, configure remote GDB debug with port




回答2:


If you are asking to run the debugger as sudo/administrator, I had the same issue. On Linux you can open CLion as sudo and gdb will not have root permission issues running an executable:

sudo ./clion.sh

I would guess that you could right click in Windows and "Run as administrator" to get the same result.

There is a feature request into JetBrains to run the debugger as root that could use more up voting.




回答3:


A workaround is:

From https://www.jetbrains.com/help/clion/attaching-to-local-process.html#prereq-ubuntu

If you are using CLion on Ubuntu (or probably, on some other Linux distribution), upon the first attempt to attach to the local process you can get the ptrace: Operation not permitted. error message. To disable it and enable attach to the local process feature, do the following:

To disable this restriction temporarily, enter the command:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

To disable this restriction permanently, open the file /etc/sysctl.d/10-ptrace.conf for editing and change the line kernel.yama.ptrace_scope = 1 to kernel.yama.ptrace_scope = 0. To apply the changes, enter: sudo service procps restart or restart your system, at your choice.




回答4:


You can create a bash script to help you. For example, run.sh:

#!/usr/bin/env bash
echo $LOGIN_PASSWD | sudo -S yourExecutable --with=some-arguments

Don't forget to chmod a+x run.sh, and export the password of current account as an environment variable in Run/Debug Configurations.



来源:https://stackoverflow.com/questions/34927781/run-a-c-program-in-clion-as-root

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!