I am trying to kill a process that I have forked off for the purpose of running a python script that I have installed. This script can be killed via crtl-c when running in the codeblocks terminal and when being run from the command line (bash).
I have tried SIGINT and SIGQUIT. When I do not run the system call to python it works ok.
int main()
{
int yahooTickerGrabberServicePID = fork();
if (yahooTickerGrabberServicePID == 0)
{
system("YahooTickerDownloader.py");
return EXIT_SUCCESS;
}
// sleep for testing only.
sleep(5);
// Check to see if child is still running - 0 return indicates this is still running because the command can be sent...
if(kill(yahooTickerGrabberServicePID, 0) == 0)
{
printf("good - still running...");
}
printf("sending sigint...");
kill(yahooTickerGrabberServicePID, SIGINT);
waitpid(yahooTickerGrabberServicePID, NULL, 0);
while(processStillRunning == 0)
{
// printf("still running... :( ");
kill(yahooTickerGrabberServicePID, SIGINT);
processStillRunning = kill(yahooTickerGrabberServicePID, 0);
waitpid(yahooTickerGrabberServicePID, NULL, 0);
}
printf("stopped?!");
return EXIT_SUCCESS;
}
}
I am aware I need more checks on the returns above, this is a full MWE.
The above does not kill the script - how can I make sure that SIGINT gets through to the python running from the system call, as it does when I hit it from the keyboard?