在后台运行带有tcsetattr原始模式的程序

时间:2013-11-18 14:05:04

标签: termios

我需要在后台运行一个程序。问题是该程序执行tcsetattr()调用并将原始模式设置如下:

    struct termios tio;
    if (tcgetattr(fileno(stdin), &tio) == -1) {
            perror("tcgetattr");
            return;
    }
    _saved_tio = tio;
    tio.c_iflag |= IGNPAR;
    tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
    tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
    //      #ifdef IEXTEN
    tio.c_lflag &= ~IEXTEN;
    //      #endif
    tio.c_oflag &= ~OPOST;
    tio.c_cc[VMIN] = 1;
    tio.c_cc[VTIME] = 0;
    if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
            perror("tcsetattr");
    else
            _in_raw_mode = 1;

这意味着,只要我用“&”运行我的程序然后按回车键,过程显示“已停止”。即使ps aux输出显示'T'作为过程状态,这意味着它没有运行。 如何让这个程序在后台运行。问题是我无法修改这个程序。

有关完整的详细信息,实际上我需要使用ipmitool和'sol'作为后台进程。

任何帮助表示赞赏! 感谢

1 个答案:

答案 0 :(得分:2)

如果不知道如何实际使用/启动ipmitool,很难给出错误的完整答案,但我会尝试添加一些细节。 因此,需要调整问题中的所有选项来调整程序的i / o(参见注释):

 // ignorance of errors of parity bit
tio.c_iflag |= IGNPAR;
// removed any interpretation of symbols (CR, NL) for input and control signals
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
// switch off generation of signals for special characters, non-canonical mode is on,
// no echo, no reaction to kill character etc
tio.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
// removed recognition of some spec characters
//      #ifdef IEXTEN
tio.c_lflag &= ~IEXTEN;
//      #endif
// disable special impl-based output processing
tio.c_oflag &= ~OPOST;
// minimum number of characters to read in non-canonical mode
tio.c_cc[VMIN] = 1;
// timeout -> 0
tio.c_cc[VTIME] = 0;
// accurately make all the adjustments then it will be possible
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1)
        perror("tcsetattr");
else
        _in_raw_mode = 1;

有关终端配置的更多详细信息,请herehere。 换句话说,这部分代码将进程的标准输入配置为“完全静默”或“原始”模式 尽管缺少信息,您也可以尝试“kill -cont%PID%”来尝试提供一些文件作为标准输入。