How can I get the a process to listen for user input without terminating? . So, for example, i want the bash to wait for X minutes, and if i say "stop" it quits, or else just keeps waiting... How can I achieve that? So, upon execution my process would wait , and then I want to be able to stop, pause or continue through stdin, typing "stop", "continue" or "pause. Thank you.
Best How To :
A simple (but wasteful) option is that the initial program forks and then wait for input. The child process can update the counter.
When the parent program receive "pause" it sends the signal SIGTSTP to the child.
When the parent program receive "continue" it sends the signal SIGCONT to the child.
When the parent program receive "stop" it sends the signal SIGQUIT to the child.
If you want, you can also set a SIGINT handler in the parent using sigaction that kills the child when you type Ctrl+C.