OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # | |
3 # $Id: killall.py 1143 2011-10-05 19:11:59Z g.rodola $ | |
4 # | |
5 # Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved. | |
6 # Use of this source code is governed by a BSD-style license that can be | |
7 # found in the LICENSE file. | |
8 | |
9 """ | |
10 Kill a process by name. | |
11 """ | |
12 | |
13 import os | |
14 import sys | |
15 import psutil | |
16 | |
17 def main(): | |
18 if len(sys.argv) != 2: | |
19 sys.exit('usage: %s name' % __file__) | |
20 else: | |
21 NAME = sys.argv[1] | |
22 | |
23 killed = [] | |
24 for proc in psutil.process_iter(): | |
25 if proc.name == NAME and proc.pid != os.getpid(): | |
26 proc.kill() | |
27 killed.append(proc.pid) | |
28 if not killed: | |
29 sys.exit('%s: no process found' % NAME) | |
30 else: | |
31 sys.exit(0) | |
32 | |
33 sys.exit(main()) | |
OLD | NEW |