Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c - Ncurses stops process when put in background

Problem:

Ncurses screen initialization causes processes sent to the background to stop and only resume when brought back to the foreground.

Question(s):

  • Is it possible to have a process using ncurses for display still run in the background?
  • Is there a way for a process to self-check if it is running in the background and call initialize ncurses when in the foreground and end it when sent back to background (and possibly repeat this as necessary)?

Notes:

  • I would only like the display to be updated when the process is running in the foreground
  • When the process is in the background no display update is needed.

Any and all help is appreciated.


Status Updates

2013/07/17

  • Looking through ncurses documentation for a reason that initscr() cause program interruption when sent to background.

  • Looking into detection of process state.

like image 789
Ambiguities Avatar asked May 21 '26 08:05

Ambiguities


1 Answers

I think the culprits might be (from signal(7))

   SIGTTIN   21,21,26    Stop    tty input for background process
   SIGTTOU   22,22,27    Stop    tty output for background process

I don't know if one can override signal handling for these signals while using ncurses. It doesn't seem to make much sense, though: Neither do you want to steal input from the foreground process, nor do you want to scribble on the tty in an uncontrolled fashion (destroying whatever the foreground process wrote). So I think, the behaviour you observe, might be the only sensible ...

But: If you want to run some ncurses program in background, you could use screen http://www.gnu.org/software/screen/ which is in almost any Linux distribution. Run you're process in a detached screen, then reconnect with 'screen -r -D' or similar.

like image 77
2 revs Avatar answered May 23 '26 00:05

2 revs