C - Ncurses stops the process when put in the background

Problem:

Initializing the Ncurses screen causes processes sent to the background to stop and resume only when they return to the foreground.

Question (s):

  • Is it possible to have a process using ncurses to display still running in the background?
  • Is there a way to self-control the process if it runs in the background and causes ncurses to be initialized when it is in the foreground and terminates it when sent back to the background (and possibly repeating this if necessary)?

Notes:

  • I would like the display to refresh when the process is in the foreground
  • When the process is in the background, updating the display is not required.

Any help is appreciated.


Status Updates

2013/07/17

  • Looking at the ncurses documentation for the reason that initscr () causes the program to be interrupted when sent to the background.

  • Inclusion in a process state.

+4
source share
1 answer

I think that the culprits may 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 do not know if it is possible to override the signal processing for these signals when using ncurses. This does not seem to make much sense: you also do not want to steal input from the foreground process, and you cannot write to tty in an uncontrolled way (destroying everything that the foreground process wrote). Therefore, I think that the behavior you observe may be the only reasonable one ...

But: If you want to run some ncurses program in the background, you can use the http://www.gnu.org/software/screen/ screen, which is found in almost any Linux distribution. Run the process on a separate screen, then reconnect to "screen -r -D" or the like.

0
source

Source: https://habr.com/ru/post/1491515/


All Articles