proc-wait3 1.9.0 → 1.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +10 -0
- data/Gemfile +2 -7
- data/MANIFEST.md +1 -1
- data/README.md +38 -4
- data/Rakefile +7 -4
- data/doc/wait3.md +225 -0
- data/examples/example_getrusage.rb +5 -3
- data/examples/example_pause.rb +8 -6
- data/examples/example_wait3.rb +5 -2
- data/examples/example_wait4.rb +5 -2
- data/examples/example_waitid.rb +5 -2
- data/ext/extconf.rb +8 -16
- data/ext/proc/wait3.c +51 -39
- data/lib/proc-wait3.rb +2 -0
- data/proc-wait3.gemspec +12 -8
- data/spec/proc_wait3_spec.rb +107 -91
- data.tar.gz.sig +0 -0
- metadata +35 -5
- metadata.gz.sig +0 -0
- data/doc/wait3.txt +0 -192
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6e56b25dc085ce18c5808a81d259c4e9f54cb75d1ff985985bb5a575d58ed90
|
4
|
+
data.tar.gz: 65379d28529797369401cc65abb6c234b9cf1995ec7cf92152d03c03c6a89a83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f2d1148e8fcadb8b9530420ac164e81b4645b04e3f7b8acded43a62acaa3000240f5e5e53b5fda4cc734f0e2f76edbf76d5b325c2cc3fefd450cf0f60ca519
|
7
|
+
data.tar.gz: ce1e71899e8db9c2c74bb5207d3a715e7cf8b355d0c5b6bc203b51608647d90fe53c0414bce48ee38c1c796987df7f9fa2b4a30c9eeebdd35900e34d288be82a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.9.2 - 21-Apr-2024
|
2
|
+
* Added the P_JAILID constant for BSD platforms.
|
3
|
+
* Added some notes to the README for coping with EINTR.
|
4
|
+
* Added rubocop and rubocop-rspec as dev dependencies and did
|
5
|
+
some general rubocop cleanup.
|
6
|
+
|
7
|
+
## 1.9.1 - 8-Feb-2024
|
8
|
+
* Replace sigset with sigaction in the pause method.
|
9
|
+
* General cleanup and platform handling updates.
|
10
|
+
|
1
11
|
## 1.9.0 - 7-Jan-2021
|
2
12
|
* Switched from test-unit to rspec.
|
3
13
|
* Skip some tests on Darwin because of EINTR errors.
|
data/Gemfile
CHANGED
data/MANIFEST.md
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://github.com/djberg96/proc-wait3/actions/workflows/ruby.yml)
|
2
|
+
|
1
3
|
## Description
|
2
4
|
Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the Process module.
|
3
5
|
|
@@ -32,9 +34,41 @@ Linux users may also notice warnings about implicit declarations. These
|
|
32
34
|
are also harmless, and can be silenced by installing the libbsd-dev package
|
33
35
|
first.
|
34
36
|
|
35
|
-
|
36
|
-
the WNOHANG flag
|
37
|
-
|
37
|
+
These methods may fail in conjunction with `fork` with `Errno::EINTR` unless
|
38
|
+
you pass the WNOHANG flag, or explicitly ignore the `SIGCHLD` signal. Ruby's
|
39
|
+
own `wait` methods appear to essentially be doing that behind the scenes.
|
40
|
+
|
41
|
+
Note that on some platforms just setting a `SIGCHLD` handler may not be
|
42
|
+
enough to prevent an `Errno::EINTR` from occuring since you can never be sure
|
43
|
+
what signal it's going to receive. Since this appears to be coming from the
|
44
|
+
guts of the Ruby core code itself IMO, it's somewhat out of my hands, but it's
|
45
|
+
not impossible to deal with.
|
46
|
+
|
47
|
+
A typical idiom would be to simulate the `TEMP_FAILURE_RETRY` macro that the GNU
|
48
|
+
library provides. This macro wraps a given function and retries it so long as
|
49
|
+
it doesn't fail, or the only failure is an `EINTR`. I've chosen not to integrate
|
50
|
+
this into the code directly (yet), but you can simulate it like so:
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
require 'English'
|
54
|
+
|
55
|
+
begin
|
56
|
+
pid = fork{ sleep 1; exit 2 }
|
57
|
+
Process.wait3
|
58
|
+
rescue Errno::EINTR
|
59
|
+
retry
|
60
|
+
end
|
61
|
+
|
62
|
+
p $CHILD_STATUS
|
63
|
+
```
|
64
|
+
|
65
|
+
For more information please see:
|
66
|
+
|
67
|
+
https://www.gnu.org/savannah-checkouts/gnu/libc/manual/html_node/Interrupted-Primitives.html
|
68
|
+
|
69
|
+
BSD provides another approach using sigaction handlers + `SA_RESTART`, but it requires knowing
|
70
|
+
the signal type in advance. So, unless you want to apply the same handler to *every* type of
|
71
|
+
signal, I don't find it especially useful.
|
38
72
|
|
39
73
|
## Integration with Ruby's process.c
|
40
74
|
I considered simply providing a patch to the core process.c file, but I
|
@@ -50,4 +84,4 @@ trouble of typing the word "status", since all they're for is comparing or
|
|
50
84
|
operating on the status attribute.
|
51
85
|
|
52
86
|
## Additional Documentation
|
53
|
-
Please see the doc/wait3.
|
87
|
+
Please see the doc/wait3.md file for detailed documentation.
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rspec/core/rake_task'
|
4
|
+
require 'rubocop/rake_task'
|
4
5
|
require 'fileutils'
|
5
6
|
require 'rbconfig'
|
6
7
|
include RbConfig
|
@@ -27,15 +28,15 @@ task :build => [:clean] do |t|
|
|
27
28
|
end
|
28
29
|
|
29
30
|
namespace :gem do
|
30
|
-
desc
|
31
|
+
desc 'Create the proc-wait3 gem'
|
31
32
|
task :create => [:clean] do
|
32
33
|
require 'rubygems/package'
|
33
|
-
spec =
|
34
|
+
spec = Gem::Specification.load('proc-wait3.gemspec')
|
34
35
|
spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
|
35
36
|
Gem::Package.build(spec)
|
36
37
|
end
|
37
38
|
|
38
|
-
desc
|
39
|
+
desc 'Install the proc-wait3 gem'
|
39
40
|
task :install => [:create] do |t|
|
40
41
|
file = Dir['*.gem'].first
|
41
42
|
sh "gem install -l #{file}"
|
@@ -69,9 +70,11 @@ namespace :example do
|
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
desc
|
73
|
+
desc 'Run the test suite'
|
73
74
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
74
75
|
t.rspec_opts = '-Iext'
|
75
76
|
end
|
76
77
|
|
77
78
|
task :default => [:build, :spec]
|
79
|
+
|
80
|
+
RuboCop::RakeTask.new
|
data/doc/wait3.md
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
## Description
|
2
|
+
Adds the `wait3`, `wait4`, `waitid`, `pause`, `sigsend`, and `getrusage`
|
3
|
+
methods to the Process module.
|
4
|
+
|
5
|
+
## Synopsis
|
6
|
+
```ruby
|
7
|
+
require 'proc/wait3'
|
8
|
+
|
9
|
+
pid = fork{ sleep 1; exit 2 }
|
10
|
+
p Time.now
|
11
|
+
Process.wait3
|
12
|
+
p $?
|
13
|
+
```
|
14
|
+
|
15
|
+
## Module Methods
|
16
|
+
### `Process.pause(signals=nil)`
|
17
|
+
|
18
|
+
Pauses the current process. If the process receives any of the signals
|
19
|
+
you pass as arguments it will return from the pause and continue with
|
20
|
+
the execution of your code. Otherwise, it will exit.
|
21
|
+
|
22
|
+
Note that you must leave out the 'SIG' prefix for the signal name, e.g.
|
23
|
+
use 'INT', not 'SIGINT'.
|
24
|
+
|
25
|
+
Returns the result of the underlying `pause()` function, which should always be -1.
|
26
|
+
|
27
|
+
### `Process.sigsend(idtype, id, signal=0)`
|
28
|
+
|
29
|
+
Sends a signal of type "idtype" to a process or process group "id". This
|
30
|
+
is more versatile method of sending signals to processes than Process.kill.
|
31
|
+
|
32
|
+
For a list of valid idtype values, see the "Process type constants" below.
|
33
|
+
Not supported on all platforms.
|
34
|
+
|
35
|
+
### `Proc.wait3(flags=0)`
|
36
|
+
|
37
|
+
Delays its caller until a signal is received or one of its child processes
|
38
|
+
terminates or stops due to tracing.
|
39
|
+
|
40
|
+
The return value is a ProcStat structure and sets the `$last_status` global
|
41
|
+
variable. The special global $? is also set. Raises a SystemError if there
|
42
|
+
are no child processes.
|
43
|
+
|
44
|
+
### `Proc.wait4(pid, flags=0)`
|
45
|
+
|
46
|
+
Waits for the given child process to exit. Returns a ProcStat structure.
|
47
|
+
The `$last_status` global variable is set. Also sets the `$?` special global
|
48
|
+
variable.
|
49
|
+
|
50
|
+
### `Proc.waitid(id_type, id_num=nil, options=nil)`
|
51
|
+
|
52
|
+
Suspends the calling process until one of its children changes state,
|
53
|
+
returning immediately if a child process changed state prior to the call.
|
54
|
+
The state of a child process will change if it terminates, stops because
|
55
|
+
of a signal, becomes trapped or reaches a breakpoint.
|
56
|
+
|
57
|
+
The `id_num` corresponds to a process ID or process group ID, depending on
|
58
|
+
the value of `id_type`, which may be `Process::P_PID`, `Process::P_PGID` or
|
59
|
+
`Process::P_ALL`. If `id_type` is `Process::P_ALL`, then the `id_num` is ignored.
|
60
|
+
|
61
|
+
The options argument is used to specify which state changes are to be
|
62
|
+
waited for. It is constructed from the bitwise-OR of one or more of the
|
63
|
+
following constants:
|
64
|
+
|
65
|
+
* Process::WCONTINUED
|
66
|
+
* Process::WEXITED
|
67
|
+
* Process::WNOHANG
|
68
|
+
* Process::WNOWAIT
|
69
|
+
* Process::WSTOPPED
|
70
|
+
* Process::WTRAPPED (not supported on all platforms)
|
71
|
+
|
72
|
+
If `Process::WNOHANG` is set as an option, this method will return
|
73
|
+
immediately, whether or not a child has changed state.
|
74
|
+
|
75
|
+
Calling this method with an `id_type` of `Process::P_ALL` and the options set
|
76
|
+
to `Process::EXITED | Process::WTRAPPED` is equivalent to calling
|
77
|
+
Process.wait.
|
78
|
+
|
79
|
+
Returns a `Proc::SigInfo` struct and sets `$?`.
|
80
|
+
|
81
|
+
Not supported on all platforms.
|
82
|
+
|
83
|
+
## Standard Constants
|
84
|
+
`Process::WAIT3_VERSION`
|
85
|
+
|
86
|
+
Returns the version of this package as a string.
|
87
|
+
|
88
|
+
## Process type constants - all platforms
|
89
|
+
`Process::P_ALL`
|
90
|
+
|
91
|
+
All non-system process.
|
92
|
+
|
93
|
+
`Process::P_PID`
|
94
|
+
|
95
|
+
A standard process id.
|
96
|
+
|
97
|
+
`Process::P_PGID`
|
98
|
+
|
99
|
+
Any non-system process group id.
|
100
|
+
|
101
|
+
## Process type constants - not all platforms supported
|
102
|
+
`Process::P_CID`
|
103
|
+
|
104
|
+
A scheduler process id.
|
105
|
+
|
106
|
+
`Process::P_GID`
|
107
|
+
|
108
|
+
Any non-system effective process group id.
|
109
|
+
|
110
|
+
`Process::P_PROJID`
|
111
|
+
|
112
|
+
A project process id. Solaris 8 or later only.
|
113
|
+
|
114
|
+
`Process::P_SID`
|
115
|
+
|
116
|
+
A session process id.
|
117
|
+
|
118
|
+
`Process::P_TASKID`
|
119
|
+
|
120
|
+
A task process id. Solaris 8 or later only.
|
121
|
+
|
122
|
+
`Process::P_UID`
|
123
|
+
|
124
|
+
Any non-system effective process user id.
|
125
|
+
|
126
|
+
## Additional Process constants - defined if waitid is defined on your system
|
127
|
+
`Process::WCONTINUED`
|
128
|
+
|
129
|
+
Return the status for any child that was stopped and has been continued.
|
130
|
+
|
131
|
+
`Process::WEXITED`
|
132
|
+
|
133
|
+
Wait for process(es) to exit.
|
134
|
+
|
135
|
+
`Process::WNOWAIT`
|
136
|
+
|
137
|
+
Keep the process in a waitable state.
|
138
|
+
|
139
|
+
`Process::WSTOPPED`
|
140
|
+
|
141
|
+
Wait for and return the process status of any child that has stopped upon
|
142
|
+
receipt of a signal.
|
143
|
+
|
144
|
+
`Process::WTRAPPED`
|
145
|
+
|
146
|
+
Wait for traced process(es) to become trapped or reach a breakpoint.
|
147
|
+
|
148
|
+
Not supported on all platforms.
|
149
|
+
|
150
|
+
## RLIMIT constants
|
151
|
+
`Process::RLIMIT_AS`
|
152
|
+
|
153
|
+
A synonym for `RLIMIT_VMEM`.
|
154
|
+
|
155
|
+
`Process::RLIMIT_CORE`
|
156
|
+
|
157
|
+
The maximum size of a core file, in bytes, that may be created.
|
158
|
+
|
159
|
+
`Process::RLIMIT_CPU`
|
160
|
+
|
161
|
+
The maximum amount of CPU time, in seconds, the process is allowed to use.
|
162
|
+
|
163
|
+
`Process::RLIMIT_DATA`
|
164
|
+
|
165
|
+
The maximum size of the process' heap size, in bytes.
|
166
|
+
|
167
|
+
`Process::RLIMIT_FSIZE`
|
168
|
+
|
169
|
+
The maximum size of a file, in bytes, that the process may create.
|
170
|
+
|
171
|
+
`Process::RLIMIT_NOFILE`
|
172
|
+
|
173
|
+
The maximum value that the kernel may assign to a file descriptor,
|
174
|
+
effectively limiting the number of open files for the calling process.
|
175
|
+
|
176
|
+
`Process::RLIMIT_STACK`
|
177
|
+
|
178
|
+
The maximum size of the process' stack in bytes.
|
179
|
+
|
180
|
+
`Process::RLIMIT_VMEM`
|
181
|
+
|
182
|
+
The maximum size of the process' mapped address space.
|
183
|
+
|
184
|
+
`Process::RLIM_INFINITY`
|
185
|
+
|
186
|
+
A infinite limit.
|
187
|
+
|
188
|
+
`Process::RLIM_SAVED_CUR`
|
189
|
+
|
190
|
+
Current soft limit.
|
191
|
+
|
192
|
+
`Process::RLIM_SAVED_MAX`
|
193
|
+
|
194
|
+
Current hard limit.
|
195
|
+
|
196
|
+
## Notes
|
197
|
+
The `wait3` and `wait4` methods are similar to the `wait2` and `waitpid2`
|
198
|
+
methods, except that they return much more information via the rusage
|
199
|
+
struct.
|
200
|
+
|
201
|
+
## Future Plans
|
202
|
+
Wrap the wait6 function, and add better BSD support in general.
|
203
|
+
|
204
|
+
## Known Bugs
|
205
|
+
None that I'm aware of. Please log any bugs on the Github project
|
206
|
+
page at https://github.com/djberg96/proc-wait3.
|
207
|
+
|
208
|
+
## License
|
209
|
+
Apache-2.0
|
210
|
+
|
211
|
+
## Copyright
|
212
|
+
(C) 2003-2024 Daniel J. Berger
|
213
|
+
|
214
|
+
All Rights Reserved.
|
215
|
+
|
216
|
+
## Warranty
|
217
|
+
This package is provided "as is" and without any express or
|
218
|
+
implied warranties, including, without limitation, the implied
|
219
|
+
warranties of merchantability and fitness for a particular purpose.
|
220
|
+
|
221
|
+
## Author
|
222
|
+
Daniel J. Berger
|
223
|
+
|
224
|
+
## See also
|
225
|
+
wait3, wait4, waitid, pause, sigsend
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
########################################################################
|
2
4
|
# example_getrusage.rb
|
3
5
|
#
|
@@ -11,7 +13,7 @@ require 'pp'
|
|
11
13
|
|
12
14
|
# Show resource stats for this process for 30 seconds
|
13
15
|
10.times do
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
pp Process.getrusage
|
17
|
+
puts '=' * 50
|
18
|
+
sleep 3
|
17
19
|
end
|
data/examples/example_pause.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#######################################################################
|
2
4
|
# example_pause.rb
|
3
5
|
#
|
@@ -9,13 +11,13 @@
|
|
9
11
|
require 'rbconfig'
|
10
12
|
require 'proc/wait3'
|
11
13
|
|
12
|
-
puts
|
14
|
+
puts 'Pausing. Hit Ctrl-C to continue.'
|
13
15
|
|
14
|
-
if
|
15
|
-
|
16
|
+
if RbConfig::CONFIG['host_os'] =~ /linux|darwin/i
|
17
|
+
Process.pause(2)
|
16
18
|
else
|
17
|
-
|
19
|
+
Process.pause('INT')
|
18
20
|
end
|
19
21
|
|
20
|
-
puts
|
21
|
-
puts
|
22
|
+
puts 'Hey, thanks for hitting Ctrl-C. Continuing...'
|
23
|
+
puts 'Done'
|
data/examples/example_wait3.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#######################################################################
|
2
4
|
# example_wait3.rb
|
3
5
|
#
|
@@ -6,10 +8,11 @@
|
|
6
8
|
#
|
7
9
|
# Modify as you see fit.
|
8
10
|
#######################################################################
|
11
|
+
require 'English'
|
9
12
|
require 'proc/wait3'
|
10
13
|
|
11
|
-
pid = fork{ sleep 1; exit 2 }
|
14
|
+
pid = fork { sleep 1; exit 2 }
|
12
15
|
|
13
16
|
p Time.now
|
14
17
|
Process.wait3
|
15
|
-
p
|
18
|
+
p $CHILD_STATUS
|
data/examples/example_wait4.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#######################################################################
|
2
4
|
# example_wait4.rb
|
3
5
|
#
|
@@ -6,9 +8,10 @@
|
|
6
8
|
#
|
7
9
|
# Modify as you see fit.
|
8
10
|
#######################################################################
|
11
|
+
require 'English'
|
9
12
|
require 'proc/wait3'
|
10
13
|
|
11
|
-
pid = fork{ sleep 2 }
|
14
|
+
pid = fork { sleep 2 }
|
12
15
|
p Time.now
|
13
16
|
Process.wait4(pid, Process::WUNTRACED)
|
14
|
-
p
|
17
|
+
p $CHILD_STATUS
|
data/examples/example_waitid.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#######################################################################
|
2
4
|
# example_waitid.rb
|
3
5
|
#
|
@@ -6,9 +8,10 @@
|
|
6
8
|
#
|
7
9
|
# Modify as you see fit.
|
8
10
|
#######################################################################
|
11
|
+
require 'English'
|
9
12
|
require 'proc/wait3'
|
10
13
|
|
11
|
-
pid = fork{ sleep 2 }
|
14
|
+
pid = fork { sleep 2 }
|
12
15
|
p Time.now
|
13
16
|
Process.waitid(Process::P_PID, pid, Process::WEXITED)
|
14
|
-
p
|
17
|
+
p $CHILD_STATUS
|
data/ext/extconf.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
########################################################
|
2
4
|
# Use the mkmf.rb file that I provide, so I can use the
|
3
5
|
# have_enum_member method
|
@@ -7,12 +9,12 @@ require 'mkmf'
|
|
7
9
|
dir_config('proc-wait3')
|
8
10
|
|
9
11
|
have_header('wait.h')
|
10
|
-
have_header('sys/resource.h')
|
12
|
+
have_header('sys/resource.h') # apt install libbsd-dev
|
11
13
|
have_header('sys/wait.h')
|
12
14
|
|
13
15
|
# wait3 is mandatory.
|
14
16
|
unless have_func('wait3')
|
15
|
-
|
17
|
+
warn 'wait3() function not found'
|
16
18
|
exit
|
17
19
|
end
|
18
20
|
|
@@ -53,20 +55,7 @@ have_struct_member('struct siginfo', 'si_stime', 'signal.h')
|
|
53
55
|
|
54
56
|
have_const('P_CID', 'signal.h')
|
55
57
|
have_const('P_GID', 'signal.h')
|
56
|
-
have_const('P_MYID', 'signal.
|
57
|
-
layout(
|
58
|
-
:pw_name, :string,
|
59
|
-
:pw_passwd, :string,
|
60
|
-
:pw_uid, :uint,
|
61
|
-
:pw_gid, :uint,
|
62
|
-
:pw_change, :ulong,
|
63
|
-
:pw_class, :string,
|
64
|
-
:pw_gecos, :string,
|
65
|
-
:pw_dir, :string,
|
66
|
-
:pw_shell, :string,
|
67
|
-
:pw_expire, :ulong
|
68
|
-
)
|
69
|
-
end')
|
58
|
+
have_const('P_MYID', 'signal.h')
|
70
59
|
have_const('P_SID', 'signal.h')
|
71
60
|
have_const('P_UID', 'signal.h')
|
72
61
|
|
@@ -81,4 +70,7 @@ have_const('P_TASKID', 'signal.h')
|
|
81
70
|
# RUSAGE_THREAD is Linux-specific
|
82
71
|
have_const('RUSAGE_THREAD', 'sys/resource.h')
|
83
72
|
|
73
|
+
# BSD
|
74
|
+
have_const('P_JAILID', 'sys/wait.h')
|
75
|
+
|
84
76
|
create_makefile('proc/wait3', 'proc')
|
data/ext/proc/wait3.c
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
VALUE v_last_status;
|
30
30
|
VALUE v_procstat_struct, v_siginfo_struct, v_usage_struct;
|
31
31
|
|
32
|
-
static void sigproc(int signum);
|
32
|
+
static void sigproc(int signum, siginfo_t* info, void* ucontext);
|
33
33
|
|
34
34
|
/*
|
35
35
|
* Returns true if this process is stopped. This is only returned
|
@@ -163,22 +163,22 @@ static VALUE proc_wait3(int argc, VALUE *argv, VALUE mod){
|
|
163
163
|
v_last_status = rb_struct_new(v_procstat_struct,
|
164
164
|
INT2FIX(pid),
|
165
165
|
INT2FIX(status),
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
166
|
+
rb_float_new((double)r.ru_utime.tv_sec+(double)r.ru_utime.tv_usec/1e6),
|
167
|
+
rb_float_new((double)r.ru_stime.tv_sec+(double)r.ru_stime.tv_usec/1e6),
|
168
|
+
LONG2NUM(r.ru_maxrss),
|
169
|
+
LONG2NUM(r.ru_ixrss),
|
170
|
+
LONG2NUM(r.ru_idrss),
|
171
|
+
LONG2NUM(r.ru_isrss),
|
172
|
+
LONG2NUM(r.ru_minflt),
|
173
|
+
LONG2NUM(r.ru_majflt),
|
174
|
+
LONG2NUM(r.ru_nswap),
|
175
|
+
LONG2NUM(r.ru_inblock),
|
176
|
+
LONG2NUM(r.ru_oublock),
|
177
|
+
LONG2NUM(r.ru_msgsnd),
|
178
|
+
LONG2NUM(r.ru_msgrcv),
|
179
|
+
LONG2NUM(r.ru_nsignals),
|
180
|
+
LONG2NUM(r.ru_nvcsw),
|
181
|
+
LONG2NUM(r.ru_nivcsw),
|
182
182
|
pst_wifstopped(status),
|
183
183
|
pst_wifsignaled(status),
|
184
184
|
pst_wifexited(status),
|
@@ -235,22 +235,22 @@ static VALUE proc_wait4(int argc, VALUE *argv, VALUE mod){
|
|
235
235
|
v_last_status = rb_struct_new(v_procstat_struct,
|
236
236
|
INT2FIX(pid),
|
237
237
|
INT2FIX(status),
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
238
|
+
rb_float_new((double)r.ru_utime.tv_sec+(double)r.ru_utime.tv_usec/1e6),
|
239
|
+
rb_float_new((double)r.ru_stime.tv_sec+(double)r.ru_stime.tv_usec/1e6),
|
240
|
+
LONG2NUM(r.ru_maxrss),
|
241
|
+
LONG2NUM(r.ru_ixrss),
|
242
|
+
LONG2NUM(r.ru_idrss),
|
243
|
+
LONG2NUM(r.ru_isrss),
|
244
|
+
LONG2NUM(r.ru_minflt),
|
245
|
+
LONG2NUM(r.ru_majflt),
|
246
|
+
LONG2NUM(r.ru_nswap),
|
247
|
+
LONG2NUM(r.ru_inblock),
|
248
|
+
LONG2NUM(r.ru_oublock),
|
249
|
+
LONG2NUM(r.ru_msgsnd),
|
250
|
+
LONG2NUM(r.ru_msgrcv),
|
251
|
+
LONG2NUM(r.ru_nsignals),
|
252
|
+
LONG2NUM(r.ru_nvcsw),
|
253
|
+
LONG2NUM(r.ru_nivcsw),
|
254
254
|
pst_wifstopped(status),
|
255
255
|
pst_wifsignaled(status),
|
256
256
|
pst_wifexited(status),
|
@@ -572,7 +572,7 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
572
572
|
*/
|
573
573
|
static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
|
574
574
|
VALUE v_signals;
|
575
|
-
int i;
|
575
|
+
int i, res;
|
576
576
|
long len;
|
577
577
|
|
578
578
|
rb_scan_args(argc, argv, "0*", &v_signals);
|
@@ -585,6 +585,7 @@ static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
|
|
585
585
|
char signame[SIG2STR_MAX];
|
586
586
|
unsigned int max = SIG2STR_MAX;
|
587
587
|
int signum;
|
588
|
+
struct sigaction act, sa;
|
588
589
|
|
589
590
|
for(i = 0; i < len; i++){
|
590
591
|
v_val = rb_ary_shift(v_signals);
|
@@ -613,7 +614,13 @@ static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
|
|
613
614
|
signum = NUM2INT(v_val);
|
614
615
|
}
|
615
616
|
|
616
|
-
|
617
|
+
memset(&act, 0, sizeof(act));
|
618
|
+
act.sa_flags = SA_SIGINFO;
|
619
|
+
act.sa_sigaction = sigproc;
|
620
|
+
res = sigaction(signum, &act, &sa);
|
621
|
+
|
622
|
+
if(res)
|
623
|
+
rb_sys_fail("sigaction");
|
617
624
|
}
|
618
625
|
}
|
619
626
|
|
@@ -624,7 +631,7 @@ static VALUE proc_pause(int argc, VALUE* argv, VALUE mod){
|
|
624
631
|
* This is just a placeholder proc to prevent the "pause" method from exiting
|
625
632
|
* the program if the appropriate signal is intercepted.
|
626
633
|
*/
|
627
|
-
static void sigproc(int signum){ /* Do nothing */ }
|
634
|
+
static void sigproc(int signum, siginfo_t* info, void* ucontext){ /* Do nothing */ }
|
628
635
|
|
629
636
|
#ifdef HAVE_SIGSEND
|
630
637
|
/*
|
@@ -787,7 +794,7 @@ static VALUE proc_getdtablesize(VALUE mod){
|
|
787
794
|
* Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to the
|
788
795
|
* Process module.
|
789
796
|
*/
|
790
|
-
void Init_wait3()
|
797
|
+
void Init_wait3(void)
|
791
798
|
{
|
792
799
|
v_procstat_struct =
|
793
800
|
rb_struct_define("ProcStat","pid","status","utime","stime","maxrss",
|
@@ -950,12 +957,17 @@ void Init_wait3()
|
|
950
957
|
rb_define_const(rb_mProcess, "P_PROJID", INT2FIX(P_PROJID));
|
951
958
|
#endif
|
952
959
|
|
960
|
+
#ifdef HAVE_CONST_P_JAILID
|
961
|
+
/* Process jail ID */
|
962
|
+
rb_define_const(rb_mProcess, "P_JAILID", INT2FIX(P_JAILID));
|
963
|
+
#endif
|
964
|
+
|
953
965
|
#ifdef HAVE_CONST_RUSAGE_THREAD
|
954
966
|
rb_define_const(rb_mProcess, "RUSAGE_THREAD", INT2FIX(RUSAGE_THREAD));
|
955
967
|
#endif
|
956
968
|
|
957
|
-
/* 1.9.
|
958
|
-
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_freeze(rb_str_new2("1.9.
|
969
|
+
/* 1.9.2: The version of the proc-wait3 library */
|
970
|
+
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_freeze(rb_str_new2("1.9.2")));
|
959
971
|
|
960
972
|
/* Define this last in our Init_wait3 function */
|
961
973
|
rb_define_readonly_variable("$last_status", &v_last_status);
|
data/lib/proc-wait3.rb
CHANGED