1

I need to run a program as is in the background. The catch is that the program does a tcsetattr() call and sets the raw mode as following :

    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;

The implication is that as soon as I run my program with '&' and press enter, the process shows 'stopped'. Even the ps aux output shows 'T' as the process state which means it is not running. How can I make this program running in background.Issue is I cant modify this program.

For complete details, actually I need to use ipmitool with 'sol' as a background process.

Any help is appreciated ! Thanks

Smash
  • 839
  • 1
  • 9
  • 10

1 Answers1

2

It is hard to give a complete answer on what is going wrong without knowledge of how ipmitool is actually used/started but I'll try to add some details. So all the options in the question are needed to adjust i/o for the program (see comments):

 // 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;

More details on terminal configuring are here and here. In other words this part of code configures the standard input of the process to a "complete silent" or "raw" mode.
In spite of the lack of the information you may also try "kill -cont %PID%" to the process or try to provide some file as standard input for it.

Michael
  • 1,505
  • 14
  • 26