我有一个运行 linux 命令的 C++ 代码,我想在通过 C++ 代码执行该 linux 命令时模拟段错误,即 SIGSEGV。 所以我的代码看起来像这样
int main(){
string cmd = "some linux command that should throw seg fault";
execute_linux_comand(cmd); // Want to simulate segfault coming while executing this command
}
我应该在“cmd”中放什么,以便它可以将SIGSEGV发送到通过调用此函数创建的子进程?
答案 0 :(得分:1)
发送kill信号给self可以通过这个命令来完成
kill -9 $$