Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't revert to shell after receiving SIGTSTP #984

Open
pafoster opened this issue May 5, 2024 · 2 comments
Open

Doesn't revert to shell after receiving SIGTSTP #984

pafoster opened this issue May 5, 2024 · 2 comments

Comments

@pafoster
Copy link

pafoster commented May 5, 2024

First off, thanks for developing this amazing library!

Unexpected behaviour: If I issue a kill -s SIGTSTP $pid as a command in a separate terminal, the terminal running the UI continues to display the UI (albeit in SIGTSTPed state). Expected behaviour (see top, links and other utilities) is for the running process to revert to the user's shell.

Related question: How do I ensure that Ctrl-Z triggers a SIGTSTP?

@rivo
Copy link
Owner

rivo commented May 9, 2024

I wonder if this is more of a question for tcell than for this project. Definitely the last question because my understanding is that tcell will capture all user input, including Ctrl-Z. For example, this is bound to the "undo" function in a TextArea.

There is Application.Suspend() also which might help you achieve what you would like to do. And if it doesn't, please explain why/how receiving SIGTSTP (and SIGCONT also, I assume) is something your application needs to be able to support.

@pafoster
Copy link
Author

pafoster commented May 18, 2024

Thank you. What I'd like to achieve is to signal that the process running the tview application is suspended, taking me back to the shell from which the process was invoked. You can reproduce this effect by invoking a utility like top in your terminal and hitting ctrl-z. What happens is that it temporarily suspends execution of the process and takes you back to the shell; if you then type fg, top will display again and continue execution. I am providing top as an example for what I believe is standard behaviour for job control in a Unix/Linux environment.

According to https://www.gnu.org/software/libc/manual/html_node/Job-Control-Signals.html:

The SIGTSTP signal is an interactive stop signal. Unlike SIGSTOP, this signal can be handled and ignored.

Your program should handle this signal if you have a special need to leave files or system tables in a secure state when a process is stopped. For example, programs that turn off echoing should handle SIGTSTP so they can turn echoing back on before stopping.

This signal is generated when the user types the SUSP character (normally C-z). For more information about terminal driver support, see Special Characters.

The typical behavior is described in this stackexchange post:

Pressing ctrl + z sends the TSTP signal to your process. This halts execution (the kernel won't schedule any more CPU time to the process) and the process is awaiting a CONT to continue processing.

You can emulate/replicate this via kill -TSTP and kill -CONT (since kill will send a nominated signal to your process, despite the name!)

I've used Application.Suspend() successfully to invoke a sub-shell. But what I am after here as mentioned above, is to a) temporarily suspend execution on the process and b) return to the shell from which the process was invoked.

The Wikipedia article on job control says:

A job running in the foreground can be stopped by typing the suspend character (Ctrl-Z). This sends the "terminal stop" signal (SIGTSTP) to the process group. By default, SIGTSTP causes processes receiving it to stop, and control is returned to the shell. However, a process can register a signal handler for or ignore SIGTSTP. A process can also be paused with the "stop" signal (SIGSTOP), which cannot be caught or ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants