博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kill和killall的区别
阅读量:6567 次
发布时间:2019-06-24

本文共 2314 字,大约阅读时间需要 7 分钟。

hot3.png

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

你可能感兴趣的文章
我设计的网站的分布式架构
查看>>
linux extract rar files
查看>>
Knockout.Js官网学习(监控属性Observables)
查看>>
ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务解决
查看>>
azure之MSSQL服务性能测试
查看>>
Android BitmapFactory.Options
查看>>
前端构建:Less入了个门
查看>>
phonegap(cordova) 自己定义插件代码篇(三)----支付宝支付工具整合
查看>>
linux 批量进行:解压缩某一类压缩文件类型的文件
查看>>
激活modelsim se 10.4 时运行patch_dll.bat不能生成TXT
查看>>
17秋 软件工程 Alpha 事后诸葛亮会议
查看>>
线性空间
查看>>
疑似checkpoint堵塞数据库连接
查看>>
Node.js中针对中文的查找和替换无效的解决方法
查看>>
理解指针的关键
查看>>
如何查看Ubuntu下已安装包版本号
查看>>
我的那些年(2)~我毕业了
查看>>
VS2017 配置ImageMagick
查看>>
Hive任务优化--控制hive任务中的map数和reduce数
查看>>
[摄影]上海往事
查看>>