问题:找出我有多少贝壳深。
详细信息:我经常从 vim 中打开外壳。构建并运行并退出。有时我忘记在里面打开另一个vim,然后打开另一个shell。:(
我想知道我有多少贝壳,甚至可能一直在我的贝壳屏幕上显示它。(我可以管理那部分)。
我的解决方案:解析进程树并查找 vim 和 bash/zsh 并找出当前进程在其中的深度。
这样的东西已经存在了吗?我找不到任何东西。
目标:以 root 身份运行程序(C++ 二进制文件)。同:SetUID 位在 Ubuntu 中不起作用?
./a.out 输出:
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
psurana //output for "whoami" Look below for the code.
ls -l 输出:
-rwsrwxr-x 1 root root 46136 Jun 7 20:13 a.out
编码 :
#include <string>
#include <stdlib.h>
int main(int argc, char *argv[]){
std::string input = "apt-get install " + std::string(argv[1]);
system(input.c_str());
system("whoami"); …
Run Code Online (Sandbox Code Playgroud)