I need to grep the output of a third party program. This program dumps out data but does not terminate without pressing ^c to terminate it.
I am currently searching and killing it using its pid. However, I was wondering however if it were possible to echo the control C character. Pseudo code would look like
echo ^c | ./program_that_does_not_terminate
I am able to do something like this in DOS, so there must be a way in linux.
C:\>echo y | del C:\tmp\*
C:\tmp\*, Are you sure (Y/N)? y
C:\>
No, piping a CTRL-C character into your process won't work, because a CTRL-C keystroke is captured by the terminal and translated into a kill signal sent to the process.
The correct character code (in ASCII) for CTRL-C is code number 3 but, if you echo that to your program, it will simply receive the character from its standard input. It won't cause the process to terminate.
If you wanted to ease the task of finding and killing the process, you could use something like:
./program_that_does_not_terminate &
pid=$!
sleep 20
kill ${pid}
$!
will give you the process ID for the last started background process.
In Bash, a ^C
can be passed as an argument on the command-line (and thus passed to echo
for echoing) by writing $'\cc'
. Thus, the desired command is:
echo $'\cc' | ./program_that_does_not_terminate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With