proc-wait3 1.8.1 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/doc/wait3.txt DELETED
@@ -1,192 +0,0 @@
1
- == Description
2
- Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to
3
- the Process module.
4
-
5
- == Synopsis
6
- require 'proc/wait3'
7
-
8
- pid = fork{ sleep 1; exit 2 }
9
- p Time.now
10
- Process.wait3
11
- p $?
12
-
13
- == Module Methods
14
- Proc.pause(signals=nil)
15
- Pauses the current process. If the process receives any of the signals
16
- you pass as arguments it will return from the pause and continue with
17
- the execution of your code. Otherwise, it will exit.
18
-
19
- Note that you must leave out the 'SIG' prefix for the signal name, e.g.
20
- use 'INT', not 'SIGINT'.
21
-
22
- Returns the result of the pause() function, which should always be -1.
23
-
24
- Process.sigsend(idtype, id, signal=0)
25
- Sends a signal of type "idtype" to a process or process group "id". This
26
- is more versatile method of sending signals to processes than Process.kill.
27
-
28
- For a list of valid idtype values, see the "Process type constants" below.
29
- Not supported on all platforms.
30
-
31
- Proc.wait3(flags=0)
32
- Delays its caller until a signal is received or one of its child processes
33
- terminates or stops due to tracing.
34
-
35
- The return value is a ProcStat structure and sets the $last_status global
36
- variable. The special global $? is also set. Raises a SystemError if there
37
- are no child processes.
38
-
39
- Proc.wait4(pid, flags=0)
40
- Waits for the given child process to exit. Returns a ProcStat structure.
41
- The $last_status global variable is set. Also sets the $? special global
42
- variable.
43
-
44
- Proc.waitid(id_type, id_num=nil, options=nil)
45
- Suspends the calling process until one of its children changes state,
46
- returning immediately if a child process changed state prior to the call.
47
- The state of a child process will change if it terminates, stops because
48
- of a signal, becomes trapped or reaches a breakpoint.
49
-
50
- The id_num corresponds to a process ID or process group ID, depending on
51
- the value of +id_type+, which may be Process::P_PID, Process::P_PGID or
52
- Process::P_ALL. If +id_type+ is Process::P_ALL, then the +id_num+ is ignored.
53
-
54
- The options argument is used to specify which state changes are to be
55
- waited for. It is constructed from the bitwise-OR of one or more of the
56
- following constants:
57
-
58
- Process::WCONTINUED
59
- Process::WEXITED
60
- Process::WNOHANG
61
- Process::WNOWAIT
62
- Process::WSTOPPED
63
- Process::WTRAPPED (not supported on all platforms)
64
-
65
- If Process::WNOHANG is set as an option, this method will return
66
- immediately, whether or not a child has changed state.
67
-
68
- Calling this method with an +id_type+ of Process::P_ALL and the options set
69
- to 'Process::EXITED | Process::WTRAPPED' is equivalent to calling
70
- Process.wait.
71
-
72
- Returns a Proc::SigInfo struct and sets $?.
73
-
74
- Not supported on all platforms.
75
-
76
- == Constants
77
- === Standard
78
- Process::WAIT3_VERSION
79
- Returns the version of this package as a string.
80
-
81
- === Process type constants
82
- ==== All platforms
83
- Process::P_ALL
84
- All non-system process.
85
-
86
- Process::P_PID
87
- A standard process id.
88
-
89
- Process::P_PGID
90
- Any non-system process group id.
91
-
92
- ==== Not supported on all platforms
93
- Process::P_CID
94
- A scheduler process id.
95
-
96
- Process::P_GID
97
- Any non-system effective process group id.
98
-
99
- Process::P_PROJID
100
- A project process id. Solaris 8 or later only.
101
-
102
- Process::P_SID
103
- A session process id.
104
-
105
- Process::P_TASKID
106
- A task process id. Solaris 8 or later only.
107
-
108
- Process::P_UID
109
- Any non-system effective process user id.
110
-
111
- === The following additional constants are defined if the waitid function is
112
- supported on your system.
113
-
114
- Process::WCONTINUED
115
- Return the status for any child that was stopped and has been continued.
116
-
117
- Process::WEXITED
118
- Wait for process(es) to exit.
119
-
120
- Process::WNOWAIT
121
- Keep the process in a waitable state.
122
-
123
- Process::WSTOPPED
124
- Wait for and return the process status of any child that has stopped upon
125
- receipt of a signal.
126
-
127
- Process::WTRAPPED
128
- Wait for traced process(es) to become trapped or reach a breakpoint.
129
-
130
- Not supported on all platforms.
131
-
132
- === RLIMIT constants
133
- Process::RLIMIT_AS
134
- A synonym for RLIMIT_VMEM
135
-
136
- Process::RLIMIT_CORE
137
- The maximum size of a core file, in bytes, that may be created.
138
-
139
- Process::RLIMIT_CPU
140
- The maximum amount of CPU time, in seconds, the process is allowed to use.
141
-
142
- Process::RLIMIT_DATA
143
- The maximum size of the process' heap size, in bytes.
144
-
145
- Process::RLIMIT_FSIZE
146
- The maximum size of a file, in bytes, that the process may create.
147
-
148
- Process::RLIMIT_NOFILE
149
- The maximum value that the kernel may assign to a file descriptor,
150
- effectively limiting the number of open files for the calling process.
151
-
152
- Process::RLIMIT_STACK
153
- The maximum size of the process' stack in bytes.
154
-
155
- Process::RLIMIT_VMEM
156
- The maximum size of the process' mapped address space.
157
-
158
- Process::RLIM_INFINITY
159
- A infinite limit.
160
-
161
- Process::RLIM_SAVED_CUR
162
- Current soft limit.
163
-
164
- Process::RLIM_SAVED_MAX
165
- Current hard limit.
166
-
167
- == Notes
168
- The wait3 and wait4 methods are similar to the wait2 and waitpid2
169
- methods, except that they return much more information via the rusage
170
- struct.
171
-
172
- == Known Bugs
173
- None that I'm aware of. Please log any bugs on the Github project
174
- page at https://github.com/djberg96/proc-wait3.
175
-
176
- == License
177
- Apache-2.0
178
-
179
- == Copyright
180
- (C) 2003-2019 Daniel J. Berger
181
- All Rights Reserved.
182
-
183
- == Warranty
184
- This package is provided "as is" and without any express or
185
- implied warranties, including, without limitation, the implied
186
- warranties of merchantability and fitness for a particular purpose.
187
-
188
- == Author
189
- Daniel J. Berger
190
-
191
- == See also
192
- wait3, wait4, waitid, pause, sigsend
@@ -1,227 +0,0 @@
1
- ##################################################################
2
- # test_proc_wait3.rb
3
- #
4
- # Test suite for the Ruby proc-wait3 package. You should run this
5
- # via the 'test' rake task.
6
- ##################################################################
7
- require 'proc/wait3'
8
- require 'test-unit'
9
- require 'rbconfig'
10
-
11
- class TC_Proc_Wait3 < Test::Unit::TestCase
12
- def self.startup
13
- @@solaris = RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
14
- @@darwin = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
15
- @@hpux = RbConfig::CONFIG['host_os'] =~ /hpux/i
16
- @@linux = RbConfig::CONFIG['host_os'] =~ /linux/i
17
- @@freebsd = RbConfig::CONFIG['host_os'] =~ /bsd/i
18
- end
19
-
20
- def setup
21
- @proc_stat = nil
22
- @proc_stat_members = [
23
- "pid", "status", "utime", "stime", "maxrss",
24
- "ixrss", "idrss", "isrss", "minflt", "majflt", "nswap", "inblock",
25
- "oublock", "msgsnd", "msgrcv", "nsignals", "nvcsw", "nivcsw",
26
- "stopped", "signaled","exited","success","coredump","exitstatus",
27
- "termsig", "stopsig"
28
- ]
29
-
30
- @proc_stat_members = @proc_stat_members.map{ |e| e.to_sym }
31
- end
32
-
33
- test "version constant is set to expected value" do
34
- assert_equal('1.8.1', Process::WAIT3_VERSION)
35
- assert_true(Process::WAIT3_VERSION.frozen?)
36
- end
37
-
38
- test "wait3 method is defined" do
39
- assert_respond_to(Process, :wait3)
40
- end
41
-
42
- test "wait3 works as expected" do
43
- fork{ sleep 0.5 }
44
- assert_nothing_raised{ Process.wait3 }
45
- end
46
-
47
- test "wait3 returns the expected proc status membes" do
48
- fork{ sleep 0.5 }
49
- assert_nothing_raised{ @proc_stat = Process.wait3 }
50
- assert_equal(@proc_stat_members, @proc_stat.members)
51
- end
52
-
53
- test "wait3 with WNOHANG works as expected" do
54
- fork{ sleep 0.5 }
55
- assert_nothing_raised{ Process.wait3(Process::WNOHANG) }
56
- end
57
-
58
- test "wait3 sets and returns $last_status to expected values" do
59
- fork{ sleep 0.5 }
60
- Process.wait3
61
- assert_kind_of(Struct::ProcStat, $last_status)
62
- assert_not_nil($last_status)
63
- end
64
-
65
- test "wait3 sets pid and status members of $?" do
66
- fork{ sleep 0.5 }
67
- Process.wait3
68
- assert_not_nil($?)
69
- end
70
-
71
- test "wait3 returns frozen struct" do
72
- fork{ sleep 0.5 }
73
- struct = Process.wait3
74
- assert_true(struct.frozen?)
75
- end
76
-
77
- test "getdtablesize works as expected" do
78
- omit_unless(@@solaris, 'getdtablesize skipped on this platform')
79
-
80
- assert_respond_to(Process, :getdtablesize)
81
- assert_kind_of(Fixnum, Process.getdtablesize)
82
- assert(Process.getdtablesize > 0)
83
- end
84
-
85
- test "wait4 method is defined" do
86
- omit_if(@@hpux, 'wait4 test skipped on this platform')
87
- assert_respond_to(Process,:wait4)
88
- end
89
-
90
- test "wait4 requires at least one argument" do
91
- assert_raises(ArgumentError){ Process.wait4 }
92
- end
93
-
94
- test "wait4 works as expected" do
95
- omit_if(@@hpux, 'wait4 test skipped on this platform')
96
-
97
- pid = fork{ sleep 0.5 }
98
- assert_nothing_raised{ @proc_stat = Process.wait4(pid) }
99
- assert_kind_of(Struct::ProcStat, @proc_stat)
100
- end
101
-
102
- test "wait4 sets and returns $last_status to expected values" do
103
- pid = fork{ sleep 0.5 }
104
- Process.wait4(pid)
105
- assert_kind_of(Struct::ProcStat, $last_status)
106
- assert_not_nil($last_status)
107
- end
108
-
109
- test "wait4 sets pid and status members of $?" do
110
- pid = fork{ sleep 0.5 }
111
- Process.wait4(pid)
112
- assert_not_nil($?)
113
- end
114
-
115
- test "wait4 returns frozen struct" do
116
- pid = fork{ sleep 0.5 }
117
- struct = Process.wait4(pid)
118
- assert_true(struct.frozen?)
119
- end
120
-
121
- test "waitid method is defined" do
122
- omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
123
- assert_respond_to(Process, :waitid)
124
- end
125
-
126
- test "waitid method works as expected" do
127
- omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
128
- pid = fork{ sleep 0.5 }
129
- assert_nothing_raised{ Process.waitid(Process::P_PID, pid, Process::WEXITED) }
130
- end
131
-
132
- test "waitid method raises expected errors if wrong argument type is passed" do
133
- omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
134
- pid = fork{ sleep 0.5 }
135
- assert_raises(TypeError){ Process.waitid("foo", pid, Process::WEXITED) }
136
- assert_raises(TypeError){ Process.waitid(Process::P_PID, pid, "foo") }
137
- assert_raises(TypeError){ Process.waitid(Process::P_PID, "foo", Process::WEXITED) }
138
- end
139
-
140
- test "waitid method raises expected error if invalid argument is passed" do
141
- omit_if(@@hpux || @@darwin || @@freebsd, 'waitid test skipped on this platform')
142
- fork{ sleep 0.5 }
143
- assert_raises(Errno::ECHILD, Errno::EINVAL){ Process.waitid(Process::P_PID, 99999999, Process::WEXITED) }
144
- end
145
-
146
- test "sigsend method is defined" do
147
- omit_unless(@@solaris, 'sigsend test skipped on this platform')
148
- assert_respond_to(Process, :sigsend)
149
- end
150
-
151
- test "sigsend works as expected" do
152
- omit_unless(@@solaris, 'sigsend test skipped on this platform')
153
- pid = fork{ sleep 0.5 }
154
- assert_nothing_raised{ Process.sigsend(Process::P_PID, pid, 0) }
155
- end
156
-
157
- test "getrusage method is defined" do
158
- assert_respond_to(Process, :getrusage)
159
- end
160
-
161
- test "getrusage works as expected" do
162
- fork{ sleep 0.5 }
163
- assert_nothing_raised{ Process.getrusage }
164
- assert_nothing_raised{ Process.getrusage(true) }
165
- end
166
-
167
- test "getrusage can get thread info on Linux" do
168
- omit_unless(@@linux)
169
- assert_nothing_raised{ Process.getrusage(Process::RUSAGE_THREAD) }
170
- end
171
-
172
- test "getrusage returns the expected struct" do
173
- fork{ sleep 0.5 }
174
- assert_kind_of(Struct::RUsage, Process.getrusage)
175
- assert_kind_of(Float, Process.getrusage.stime)
176
- assert_kind_of(Float, Process.getrusage.utime)
177
- end
178
-
179
- test "pause method is defined" do
180
- assert_respond_to(Process, :pause)
181
- end
182
-
183
- test "expected constants are defined" do
184
- omit_if(@@darwin || @@freebsd, 'wait constant check skipped on this platform')
185
-
186
- assert_not_nil(Process::WCONTINUED)
187
- assert_not_nil(Process::WEXITED)
188
- assert_not_nil(Process::WNOWAIT)
189
- assert_not_nil(Process::WSTOPPED)
190
-
191
- omit_if(@@linux, 'WTRAPPED constant check skipped on this platform')
192
- assert_not_nil(Process::WTRAPPED)
193
- end
194
-
195
- test "expected process type flag constants are defined" do
196
- omit_if(@@linux || @@darwin || @@freebsd, 'process type flag check skipped on this platform')
197
-
198
- assert_not_nil(Process::P_ALL)
199
- assert_not_nil(Process::P_CID)
200
- assert_not_nil(Process::P_GID)
201
- assert_not_nil(Process::P_MYID) unless @@solaris
202
- assert_not_nil(Process::P_PGID)
203
- assert_not_nil(Process::P_PID)
204
- assert_not_nil(Process::P_SID)
205
- assert_not_nil(Process::P_UID)
206
- end
207
-
208
- test "solaris-specific process type flags are defined on solaris" do
209
- omit_unless(@@solaris, 'P_TASKID and P_PROJID constant check skipped on this platform')
210
-
211
- assert_not_nil(Process::P_TASKID)
212
- assert_not_nil(Process::P_PROJID)
213
- end
214
-
215
- def teardown
216
- @proc_stat = nil
217
- @proc_stat_members = nil
218
- end
219
-
220
- def self.shutdown
221
- @@solaris = nil
222
- @@darwin = nil
223
- @@hpux = nil
224
- @@linux = nil
225
- @@freebsd = nil
226
- end
227
- end