如果按“终止”按钮,Linux 上的 Eclipse CDT 中会发生什么?

发布于 2024-09-19 01:12:16 字数 118 浏览 8 评论 0原文

我想一些信号会被发送到进程。一些还是一个?如果不止一个,它们按什么顺序发生?

如果按下“终止”按钮并且进程已分叉,会发生什么情况? 如果该进程已通过 system(...) 启动了其他进程,会发生什么情况?

I guess some signals will be sent to the process. Some or one? If more than one in which order do they occure?

And what happens if the Terminate button is pressed and if the process has forked?
And what happens if the process has started other processes by system(...)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

被翻牌 2024-09-26 01:12:16

如果不检查的话我无法确定,但如果发送的信号不是 SIGTERM (或者可能是 SIGKILL,但这对 CDT 有点不友好),我会感到惊讶。

至于子流程,取决于它们实际在做什么。如果他们通过管道与其父进程进行通信(以任何方式,包括读取其标准输出),他们可能会发现这些文件描述符关闭或进入异常状态;如果他们尝试使用 fd,他们将会收到一个 SIGPIPE。那里可能还有 SIGHUP。

如果一个子进程确实完全不相交(关闭所有打开的 FD,父进程中没有 SIGTERM 处理程序可能会告诉它退出),那么理论上它可以继续运行。这就是守护进程的产生方式。

I can't be sure without checking, but I would be surprised if the signal sent was anything other than SIGTERM (or possibly SIGKILL, but that would be a bit unfriendly of CDT).

As for sub-processes, depends what they are actually doing. If they are communicating with their parent processes over a pipe (in any way whatsoever, including reading their stdout), they'll likely find that those file descriptors close or enter the exception state; if they try to use the fds anyway they'll be sent a SIGPIPE. There may also be a SIGHUP in there.

If a sub-process was really completely disjoint (close all open FDs, no SIGTERM handler in the parent which might tell it to exit) then it could theoretically keep running. This is how daemon processes are spawned.

眼中杀气 2024-09-26 01:12:16

我用终止按钮检查了 SIGTERM、SIGHUP、SIGPIPE。不起作用...
我猜这是 SIGKILL,这让我很难过!另外,我没有找到从外部(或内置插件)控制台运行程序的好解决方案。

I checked SIGTERM, SIGHUP, SIGPIPE with terminate button. Doesn't work...
I guess it is SIGKILL and this makes me very sad! Also, I didn't find a good solution to run program from external(or built-in plugin) console.

怀中猫帐中妖 2024-09-26 01:12:16

好像是SIGKILL。 GDB 使用 SIGSTOP 来停止/恢复。来自 signal 手册页:

信号 SIGKILL 和 SIGSTOP 无法被捕获或忽略。

我尝试用 eclipse 调试以下程序。在运行会话中按 terminate 或在调试会话中按 pause 不会打印任何内容。因此它必须是 SIGKILLSIGSTOP

#include <signal.h>
#include <string.h>
#include <unistd.h>

void handler(int sig) {
    printf("\nsig:%2d %s\n", sig, strsignal(sig));
}

int main(int argc, char **argv) {
    int signum;
    int delay;

    if (argc < 2) {
        printf("usage: continue <sleep>\n");
        return 1;
    }

    delay = atoi(argv[1]);

    for (signum = 1; signum < 64; signum++) {
        signal(signum, handler);
    }

    printf("sleeping %d s\n", delay);
    for(;;) {
        sleep(delay);
    }

    return 0;
}

It seems to be SIGKILL. SIGSTOP is used by GDB to stop/resume. From signal man page:

The signals SIGKILL and SIGSTOP cannot be caught or ignored.

I tried to debug following program with eclipse. Pressing terminate in Run session or pause in Debug session does not print anything. Thus it must be either SIGKILL or SIGSTOP.

#include <signal.h>
#include <string.h>
#include <unistd.h>

void handler(int sig) {
    printf("\nsig:%2d %s\n", sig, strsignal(sig));
}

int main(int argc, char **argv) {
    int signum;
    int delay;

    if (argc < 2) {
        printf("usage: continue <sleep>\n");
        return 1;
    }

    delay = atoi(argv[1]);

    for (signum = 1; signum < 64; signum++) {
        signal(signum, handler);
    }

    printf("sleeping %d s\n", delay);
    for(;;) {
        sleep(delay);
    }

    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文