1

我需要在后台运行一个程序。问题是程序执行 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;

这意味着,只要我使用“&”运行我的程序并按 Enter,该过程就会显示“已停止”。甚至 ps aux 输出也将“T”显示为进程状态,这意味着它没有运行。我怎样才能让这个程序在后台运行。问题是我不能修改这个程序。

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

任何帮助表示赞赏!谢谢

4

1 回答 1

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;

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

于 2013-11-18T14:54:51.710 回答