- 论坛徽章:
- 0
|
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. |
|