To kill a python script from your C program, you can find its process id, using the name of the python script(or some other regex), and then kill the process.
My C is a little rusty, but the code below will kill a running python script called test.py
.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main (void) {
bool kill_python = true;
if (kill_python == true) {
FILE *cmd = popen("kill -9 $(ps aux | grep '[t]est.py' | awk '{print $2}')", "r");
pclose(cmd);
}
return 0;
}
ps aux | grep '[t]est.py' | awk '{print $2}'
returns the process id of the python script
kill -9 {PID}
kills the process forcibly(-9
= non-catchable, non-ignorable kill)