tasks 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/tasks.rb +17 -0
  2. metadata +2 -2
data/lib/tasks.rb CHANGED
@@ -33,4 +33,21 @@ module Tasks
33
33
  rescue Errno::ESRCH
34
34
  Process.kill "KILL", slave
35
35
  end
36
+
37
+ # Kills a process's all children
38
+ # require 'lib/tasks'; include Tasks
39
+ # pid = spawn 'sleep 10 | head'
40
+ # kill_children(pid)
41
+ #
42
+ # system 'ps aux | grep slee'
43
+ def kill_children(parent_pid)
44
+ a = `ps ax -o pid,command,ppid`.split(/\n/)[1..-1]
45
+ pss = a.map {|i| i.strip.split(/\s+/, 3) }.select {|i| i[1].to_i == parent_pid }.map {|i| i[0] }
46
+ pss.each {|i|
47
+ begin
48
+ Process.kill 'KILL', i.to_i
49
+ rescue Errno::ESRCH => e
50
+ end
51
+ }
52
+ end
36
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.1"
4
+ version: "1.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - ujihisa
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-01 00:00:00 +09:00
12
+ date: 2010-01-01 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15