wait_pid 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.rdoc +16 -0
- data/Rakefile +12 -0
- data/VERSION +1 -0
- data/bin/wait_pid +9 -0
- data/bin/wait_pid~ +8 -0
- data/lib/wait_pid.rb +23 -0
- data/spec/spec.wait_pid.rb +41 -0
- metadata +72 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
= wait_pid
|
2
|
+
|
3
|
+
This provides a ruby library
|
4
|
+
|
5
|
+
WaitPid.wait_pid pid_number # waits until that process exits
|
6
|
+
|
7
|
+
and also a binary command
|
8
|
+
|
9
|
+
$ wait_pid pid_number # waits until that process exits
|
10
|
+
|
11
|
+
Currently it just polls 100 times/s to see if the process is still around. If more granularity is needed let me know [it is possible, at least in windows, or a higher polling capability could be made optional in linux].
|
12
|
+
|
13
|
+
Enjoy. Feedback welcome.
|
14
|
+
|
15
|
+
http://github.com/rdp/wait_pid
|
16
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "wait_pid"
|
5
|
+
gem.summary = %Q{the wait_pid command -- (ruby gem/binary for waiting on an arbitrary external pid, doze/linux supported)}
|
6
|
+
gem.email = "rogerpack2005@gmail.com"
|
7
|
+
gem.homepage = "http://github.com/rdp/wait_pid"
|
8
|
+
gem.authors = ["rdp"]
|
9
|
+
gem.add_development_dependency 'sane'
|
10
|
+
|
11
|
+
end
|
12
|
+
Jeweler::GemcutterTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/bin/wait_pid
ADDED
data/bin/wait_pid~
ADDED
data/lib/wait_pid.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
class WaitPid
|
3
|
+
|
4
|
+
def self.wait_pid(pid, test = false)
|
5
|
+
# initial test
|
6
|
+
count = 0
|
7
|
+
begin
|
8
|
+
loop { Process.kill( 0, pid); count += 1; sleep 0.01}
|
9
|
+
rescue Errno::ESRCH
|
10
|
+
if count == 0
|
11
|
+
if test
|
12
|
+
return "non existing"
|
13
|
+
else
|
14
|
+
puts "warning: pid not found #{pid}" if $VERBOSE
|
15
|
+
end
|
16
|
+
else
|
17
|
+
# normal
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
2
|
+
require 'spec/autorun'
|
3
|
+
require 'sane'
|
4
|
+
require_rel '../lib/wait_pid'
|
5
|
+
|
6
|
+
|
7
|
+
def spawn command # should return a pid
|
8
|
+
if RUBY_VERSION < '1.9'
|
9
|
+
if OS.linux?
|
10
|
+
fork { system(command) }
|
11
|
+
else
|
12
|
+
raise 'todo'
|
13
|
+
end
|
14
|
+
else
|
15
|
+
Process.spawn command
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "wait pid" do
|
20
|
+
|
21
|
+
it "should warn if a pid doesn't exist" do
|
22
|
+
out = WaitPid.wait_pid 1234, true
|
23
|
+
out.should be_a(String)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should work without a second argument" do
|
27
|
+
WaitPid.wait_pid 1234
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should wait on a pid" do
|
31
|
+
a = spawn 'ruby -e "sleep 1"'
|
32
|
+
Thread.new { Process.wait a } # gotta wait for it, or, as child, it never "really" ends in terms of sig 0
|
33
|
+
start = Time.now
|
34
|
+
WaitPid.wait_pid(a)
|
35
|
+
assert(Time.now - start > 0.5)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to wait on more than one pid"
|
39
|
+
it "should be able to optionally output when each of those several dies"
|
40
|
+
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wait_pid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rdp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sane
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: rogerpack2005@gmail.com
|
27
|
+
executables:
|
28
|
+
- wait_pid
|
29
|
+
- wait_pid~
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- README.rdoc
|
38
|
+
- Rakefile
|
39
|
+
- VERSION
|
40
|
+
- bin/wait_pid
|
41
|
+
- lib/wait_pid.rb
|
42
|
+
- spec/spec.wait_pid.rb
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: http://github.com/rdp/wait_pid
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --charset=UTF-8
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
version:
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.3.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: the wait_pid command -- (ruby gem/binary for waiting on an arbitrary external pid, doze/linux supported)
|
71
|
+
test_files:
|
72
|
+
- spec/spec.wait_pid.rb
|