Why does the console need sometimes a reset after CTRL+C
Clash Royale CLAN TAG#URR8PPP
up vote
9
down vote
favorite
Some command line interface tools return a broken console when canceled by CTRL+C
.
Sometimes the text is invisible, or there are graphic problems until I run the command reset
.
(I use bash, but expect it is independent of the shell.)
Does this effect have a name?
What causes this, and how can programmers prevent this in the tools?
Is there a strategy how this problem is addressed in the major programming languages?
command-line console kill crash
add a comment |Â
up vote
9
down vote
favorite
Some command line interface tools return a broken console when canceled by CTRL+C
.
Sometimes the text is invisible, or there are graphic problems until I run the command reset
.
(I use bash, but expect it is independent of the shell.)
Does this effect have a name?
What causes this, and how can programmers prevent this in the tools?
Is there a strategy how this problem is addressed in the major programming languages?
command-line console kill crash
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
stty sane
for the grey beards
â Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23
add a comment |Â
up vote
9
down vote
favorite
up vote
9
down vote
favorite
Some command line interface tools return a broken console when canceled by CTRL+C
.
Sometimes the text is invisible, or there are graphic problems until I run the command reset
.
(I use bash, but expect it is independent of the shell.)
Does this effect have a name?
What causes this, and how can programmers prevent this in the tools?
Is there a strategy how this problem is addressed in the major programming languages?
command-line console kill crash
Some command line interface tools return a broken console when canceled by CTRL+C
.
Sometimes the text is invisible, or there are graphic problems until I run the command reset
.
(I use bash, but expect it is independent of the shell.)
Does this effect have a name?
What causes this, and how can programmers prevent this in the tools?
Is there a strategy how this problem is addressed in the major programming languages?
command-line console kill crash
asked Nov 11 '17 at 14:26
Jonas Stein
1,02721033
1,02721033
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
stty sane
for the grey beards
â Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23
add a comment |Â
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
stty sane
for the grey beards
â Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
stty sane
for the grey beardsâ Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23
stty sane
for the grey beardsâ Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
14
down vote
A console sometimes needs a reset(1)
(or some stty(1)
command) because the state of a pseudo-terminal does not change when some process (e.g. a program started by your shell) terminates.
Read the tty demystified.
(I find the handling of pseudo-terminals and pseudottys the most difficult part of Linux)
Is there a strategy how this problem is addressed in the major programming languages?
A well-behaved program dealing with the terminal and changing its mode or line discipline should try hard to avoid crashing and issue the appropriate calls (see termios(3)) to put the terminal in the right state. BTW, libraries like ncurses or readline are helpful (but you need to call their cleanup routines appropriately).
See signal(7) and signal-safety(7). Avoiding crashing in your code is difficult. Read about undefined behavior.
An imperfect workaround could be to define a shell function which runs your program then does a reset
(that could sometimes be inappropriate).
That workaround isn't great; sometimesreset
can result in differentstty
settings from the original ones.
â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I startedstty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red.stty -a > /tmp/test2
buttest1
andtest2
were exactly the same.
â Jonas Stein
Nov 12 '17 at 1:04
add a comment |Â
up vote
2
down vote
Responding to this problem isn't completely shell-independent. In zsh, there is the ttyctl
builtin, which can "freeze" or "unfreeze" the tty mode. I don't think there's an equivalent in bash. The setty
command in tcsh does the same thing, but more fine-grained: you can freeze individual settings.
Freezing the tty mode just means that zsh will remember the current mode, and if some future child changes it, the mode will be restored when the child suspends or terminates.
This will protect you from some of the bad effects of programs that crash or otherwise fail to clean up the terminal. You must remember to unfreeze if you want to make a change with stty
, otherwise the shell will immediately undo whatever your stty
did.
reset
does more than restore stty
modes, so you still might need it sometimes, but not often.
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
14
down vote
A console sometimes needs a reset(1)
(or some stty(1)
command) because the state of a pseudo-terminal does not change when some process (e.g. a program started by your shell) terminates.
Read the tty demystified.
(I find the handling of pseudo-terminals and pseudottys the most difficult part of Linux)
Is there a strategy how this problem is addressed in the major programming languages?
A well-behaved program dealing with the terminal and changing its mode or line discipline should try hard to avoid crashing and issue the appropriate calls (see termios(3)) to put the terminal in the right state. BTW, libraries like ncurses or readline are helpful (but you need to call their cleanup routines appropriately).
See signal(7) and signal-safety(7). Avoiding crashing in your code is difficult. Read about undefined behavior.
An imperfect workaround could be to define a shell function which runs your program then does a reset
(that could sometimes be inappropriate).
That workaround isn't great; sometimesreset
can result in differentstty
settings from the original ones.
â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I startedstty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red.stty -a > /tmp/test2
buttest1
andtest2
were exactly the same.
â Jonas Stein
Nov 12 '17 at 1:04
add a comment |Â
up vote
14
down vote
A console sometimes needs a reset(1)
(or some stty(1)
command) because the state of a pseudo-terminal does not change when some process (e.g. a program started by your shell) terminates.
Read the tty demystified.
(I find the handling of pseudo-terminals and pseudottys the most difficult part of Linux)
Is there a strategy how this problem is addressed in the major programming languages?
A well-behaved program dealing with the terminal and changing its mode or line discipline should try hard to avoid crashing and issue the appropriate calls (see termios(3)) to put the terminal in the right state. BTW, libraries like ncurses or readline are helpful (but you need to call their cleanup routines appropriately).
See signal(7) and signal-safety(7). Avoiding crashing in your code is difficult. Read about undefined behavior.
An imperfect workaround could be to define a shell function which runs your program then does a reset
(that could sometimes be inappropriate).
That workaround isn't great; sometimesreset
can result in differentstty
settings from the original ones.
â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I startedstty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red.stty -a > /tmp/test2
buttest1
andtest2
were exactly the same.
â Jonas Stein
Nov 12 '17 at 1:04
add a comment |Â
up vote
14
down vote
up vote
14
down vote
A console sometimes needs a reset(1)
(or some stty(1)
command) because the state of a pseudo-terminal does not change when some process (e.g. a program started by your shell) terminates.
Read the tty demystified.
(I find the handling of pseudo-terminals and pseudottys the most difficult part of Linux)
Is there a strategy how this problem is addressed in the major programming languages?
A well-behaved program dealing with the terminal and changing its mode or line discipline should try hard to avoid crashing and issue the appropriate calls (see termios(3)) to put the terminal in the right state. BTW, libraries like ncurses or readline are helpful (but you need to call their cleanup routines appropriately).
See signal(7) and signal-safety(7). Avoiding crashing in your code is difficult. Read about undefined behavior.
An imperfect workaround could be to define a shell function which runs your program then does a reset
(that could sometimes be inappropriate).
A console sometimes needs a reset(1)
(or some stty(1)
command) because the state of a pseudo-terminal does not change when some process (e.g. a program started by your shell) terminates.
Read the tty demystified.
(I find the handling of pseudo-terminals and pseudottys the most difficult part of Linux)
Is there a strategy how this problem is addressed in the major programming languages?
A well-behaved program dealing with the terminal and changing its mode or line discipline should try hard to avoid crashing and issue the appropriate calls (see termios(3)) to put the terminal in the right state. BTW, libraries like ncurses or readline are helpful (but you need to call their cleanup routines appropriately).
See signal(7) and signal-safety(7). Avoiding crashing in your code is difficult. Read about undefined behavior.
An imperfect workaround could be to define a shell function which runs your program then does a reset
(that could sometimes be inappropriate).
edited Nov 11 '17 at 17:47
answered Nov 11 '17 at 14:31
Basile Starynkevitch
7,9081940
7,9081940
That workaround isn't great; sometimesreset
can result in differentstty
settings from the original ones.
â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I startedstty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red.stty -a > /tmp/test2
buttest1
andtest2
were exactly the same.
â Jonas Stein
Nov 12 '17 at 1:04
add a comment |Â
That workaround isn't great; sometimesreset
can result in differentstty
settings from the original ones.
â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I startedstty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red.stty -a > /tmp/test2
buttest1
andtest2
were exactly the same.
â Jonas Stein
Nov 12 '17 at 1:04
That workaround isn't great; sometimes
reset
can result in different stty
settings from the original ones.â Bob
Nov 11 '17 at 15:25
That workaround isn't great; sometimes
reset
can result in different stty
settings from the original ones.â Bob
Nov 11 '17 at 15:25
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
Yes, thanks for pointing that out. I added "imperfect".
â Basile Starynkevitch
Nov 11 '17 at 15:35
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I started
stty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2
but test1
and test2
were exactly the same.â Jonas Stein
Nov 12 '17 at 1:04
I have read your links, they were interesting, but it would be helpfull, if you could add a pointer to a section for this Q/A each. After reading tty demystified, I started
stty -a > /tmp/test1
in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2
but test1
and test2
were exactly the same.â Jonas Stein
Nov 12 '17 at 1:04
add a comment |Â
up vote
2
down vote
Responding to this problem isn't completely shell-independent. In zsh, there is the ttyctl
builtin, which can "freeze" or "unfreeze" the tty mode. I don't think there's an equivalent in bash. The setty
command in tcsh does the same thing, but more fine-grained: you can freeze individual settings.
Freezing the tty mode just means that zsh will remember the current mode, and if some future child changes it, the mode will be restored when the child suspends or terminates.
This will protect you from some of the bad effects of programs that crash or otherwise fail to clean up the terminal. You must remember to unfreeze if you want to make a change with stty
, otherwise the shell will immediately undo whatever your stty
did.
reset
does more than restore stty
modes, so you still might need it sometimes, but not often.
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
add a comment |Â
up vote
2
down vote
Responding to this problem isn't completely shell-independent. In zsh, there is the ttyctl
builtin, which can "freeze" or "unfreeze" the tty mode. I don't think there's an equivalent in bash. The setty
command in tcsh does the same thing, but more fine-grained: you can freeze individual settings.
Freezing the tty mode just means that zsh will remember the current mode, and if some future child changes it, the mode will be restored when the child suspends or terminates.
This will protect you from some of the bad effects of programs that crash or otherwise fail to clean up the terminal. You must remember to unfreeze if you want to make a change with stty
, otherwise the shell will immediately undo whatever your stty
did.
reset
does more than restore stty
modes, so you still might need it sometimes, but not often.
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Responding to this problem isn't completely shell-independent. In zsh, there is the ttyctl
builtin, which can "freeze" or "unfreeze" the tty mode. I don't think there's an equivalent in bash. The setty
command in tcsh does the same thing, but more fine-grained: you can freeze individual settings.
Freezing the tty mode just means that zsh will remember the current mode, and if some future child changes it, the mode will be restored when the child suspends or terminates.
This will protect you from some of the bad effects of programs that crash or otherwise fail to clean up the terminal. You must remember to unfreeze if you want to make a change with stty
, otherwise the shell will immediately undo whatever your stty
did.
reset
does more than restore stty
modes, so you still might need it sometimes, but not often.
Responding to this problem isn't completely shell-independent. In zsh, there is the ttyctl
builtin, which can "freeze" or "unfreeze" the tty mode. I don't think there's an equivalent in bash. The setty
command in tcsh does the same thing, but more fine-grained: you can freeze individual settings.
Freezing the tty mode just means that zsh will remember the current mode, and if some future child changes it, the mode will be restored when the child suspends or terminates.
This will protect you from some of the bad effects of programs that crash or otherwise fail to clean up the terminal. You must remember to unfreeze if you want to make a change with stty
, otherwise the shell will immediately undo whatever your stty
did.
reset
does more than restore stty
modes, so you still might need it sometimes, but not often.
answered Nov 11 '17 at 22:11
Wumpus Q. Wumbley
4,0101120
4,0101120
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
add a comment |Â
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
Indeed: I started stty -a > /tmp/test1 in bash then a command, which I cancelled. The terminal color was now red. stty -a > /tmp/test2 but test1 and test2 were exactly the same. I tried the same with tcsh, but I could not crash my command by CTRL+C. The colors remained fine.
â Jonas Stein
Nov 12 '17 at 1:10
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f403906%2fwhy-does-the-console-need-sometimes-a-reset-after-ctrlc%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Related questions are unix.stackexchange.com/questions/401010 , unix.stackexchange.com/questions/79684 , unix.stackexchange.com/questions/164944 , unix.stackexchange.com/questions/282514 , and unix.stackexchange.com/questions/398291 just for starters. See also superuser.com/questions/1259442 .
â JdeBP
Nov 11 '17 at 16:53
stty sane
for the grey beardsâ Thorbjørn Ravn Andersen
Nov 11 '17 at 23:23