CooCooWakka : KillProcess

首页 :: 索引 :: 修订历史 :: 最新评论 :: CooCooWakkaGroup :: 登陆/注册 :: 你好, 38.103.63.62
你的足迹: » KillProcess
分类: » 类别索引 » Linux

Killing Processes


This week we show you some interesting ways to kill stubborn processes. Never let it be said that you can't kill a process again! The first way is the old boring way that most people probably use. Use the command ps aux, look through the process list until you find the PID you want and issue the kill command. How tedious!

Alternatively, try using the killall command which will automatically kill a program based on its name.

Code listing 9.1

  # killall mozilla-bin

But what if you only know part of the name? Well, you could combine ps with grep, kill and awk to produce something like this.

Code listing 9.2

  # ps aux | grep mozilla | awk '{print $2}' | xargs kill

But, there's a far simpler way. Enter pkill and the closely related pgrep. These commands are part of the sys-apps/procps package and are designed to search for (or kill) running processes. So the previous command could be replaced with the following:

Code listing 9.3

  # pkill mozilla

Note: To list the PIDs instead of killing them, use pgrep.

Finally, what if you have a runaway process hogging /dev/dsp, or some other file/socket? You can use fuser, which displays the PIDs of process using a specified file or filesystem. Or give it the -k option, like this, and you can easily kill those processes:

Code listing 9.4

  # fuser -k /dev/dsp
当前页面没有留言.[显示留言板]

SourceForge.net Logo Creative Commons License
请享受共创成果的同时,尊重他人劳动。本站点内容如未特别声明,全部遵循 Creative Commons License by-nc-sa协议发布。