向自己发送终止信号

时间:2021-02-25 13:03:22

标签: c++ linux signals

我有一个运行 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发送到通过调用此函数创建的子进程?

1 个答案:

答案 0 :(得分:1)

发送kill信号给self可以通过这个命令来完成

kill -9 $$