免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1258 | 回复: 1
打印 上一主题 下一主题

[学习分享] 高手来看看这怎么做 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-02-24 11:12 |只看该作者 |正序浏览
Assignment specifications: Your assignment is to write a script, called "KillByName", that kills all processes associated with a given name.

To turn in your assignment and get credit, your script must:
1. Behave according to the specifications
2. Have the name KillByName
3. Be turned in using the turnin command

If the name given is a login or User ID (UID), you need to kill all processes owned by that user. If the name given is a parent process ID, you need to kill the child processes first before killing the parent. If the name given is an executable, you need to kill all processes with that name.

You should "grep" the command line looking from processes associated with the name entered. Any processes found matching should be entered into one of two lists: one is the list of child processes, and the other is the list of parent processes. This more easily allows you to kill children and then their parents.

For simplicity and because of the bash shell.s ubiquity, write your shell script for bash.

The script should have the following options to be specified on the command line:

The graceful kill option (-g): If the user runs your script with the -g flag, your script should only attempt to kill processes using kill, and should not attempt to use "kill -9". This means that if any process traps signal 15, the default signal sent out by kill, that process should not be killed immediately by your script when run with this option. Note that if the "-g flag" is not present, then your script should first attempt to kill processes using just kill and, if they are still alive, you should then proceed to use kill -9.

The delay option (-d): If the -d flag is used, it should be followed by an integer (the number of seconds) that the script should wait before attempting to kill the processes. When you.re finished, you should be able to call your script in the following way:

./KillByName [-g] [-d #] name_associated_with_process

The options are in [brackets] to denote that they are optional, i.e. you can run it literally like:

./KillByName -d 5 deadInFive
./KillByName -g killMeSoftly

Your script should detect an illegal usage of your script's options on the command line. For example, if a user typed...

./KillByName -g

your script should print out an error message explaining the appropriate usage of your script. If there are no processes by the given name, your script should NOT print out any kind of error message. Instead it should exit with an exit status of 1. On the other hand, if the specified processes are successfully killed, then your script should exit with an exit status of 0.

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
2 [报告]
发表于 2013-02-24 21:09 |只看该作者
马上要开学了才想起要做寒假作业?
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP