我知道我可以通过中断 gdb 中的进程、使用文件描述符关闭然后使用我想要的文件名重新打开来更改程序写入的文件。有没有办法在运行时做同样的事情?
例如,我知道我要更改的文件使用文件描述符 5,所以我尝试了
./myexe 5>/dev/null
但所做的只是改变一些东西,所以感兴趣的文件在 fd=6 上。
我的默认堆栈大小(根据 ulimit -s)是 8192 kB,所以当我尝试运行它时,自然会出现段错误下面的代码。此外,自然地,如果我执行'ulimit -s 9000',它可以正常工作。但是,当我执行 'ulimit -s unlimited' 时,代码再次出现段错误。任何想法这里发生了什么?
如果有用,我正在使用内核 4.19.0-6 和 gcc 版本 Debian 8.3.0-6 运行 Debian 10。
#include <iostream>
#include <unistd.h>
#include <cstdlib>
void* wait_exit(void*)
{
char bob[8193*1024];
return 0;
}
int main()
{
pthread_t t_exit;
int ret;
if((ret = pthread_create(&t_exit,NULL,wait_exit,NULL)) !=0)
{
std::cout<<"Cannot create exit thread: "<<ret<<std::endl;
}
std::cout<<"Made thread"<<std::endl;
sleep(5);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我有以下括号扩展(bash shell):
echo -e {0..4..2}" "{0..2..2}"\n"
Run Code Online (Sandbox Code Playgroud)
我预计这会产生
0 0
0 2
2 0
2 2
4 0
4 2
Run Code Online (Sandbox Code Playgroud)
但是除了第一行之外,输出的每一行都有一个前导空格,最后还有一个我没想到的额外的空行。为什么是这样。有没有简单的方法来修复它?显然我可以做一些笨拙的事情,比如 pipe to sed 's/^ //'
,但是有没有更漂亮的方法而不用管道到额外的命令?