wait_pid 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
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
@@ -0,0 +1,9 @@
1
+ require 'wait_pid'
2
+
3
+ if ARGV.include?('-h') || ARGV.include?('--help') || ARGV.length == 0
4
+ puts "syntax: pid"
5
+ exit
6
+ end
7
+
8
+ raise 'only one pid currently supported' if ARGV.length > 1
9
+ WaitPid.wait_pid ARGV[0].to_i
data/bin/wait_pid~ ADDED
@@ -0,0 +1,8 @@
1
+ require 'wait_pid'
2
+
3
+ if ARGV.include?('-h') || ARGV.include('--help')
4
+ puts "syntax: pid"
5
+ exit
6
+ end
7
+
8
+ WaitPid.wait_pid ARGV[0].to_i
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