c - linux下如何定位导致应用程序收到SIGTTIN的代码位置?

标签 c linux

我的一个 c++ 应用程序在运行了一段不确定的时间后会挂起,因为它没有终止,所以它不能被父进程重新启动。

已知SIGTTIN可以防止程序被nohup挂起或使用 </dev/null重定向标准输入,但这并不能从根本上解决问题。

那么,有谁知道如何调试或定位产生SIGTTIN信号的代码的位置吗?

// this is a example, exec command to get SIGTTIN: ./a.out &
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

int main(int argc, char* argv[]) {
        int len;
        char buf[64];

        while(1) {
                len = read(STDIN_FILENO, buf, 64);
                if (len > 0) {
                        write(STDOUT_FILENO, buf, len);
                }
                else {
                        perror("read");
                }
        }
        return 0;
}

最佳答案

您在后台执行./a.out & 启动您的程序,但您的程序从stdin 读取,所以您有那个信号

来自 https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html :

Macro: int SIGTTIN

A process cannot read from the user’s terminal while it is running as a background job. When any process in a background job tries to read from the terminal, all of the processes in the job are sent a SIGTTIN signal. The default action for this signal is to stop the process. For more information about how this interacts with the terminal driver, see Access to the Terminal.

locate the location of the code that produces the SIGTTIN signal?

这是阅读

关于c - linux下如何定位导致应用程序收到SIGTTIN的代码位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56357784/

相关文章:

Rust 常量/静态可以暴露给 C 吗?

mysql - Laravel 代客 Linux : Can't connect MariaDB/Mysql

c - Linux/Unix 作为内核运行

c - 预处理器 __VA_ARGS__ 长度的限制?

c - 如何在 C 中解析带引号分隔字段的 CSV?

使用字符串检查宏定义

c - 调用 sendto() 时长度错误

c++ - 如何在Linux上构建wxWidgets示例

linux - 将库(来自汇编文件)与 Makefile 中的 main.c 链接

c - OpenSSL - IPv6 支持