回声对照C字 [英] Echo Control C character

查看:111
本文介绍了回声对照C字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要到grep第三方程序的输出。这个程序转储出的数据,但没有pressing ^ C不会终止终止它。

我目前搜索和使用它的PID杀死它。不过,我在想,但是如果有可能呼应的控制组C字符。伪code看起来像

 回声^ C | ./program_that_does_not_terminate

我能够做这样的事在DOS下,所以必须有在Linux的方式。

  C:\\>回声Y |德尔C:\\ tmp目录\\ *。
C:\\ tmp目录\\ *,是否确定(Y / N)? ÿ
C:\\>


解决方案

没有,管道一CTRL-C字符到你的进程将无法正常工作,因为CTRL-C击键被的终端抓获并转化为发送到进程kill信号。

正确的字符code(ASCII格式)为CTRL-C是code 3号,但如果你呼应,为你的程序,它只会收到从标准输入的字符。它不会导致进程终止。

如果你想找到轻松和杀害过程的任务,您可以使用类似:

  ./ program_that_does_not_terminate&安培;
PID = $!
睡眠20
杀$ {} PID

$!会给你进程ID是上次启动的后台进程。

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.

这篇关于回声对照C字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆