开发者

Bash: How do I stop bash from mindlessly writing millions of lines to console once it has begun?

I do this way too often it is kind of embarrassing. Regardless, possibly we can put an end to this once and for all? I just grepped a log file for a mysterious ip that apparently is on every line (it turns out it is the ip for the server itself! myst开发者_运维知识库ery solved). It turns out this file has millions of lines. Actually I just checked and it is still going.

Any way to stop this madness?


why don't you pipe the result to more.. this way the results are paged & you can quit by pressing CTRL+C.

your command would be cat someFile.log | grep someIP | more


As others have said, use CTRL+C to interrupt. If for some reason this isn't working for you, open another terminal or console session on the same box and issue this command:

ps -o pid=,args= -C grep

This will list the Process ID (PID) if each currently running grep command. Find the one which corresponds to the one you want to kill and then execute the following commands in sequence, checking after each whether the process has terminated.

kill -INT $PID
kill -TERM $PID
kill -QUIT $PID
kill -SEGV $PID
kill -KILL $PID

Where $PID is the Process ID you identified above.

Note that -C is a GNU ps extension and may not be supported by other ps implementations. If that's the case for you then something like the following might be required:

ps -o pid= -o comm= -o args= | awk '$2~/grep/{print $1, $3}'

Which is essentially the same.


Just hit ctrl-c (with keyboard focus in the terminal in question) to kill the process. Closing the terminal tends to work too, but isn't so clean.


CTRL+C should do the trick. It sends SIGINT to the process.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜