~ubuntu-branches/ubuntu/trusty/abs-guide/trusty-proposed

« back to all changes in this revision

Viewing changes to kill-process.sh

  • Committer: Package Import Robot
  • Author(s): Sandro Tosi
  • Date: 2012-06-03 10:57:27 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20120603105727-rm7frl4feikr2swm
Tags: 6.5-1
* New upstream release
* debian/watch
  - updated
* debian/abs-guide.lintian-overrides
  - updated for new upstream code
* debian/control
  - bump Standards-Version to 3.9.3 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# kill-process.sh
 
3
 
 
4
NOPROCESS=2
 
5
 
 
6
process=xxxyyyzzz  # Use nonexistent process.
 
7
# For demo purposes only...
 
8
# ... don't want to actually kill any actual process with this script.
 
9
#
 
10
# If, for example, you wanted to use this script to logoff the Internet,
 
11
#     process=pppd
 
12
 
 
13
t=`pidof $process`       # Find pid (process id) of $process.
 
14
# The pid is needed by 'kill' (can't 'kill' by program name).
 
15
 
 
16
if [ -z "$t" ]           # If process not present, 'pidof' returns null.
 
17
then
 
18
  echo "Process $process was not running."
 
19
  echo "Nothing killed."
 
20
  exit $NOPROCESS
 
21
fi  
 
22
 
 
23
kill $t                  # May need 'kill -9' for stubborn process.
 
24
 
 
25
# Need a check here to see if process allowed itself to be killed.
 
26
# Perhaps another " t=`pidof $process` " or ...
 
27
 
 
28
 
 
29
# This entire script could be replaced by
 
30
#        kill $(pidof -x process_name)
 
31
# or
 
32
#        killall process_name
 
33
# but it would not be as instructive.
 
34
 
 
35
exit 0