By mistake I ran a funny command today that looks like vi filename | vi - . It made my terminal stuck even Ctrl-C was of no use. I had to close the terminal only. I tried it a couple of times and tried on my friend machine too. Just wondering why Ctrl-C was also not able to help.
3 Answers
vi is reading from stdin.
When you edit in vi Ctrl+c does not work either.
To quit vi use :q or :q! will work like in a normal vi session.
1 Comment
plaes
Thank you! I sometimes manage to call
vim file | foo and this seems to also hang the terminal.Using the POSIX function signal() a C program can choose what to do if there is a keyboard interrupt.
Here is an example (copied from this site):
#include <stdio.h> #include <stdlib.h> #include <signal.h> FILE *temp_file; void leave(int sig); main() { (void) signal(SIGINT, leave); temp_file = fopen("tmp", "w"); for(;;) { /* * Do things.... */ printf("Ready...\n"); (void)getchar(); } /* cant get here ... */ exit(EXIT_SUCCESS); } /* * on receipt of SIGINT, close tmp file */ void leave(int sig) { fprintf(temp_file,"\nInterrupted..\n"); fclose(temp_file); exit(sig); } But as you can see, vi doesn't use the keyboard interrupt to exit. It doesn't matter whether you are using it in a pipe or not.