kill和killall的区别

In order to know the difference between kill and killall commands we first need to make sure that we understand the basics behind processes on the Linux system. Process is an instance of a running program. Each process is assigned PID ( Process ID ) which is unique for each process and therefore, no two processes can be assigned same PID. Once the process is terminated the PID is available for reuse. Try the following example:
$ yes > /dev/null &
[1] 3706
The command above will start process syes  and output its standard output to /dev/null . What we are interested in here, is the second line which contains the following information "[1]" ( job ID ) and "3706" the actual PID. On your Linux system you can run multiple process at any given time and each process, depending on the user privileges can be terminated using either kill or killall commands. Let's start few additional processes:
$ yes > /dev/null &
[2] 3782
$ yes > /dev/null &
[3] 3783
$ yes > /dev/null &
[4] 3784
$ yes > /dev/null &
[5] 3785
From the above you can see that we have started additional processes using yes  command and that each process have different PID. To list all you processes forked from the current shell use jobs  command:
$ jobs
[1]   Running                 yes > /dev/null &
[2]   Running                 yes > /dev/null &
[3]   Running                 yes > /dev/null &
[4]-  Running                 yes > /dev/null &
[5]+  Running                 yes > /dev/null &

The difference between kill vs killall commands is that with kill command we can terminate only a single process at the time, whereas with killall command we are able to terminated multiple processes based on given criteria such as process group, process age or user ownership. Let's use kill  command to kill process with PID 3783:
$ kill 3783
[3]   Terminated              yes > /dev/null
Terminating each process one by one can prove to be a hard and tedious work. Let's see whether we can get some help by using killall command and process name:
$ killall yes
[1]   Terminated              yes > /dev/null
[2]   Terminated              yes > /dev/null
[4]-  Terminated              yes > /dev/null
[5]+  Terminated              yes > /dev/null
As you can see all processes were terminated based on the process name.

转载于:https://my.oschina.net/uniquejava/blog/472723

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值