Skip to content
Advertisement

Send a kill signal to self

I have a C++ code that runs a linux command, I want to simulate segfault i.e. SIGSEGV while executing that linux command from by C++ code. So my code looks like this

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
}

What should I put in “cmd” so that it can send SIGSEGV to the sub-process created by calling this function?

Advertisement

Answer

Sending kill signal to self can by done by putting this command

kill -9 $$
Advertisement