python - 如何通过系统调用发送 sigterm 来处理正在运行的 python
问题描述
我试图杀死一个为了运行我安装的 python 脚本而分叉的进程。在代码块终端中运行以及从命令行 (bash) 运行时,可以通过 crtl-c 终止此脚本。
我试过 SIGINT 和 SIGQUIT。当我不运行对 python 的系统调用时,它可以正常工作。
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;
}
}
我知道我需要对上述退货进行更多检查,这是一个完整的 MWE。
以上不会杀死脚本 - 我如何确保 SIGINT 进入从系统调用运行的 python,就像我从键盘敲击它时一样?
解决方案
推荐阅读
- javascript - Javascript对象在服务器端通过空
- javascript - 转到其他页面后使视频不重新加载?
- python - TypeError:过滤器类型的对象不是 JSON 可序列化的 - 嵌套对象
- wordpress - 寻求为 Contact Form 7 创建“按表单视图付费”系统的方法
- node.js - 从目录中的所有 png 创建 mp4
- excel - 使用 MSXML 登录以进行数据抓取
- node.js - 试图在 nodejs 中获取 meanfreq 会导致常量
- python - gremlin_python 在向顶点添加属性时由于 aiohttp.WSMsgType.closed 引发 RuntimeError 异常
- prolog - 如何通过在 Prolog 中创建这些整数的列表来查询两个值之间的整数?
- python - 将数据附加到现有工作表并使用 Python 将其保存在其他位置\新名称