简体   繁体   English

如何在打开“ raw()”设置的情况下终止ncurses程序?

[英]How to terminate an ncurses program with the `raw()` setting turned on?

In order to save time, I'd like to know if there's a professional way to terminate an unresponsive ncurses program (from the terminal) with the raw() setting turned on. 为了节省时间,我想知道是否有一种专业的方法可以通过启用raw()设置来终止无响应的ncurses程序(从终端)。 Here, CTRL+C Won't help. 在这里, CTRL + C将无济于事。

Example progam: 示例程序:

#include <ncurses.h>

int main()
{
    initscr();
    raw();

    while(1)
    {
        printw("Yello\n");
    }

    refresh();
    endwin();

    return 0;
}

Whenever you hit the Control-C ( Cc ) combination, the terminal parses it and then sends a signal (SIGINT) to whatever application is running in the foreground. 每当您按下Control-CCc )组合时,终端就会对其进行解析,然后向前台运行的任何应用程序发送信号(SIGINT)。 Control-C has no special meaning to the operating system, only to the terminal. Control-C对操作系统没有特殊意义,仅对终端没有意义。

When you call ncurses' raw() or cbreak() function, it essentially instructs the terminal to ignore these special characters and pass them on directly to whatever's running in the foreground, essentially instructing the terminal that the application "knows what it's doing". 当您调用ncurses的raw()cbreak()函数时,它实际上指示终端忽略这些特殊字符,并将它们直接传递给在前台运行的任何字符,实质上是指示终端应用程序“知道它在做什么”。

So yes, you would have to "manually" (ie from another terminal) kill the running application: 因此,是的,您将不得不“手动”(即从另一个终端)杀死正在运行的应用程序:

ps aux | grep your_executable_name
kill the_pid

Yes, you can do this while in a TTY. 是的,您可以在TTY中执行此操作。 And yes, you can jam your whole system if you lock all available TTYs (and don't have SSH access). 是的,如果您锁定所有可用的TTY(并且没有SSH访问权限),则可能会阻塞整个系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM