相关疑难解决方法(0)

信号处理程序是否有可能在"exec"之后存活?

我为进程写了一个信号处理程序,然后fork(),信号处理程序将应用于父进程和子进程.如果我用"exec"替换子进程,则信号处理程序不再存在.

我知道发生这种情况是因为"exec"调用将使用它自己覆盖子进程地址空间.我只是想知道即使在"exec"调用之后是否有办法让信号处理程序工作?

linux signals exec

29
推荐指数
1
解决办法
1万
查看次数

使用SIGTSTP挂起子进程后,shell没有响应

我正在用C编写一个基本shell,我正在努力暂停子进程.

我认为我的信号处理程序是正确的,并且我的子进程正在挂起,但在此之后,终端应该返回到父进程并且没有发生.

孩子被暂停,但我的shell没有注册任何输入或输出.tcsetpgrp()似乎没有帮助.

这是我的SIGTSTP shell代码中的信号处理程序:

void suspend(int sig) {
    pid_t pid;
    sigset_t mask;
    //mpid is the pgid of this shell.
    tcsetpgrp(STDIN_FILENO, mpid);
    tcsetpgrp(STDOUT_FILENO, mpid);
    sigemptyset(&mask);
    sigaddset(&mask, SIGTSTP);
    sigprocmask(SIG_UNBLOCK, &mask, NULL);
    signal(SIGTSTP, SIG_DFL);
    //active.pid is the pid of the child currently in the fg.
    if (active.pid != 0) {
        kill(active.pid, SIGTSTP);
    }
    else{
        //if this code is being run in the child, child calls SIGTSTP on itself.
        pid = getpid();
        if (pid != 0 && pid != mpid){
            kill(pid, SIGTSTP);
        } …
Run Code Online (Sandbox Code Playgroud)

c shell signals process

6
推荐指数
2
解决办法
6673
查看次数

标签 统计

signals ×2

c ×1

exec ×1

linux ×1

process ×1

shell ×1