proc-wait3 1.5.5 → 1.5.6
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.
- data/CHANGES +10 -0
- data/README +33 -51
- data/Rakefile +42 -81
- data/ext/extconf.rb +52 -73
- data/ext/proc/wait3.c +130 -109
- data/proc-wait3.gemspec +23 -24
- data/test/test_proc_wait3.rb +226 -235
- metadata +4 -4
data/CHANGES
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 1.5.6 - 7-Jan-2010
|
2
|
+
* Checks are now made for the si_fd, si_utime, si_status and si_stime siginfo_t
|
3
|
+
struct members. This addresses build failures on OS X 10.5 and later where
|
4
|
+
those struct members went mysteriously MIA.
|
5
|
+
* The have_const method is no longer added to your mkmf.rb file. It is simply
|
6
|
+
defined in the extconf.rb file.
|
7
|
+
* Some gemspec and Rakefile refactoring.
|
8
|
+
* Updates to the README.
|
9
|
+
* Source code moved to github.
|
10
|
+
|
1
11
|
== 1.5.5 - 8-Aug-2009
|
2
12
|
* Now compatible with Ruby 1.9.x.
|
3
13
|
* License changed to Artistic 2.0.
|
data/README
CHANGED
@@ -1,54 +1,36 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
= Description
|
2
|
+
Adds the wait3, wait4, waitid, pause, sigsend, and getrusage methods to
|
3
|
+
the Process module. For Ruby 1.8.4 or earlier, it also adds the getrlimit
|
4
|
+
and setrlimit methods.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
=== Local Installation
|
10
|
-
rake install
|
6
|
+
= Installation
|
7
|
+
|
8
|
+
gem install proc-wait3
|
11
9
|
|
12
10
|
== Tested Platforms
|
13
|
-
* Solaris
|
14
|
-
* Linux
|
15
|
-
* FreeBSD
|
16
|
-
* OS X
|
17
|
-
|
18
|
-
|
19
|
-
Linux users who compile with gcc -Wall will notice a few warnings. These
|
20
|
-
are harmless (and unavoidable atm).
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
based on an earlier post, seem somewhat gun-shy about integrating support
|
40
|
-
for wait3() and wait4() based, I think, on portability concerns.
|
41
|
-
|
42
|
-
Second, and more importantly, I don't like the cProcStatus class. The
|
43
|
-
extra inspection code seems like an awful lot of work for very little gain.
|
44
|
-
The overloaded methods are also overkill, and do nothing but save me the
|
45
|
-
trouble of typing the word "status", since all they're for is comparing or
|
46
|
-
operating on the status attribute.
|
47
|
-
|
48
|
-
That being said, I would be willing to write a patch for process.c if there's
|
49
|
-
enough support for it. If you'd like to see that, please log a comment and/or
|
50
|
-
feature request on the project page at
|
51
|
-
http://www.rubyforge.org/projects/shards.
|
52
|
-
|
53
|
-
== Additional Documentation
|
54
|
-
Please see the doc/wait3.txt file for detailed documentation.
|
11
|
+
* Solaris
|
12
|
+
* Linux
|
13
|
+
* FreeBSD
|
14
|
+
* OS X
|
15
|
+
|
16
|
+
= Warnings
|
17
|
+
Linux users who compile with gcc -Wall will notice a few warnings. These
|
18
|
+
are harmless (and unavoidable atm).
|
19
|
+
|
20
|
+
= Integration with Ruby's process.c
|
21
|
+
|
22
|
+
I considered simply providing a patch to the core process.c file, but I
|
23
|
+
decided against it for two reasons. First, I wanted to get something
|
24
|
+
out more quickly rather than waiting for approval from the core developers
|
25
|
+
who, based on an earlier post, seem somewhat gun-shy about integrating support
|
26
|
+
for wait3() and wait4() based, I think, on portability concerns.
|
27
|
+
|
28
|
+
Second, and more importantly, I don't like the cProcStatus class. The
|
29
|
+
extra inspection code seems like an awful lot of work for very little gain.
|
30
|
+
The overloaded methods are also overkill, and do nothing but save me the
|
31
|
+
trouble of typing the word "status", since all they're for is comparing or
|
32
|
+
operating on the status attribute.
|
33
|
+
|
34
|
+
= Additional Documentation
|
35
|
+
|
36
|
+
Please see the doc/wait3.txt file for detailed documentation.
|
data/Rakefile
CHANGED
@@ -4,102 +4,63 @@ require 'fileutils'
|
|
4
4
|
|
5
5
|
desc "Clean the generated build files"
|
6
6
|
task :clean do |t|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
Dir.chdir('ext') do
|
8
|
+
sh 'make distclean' rescue nil
|
9
|
+
rm 'proc/wait3.' + Config::CONFIG['DLEXT'] rescue nil
|
10
|
+
rm_rf 'conftest.dSYM' if File.exists?('conftest.dSYM') # OS X
|
11
|
+
end
|
11
12
|
end
|
12
13
|
|
13
14
|
desc "Build the source (but don't install it)"
|
14
|
-
task :build => [:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
task :build => [:clean] do |t|
|
16
|
+
Dir.chdir('ext') do
|
17
|
+
ruby 'extconf.rb'
|
18
|
+
sh 'make'
|
19
|
+
FileUtils.mv 'wait3.' + Config::CONFIG['DLEXT'], 'proc'
|
20
|
+
end
|
20
21
|
end
|
21
22
|
|
22
23
|
desc "Install the proc-wait3 library"
|
23
24
|
task :install => [:build] do |t|
|
24
|
-
|
25
|
+
sh 'make install'
|
25
26
|
end
|
26
27
|
|
27
|
-
desc
|
28
|
-
task :
|
29
|
-
|
28
|
+
desc "Build the gem"
|
29
|
+
task :gem do
|
30
|
+
spec = eval(IO.read('proc-wait3.gemspec'))
|
31
|
+
Gem::Builder.new(spec).build
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
namespace :example do
|
35
|
+
desc 'Run the Process.getrusage example program'
|
36
|
+
task :getrusage => [:build] do
|
37
|
+
ruby '-Iext examples/example_getrusage.rb'
|
38
|
+
end
|
36
39
|
|
37
|
-
desc 'Run the Process.
|
38
|
-
task :
|
39
|
-
|
40
|
-
end
|
40
|
+
desc 'Run the Process.pause example program'
|
41
|
+
task :pause => [:build] do
|
42
|
+
ruby '-Iext examples/example_pause.rb'
|
43
|
+
end
|
41
44
|
|
42
|
-
desc 'Run the Process.
|
43
|
-
task :
|
44
|
-
|
45
|
-
end
|
45
|
+
desc 'Run the Process.wait3 example program'
|
46
|
+
task :wait3 => [:build] do
|
47
|
+
ruby '-Iext examples/example_wait3.rb'
|
48
|
+
end
|
46
49
|
|
47
|
-
desc 'Run the Process.
|
48
|
-
task :
|
49
|
-
|
50
|
-
end
|
50
|
+
desc 'Run the Process.wait4 example program'
|
51
|
+
task :wait4 => [:build] do
|
52
|
+
ruby '-Iext examples/example_wait4.rb'
|
53
|
+
end
|
51
54
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
t.verbose = true
|
55
|
+
desc 'Run the Process.waitid example program'
|
56
|
+
task :waitid => [:build] do
|
57
|
+
ruby '-Iext examples/example_waitid.rb'
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
|
-
|
60
|
-
task :
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
date = Time.now
|
65
|
-
|
66
|
-
FileUtils.cp(file, 'mkmf.orig') # Backup original
|
67
|
-
|
68
|
-
File.open(file, 'a+'){ |fh|
|
69
|
-
fh.puts %Q{
|
70
|
-
# Returns whether or not the constant +const+ can be found in the common
|
71
|
-
# header files, or within a +header+ that you provide. If found, a macro is
|
72
|
-
# passed as a preprocessor constant to the compiler using the constant name,
|
73
|
-
# in uppercase, prepended with 'HAVE_'. This method is also used to test
|
74
|
-
# for the presence of enum values.
|
75
|
-
#
|
76
|
-
# For example, if have_const('FOO') returned true, then the HAVE_CONST_FOO
|
77
|
-
# preprocessor macro would be passed to the compiler.
|
78
|
-
#
|
79
|
-
# This method was added automatically by the proc-wait3 library on
|
80
|
-
# #{date}.
|
81
|
-
#
|
82
|
-
def have_const(const, header = nil, opt = "", &b)
|
83
|
-
checking_for const do
|
84
|
-
header = cpp_include(header)
|
85
|
-
if try_compile(<<"SRC", opt, &b)
|
86
|
-
#\{COMMON_HEADERS\}
|
87
|
-
#\{header\}
|
88
|
-
/* top */
|
89
|
-
static int t = #\{const\};
|
90
|
-
SRC
|
91
|
-
$defs.push(
|
92
|
-
format(
|
93
|
-
"-DHAVE_CONST_%s",
|
94
|
-
const.strip.upcase.tr_s("^A-Z0-9_", "_")
|
95
|
-
)
|
96
|
-
)
|
97
|
-
true
|
98
|
-
else
|
99
|
-
false
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end}
|
103
|
-
}
|
104
|
-
end
|
61
|
+
Rake::TestTask.new do |t|
|
62
|
+
task :test => [:build]
|
63
|
+
t.libs << 'ext'
|
64
|
+
t.warning = true
|
65
|
+
t.verbose = true
|
105
66
|
end
|
data/ext/extconf.rb
CHANGED
@@ -4,32 +4,55 @@
|
|
4
4
|
########################################################
|
5
5
|
require 'mkmf'
|
6
6
|
|
7
|
+
# We need this for older versions of Ruby.
|
8
|
+
def have_const(const, header = nil, opt = "", &b)
|
9
|
+
checking_for const do
|
10
|
+
header = cpp_include(header)
|
11
|
+
if try_compile(<<"SRC", opt, &b)
|
12
|
+
#{COMMON_HEADERS}
|
13
|
+
#{header}
|
14
|
+
/* top */
|
15
|
+
static int t = #{const};
|
16
|
+
SRC
|
17
|
+
$defs.push(
|
18
|
+
format(
|
19
|
+
"-DHAVE_CONST_%s",
|
20
|
+
const.strip.upcase.tr_s("^A-Z0-9_", "_")
|
21
|
+
)
|
22
|
+
)
|
23
|
+
true
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
7
30
|
# Check to see if Ruby has already defined the various RLIMIT constants
|
8
31
|
# and set an appropriate macro in the source.
|
9
32
|
#
|
10
33
|
begin
|
11
|
-
|
34
|
+
Process::RLIMIT_AS
|
12
35
|
rescue
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
check_sizeof('int')
|
37
|
+
check_sizeof('long')
|
38
|
+
check_sizeof('long long')
|
39
|
+
unless check_sizeof('rlim_t', 'sys/resource.h')
|
40
|
+
if (2**33).is_a?(Fixnum)
|
41
|
+
$defs.push('-DSIZEOF_RLIM_T 8') # 64 bit
|
42
|
+
else
|
43
|
+
$defs.push('-DSIZEOF_RLIM_T 4') # 32 bit
|
44
|
+
end
|
45
|
+
end
|
23
46
|
else
|
24
|
-
|
47
|
+
$defs.push('-DRUBY_HAS_RLIMIT') # Used within wait.c
|
25
48
|
end
|
26
49
|
|
27
50
|
have_header('wait.h')
|
28
51
|
|
29
52
|
# wait3 is mandatory.
|
30
53
|
unless have_func('wait3')
|
31
|
-
|
32
|
-
|
54
|
+
STDERR.puts 'wait3() function not found'
|
55
|
+
exit
|
33
56
|
end
|
34
57
|
|
35
58
|
# Yay, Linux
|
@@ -43,6 +66,7 @@ have_func('sigsend')
|
|
43
66
|
have_func('getrusage')
|
44
67
|
have_func('getdtablesize')
|
45
68
|
|
69
|
+
have_struct_member('struct siginfo', 'si_fd', 'signal.h')
|
46
70
|
have_struct_member('struct siginfo', 'si_trapno', 'signal.h')
|
47
71
|
have_struct_member('struct siginfo', 'si_pc', 'signal.h')
|
48
72
|
have_struct_member('struct siginfo', 'si_sysarg', 'signal.h')
|
@@ -52,67 +76,22 @@ have_struct_member('struct siginfo', 'si_syscall', 'signal.h')
|
|
52
76
|
have_struct_member('struct siginfo', 'si_nsysarg', 'signal.h')
|
53
77
|
have_struct_member('struct siginfo', 'si_fault', 'signal.h')
|
54
78
|
have_struct_member('struct siginfo', 'si_tstamp', 'signal.h')
|
79
|
+
have_struct_member('struct siginfo', 'si_utime', 'signal.h')
|
80
|
+
have_struct_member('struct siginfo', 'si_status', 'signal.h')
|
81
|
+
have_struct_member('struct siginfo', 'si_stime', 'signal.h')
|
55
82
|
|
56
|
-
|
83
|
+
have_const('P_CID', 'signal.h')
|
84
|
+
have_const('P_GID', 'signal.h')
|
85
|
+
have_const('P_MYID', 'signal.h')
|
86
|
+
have_const('P_SID', 'signal.h')
|
87
|
+
have_const('P_UID', 'signal.h')
|
57
88
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
have_const('P_CID', 'signal.h')
|
62
|
-
have_const('P_GID', 'signal.h')
|
63
|
-
have_const('P_MYID', 'signal.h')
|
64
|
-
have_const('P_SID', 'signal.h')
|
65
|
-
have_const('P_UID', 'signal.h')
|
66
|
-
|
67
|
-
have_const('P_ALL', 'signal.h') || have_const('P_ALL', 'sys/wait.h')
|
68
|
-
have_const('P_PGID', 'signal.h') || have_const('P_PGID', 'sys/wait.h')
|
69
|
-
have_const('P_PID', 'signal.h') || have_const('P_PID', 'sys/wait.h')
|
89
|
+
have_const('P_ALL', 'signal.h') || have_const('P_ALL', 'sys/wait.h')
|
90
|
+
have_const('P_PGID', 'signal.h') || have_const('P_PGID', 'sys/wait.h')
|
91
|
+
have_const('P_PID', 'signal.h') || have_const('P_PID', 'sys/wait.h')
|
70
92
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
rescue NoMethodError
|
75
|
-
require 'rbconfig'
|
76
|
-
count += 1
|
77
|
-
file = File.join(Config::CONFIG['rubylibdir'], 'mkmf.rb')
|
78
|
-
FileUtils.cp(file, 'mkmf.orig') # Backup original
|
79
|
-
File.open(file, 'a+'){ |fh|
|
80
|
-
fh.puts %Q{
|
81
|
-
# Returns whether or not the constant +const+ can be found in the common
|
82
|
-
# header files, or within a +header+ that you provide. If found, a macro is
|
83
|
-
# passed as a preprocessor constant to the compiler using the constant name,
|
84
|
-
# in uppercase, prepended with 'HAVE_'. This method is also used to test
|
85
|
-
# for the presence of enum values.
|
86
|
-
#
|
87
|
-
# For example, if have_const('FOO') returned true, then the HAVE_CONST_FOO
|
88
|
-
# preprocessor macro would be passed to the compiler.
|
89
|
-
#
|
90
|
-
# This method was added automatically by the proc-wait3 library on
|
91
|
-
# #{Time.now}.
|
92
|
-
#
|
93
|
-
def have_const(const, header = nil, opt = "", &b)
|
94
|
-
checking_for const do
|
95
|
-
header = cpp_include(header)
|
96
|
-
if try_compile(<<"SRC", opt, &b)
|
97
|
-
#\{COMMON_HEADERS\}
|
98
|
-
#\{header\}
|
99
|
-
/* top */
|
100
|
-
static int t = #\{const\};
|
101
|
-
SRC
|
102
|
-
$defs.push(
|
103
|
-
format(
|
104
|
-
"-DHAVE_CONST_%s",
|
105
|
-
const.strip.upcase.tr_s("^A-Z0-9_", "_")
|
106
|
-
)
|
107
|
-
)
|
108
|
-
true
|
109
|
-
else
|
110
|
-
false
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end}
|
114
|
-
}
|
115
|
-
retry unless count >= 2
|
116
|
-
end
|
93
|
+
# These are only supported by Solaris 8 and later afaik
|
94
|
+
have_const('P_PROJID', 'signal.h')
|
95
|
+
have_const('P_TASKID', 'signal.h')
|
117
96
|
|
118
97
|
create_makefile('proc/wait3', 'proc')
|
data/ext/proc/wait3.c
CHANGED
@@ -145,7 +145,7 @@ static VALUE pst_wstopsig(int status)
|
|
145
145
|
|
146
146
|
/*
|
147
147
|
* call-seq:
|
148
|
-
*
|
148
|
+
* Process.wait3(flags=nil)
|
149
149
|
*
|
150
150
|
* Delays its caller until a signal is received or one of its child processes
|
151
151
|
* terminates or stops due to tracing.
|
@@ -210,7 +210,7 @@ static VALUE proc_wait3(int argc, VALUE *argv, VALUE mod){
|
|
210
210
|
#ifdef HAVE_WAIT4
|
211
211
|
/*
|
212
212
|
* call-seq:
|
213
|
-
*
|
213
|
+
* Process.wait4(pid, flags=0)
|
214
214
|
*
|
215
215
|
* Waits for the given child process to exit. Returns a ProcStat structure.
|
216
216
|
* Also sets the $? special global variable.
|
@@ -279,7 +279,7 @@ static VALUE proc_wait4(int argc, VALUE *argv, VALUE mod){
|
|
279
279
|
#ifdef HAVE_WAITID
|
280
280
|
/*
|
281
281
|
* call-seq:
|
282
|
-
*
|
282
|
+
* Process.waitid(id_type, id_num=nil, options=nil)
|
283
283
|
*
|
284
284
|
* Suspends the calling process until one of its children changes state,
|
285
285
|
* returning immediately if a child process changed state prior to the call.
|
@@ -432,9 +432,15 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
432
432
|
* the si_signo struct member will always be SIGCHLD.
|
433
433
|
*/
|
434
434
|
if(sig == SIGCHLD){
|
435
|
+
#ifdef HAVE_ST_SI_UTIME
|
435
436
|
v_utime = ULL2NUM(infop.si_utime);
|
437
|
+
#endif
|
438
|
+
#ifdef HAVE_ST_SI_STATUS
|
436
439
|
v_status = ULL2NUM(infop.si_status);
|
440
|
+
#endif
|
441
|
+
#ifdef HAVE_ST_SI_STIME
|
437
442
|
v_stime = ULL2NUM(infop.si_stime);
|
443
|
+
#endif
|
438
444
|
}
|
439
445
|
|
440
446
|
if(sig == SIGBUS || sig == SIGFPE || sig == SIGILL || sig == SIGSEGV ||
|
@@ -449,7 +455,9 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
449
455
|
}
|
450
456
|
|
451
457
|
if(sig == SIGXFSZ){
|
458
|
+
#ifdef HAVE_ST_SI_FD
|
452
459
|
v_fd = INT2FIX(infop.si_fd);
|
460
|
+
#endif
|
453
461
|
if(code == POLL_IN || code == POLL_OUT || code == POLL_MSG){
|
454
462
|
v_band = LONG2FIX(infop.si_band);
|
455
463
|
}
|
@@ -494,11 +502,11 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
494
502
|
#endif
|
495
503
|
|
496
504
|
v_last_status = rb_struct_new(v_siginfo_struct,
|
497
|
-
INT2FIX(infop.si_signo),
|
498
|
-
INT2FIX(infop.si_errno),
|
499
|
-
INT2FIX(infop.si_code),
|
500
|
-
INT2FIX(infop.si_pid),
|
501
|
-
INT2FIX(infop.si_uid),
|
505
|
+
INT2FIX(infop.si_signo), // Probably SIGCHLD
|
506
|
+
INT2FIX(infop.si_errno), // 0 means no error
|
507
|
+
INT2FIX(infop.si_code), // Should be anything but SI_NOINFO
|
508
|
+
INT2FIX(infop.si_pid), // Real PID that sent the signal
|
509
|
+
INT2FIX(infop.si_uid), // Real UID of process that sent signal
|
502
510
|
v_utime,
|
503
511
|
v_status,
|
504
512
|
v_stime,
|
@@ -508,7 +516,9 @@ static VALUE proc_waitid(int argc, VALUE* argv, VALUE mod){
|
|
508
516
|
#ifdef HAVE_ST_SI_PC
|
509
517
|
v_pc,
|
510
518
|
#endif
|
519
|
+
#ifdef HAVE_ST_SI_FD
|
511
520
|
v_fd,
|
521
|
+
#endif
|
512
522
|
v_band,
|
513
523
|
#ifdef HAVE_ST_SI_FADDR
|
514
524
|
v_addr,
|
@@ -830,210 +840,221 @@ static VALUE proc_getdtablesize(VALUE mod){
|
|
830
840
|
*/
|
831
841
|
void Init_wait3()
|
832
842
|
{
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
843
|
+
v_procstat_struct =
|
844
|
+
rb_struct_define("ProcStat","pid","status","utime","stime","maxrss",
|
845
|
+
"ixrss", "idrss", "isrss", "minflt","majflt","nswap","inblock",
|
846
|
+
"oublock","msgsnd", "msgrcv","nsignals","nvcsw","nivcsw","stopped",
|
847
|
+
"signaled","exited","success","coredump","exitstatus","termsig",
|
848
|
+
"stopsig",NULL
|
849
|
+
);
|
840
850
|
|
841
|
-
|
842
|
-
|
851
|
+
rb_define_module_function(rb_mProcess, "wait3", proc_wait3, -1);
|
852
|
+
rb_define_module_function(rb_mProcess, "pause", proc_pause, -1);
|
843
853
|
|
844
854
|
#ifndef RUBY_HAS_RLIMIT
|
845
|
-
|
846
|
-
|
855
|
+
rb_define_module_function(rb_mProcess, "getrlimit", proc_getrlimit, 1);
|
856
|
+
rb_define_module_function(rb_mProcess, "setrlimit", proc_setrlimit, -1);
|
847
857
|
#endif
|
848
858
|
|
849
859
|
#ifdef HAVE_GETDTABLESIZE
|
850
|
-
|
860
|
+
rb_define_module_function(rb_mProcess,"getdtablesize",proc_getdtablesize,0);
|
851
861
|
#endif
|
852
862
|
|
853
863
|
#ifdef HAVE_SIGSEND
|
854
|
-
|
864
|
+
rb_define_module_function(rb_mProcess, "sigsend", proc_sigsend, -1);
|
855
865
|
#endif
|
856
866
|
|
857
867
|
#ifdef HAVE_WAIT4
|
858
|
-
|
868
|
+
rb_define_module_function(rb_mProcess, "wait4", proc_wait4, -1);
|
859
869
|
#endif
|
860
870
|
|
861
871
|
#ifdef HAVE_GETRUSAGE
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
872
|
+
v_usage_struct =
|
873
|
+
rb_struct_define("RUsage","utime","stime","maxrss","ixrss","idrss",
|
874
|
+
"isrss","minflt","majflt","nswap","inblock","oublock","msgsnd",
|
875
|
+
"msgrcv","nsignals","nvcsw","nivcsw",NULL
|
876
|
+
);
|
867
877
|
|
868
|
-
|
878
|
+
rb_define_module_function(rb_mProcess, "getrusage", proc_getrusage, -1);
|
869
879
|
#endif
|
870
880
|
|
871
881
|
#ifdef HAVE_WAITID
|
872
|
-
|
873
|
-
|
874
|
-
|
882
|
+
v_siginfo_struct =
|
883
|
+
rb_struct_define("SigInfo", "signo", "errno", "code", "pid", "uid"
|
884
|
+
#ifdef HAVE_ST_SI_UTIME
|
885
|
+
,"utime"
|
886
|
+
#endif
|
887
|
+
#ifdef HAVE_ST_SI_STATUS
|
888
|
+
,"status"
|
889
|
+
#endif
|
890
|
+
#ifdef HAVE_ST_SI_STIME
|
891
|
+
,"stime"
|
892
|
+
#endif
|
875
893
|
#ifdef HAVE_ST_SI_TRAPNO
|
876
|
-
|
894
|
+
,"trapno"
|
877
895
|
#endif
|
878
896
|
#ifdef HAVE_ST_SI_PC
|
879
|
-
|
897
|
+
,"pc"
|
898
|
+
#endif
|
899
|
+
#ifdef HAVE_ST_SI_FD
|
900
|
+
,"fd"
|
880
901
|
#endif
|
881
|
-
|
902
|
+
,"band"
|
882
903
|
#ifdef HAVE_ST_SI_FADDR
|
883
|
-
|
904
|
+
,"faddr"
|
884
905
|
#endif
|
885
906
|
#ifdef HAVE_ST_SI_TSTAMP
|
886
|
-
|
907
|
+
,"tstamp"
|
887
908
|
#endif
|
888
909
|
#ifdef HAVE_ST_SI_SYSCALL
|
889
|
-
|
910
|
+
,"syscall"
|
890
911
|
#endif
|
891
912
|
#ifdef HAVE_ST_SI_NSYSARG
|
892
|
-
|
913
|
+
,"nsysarg"
|
893
914
|
#endif
|
894
915
|
#ifdef HAVE_ST_SI_FAULT
|
895
|
-
|
916
|
+
,"fault"
|
896
917
|
#endif
|
897
918
|
#ifdef HAVE_ST_SI_SYSARG
|
898
|
-
|
919
|
+
,"sysarg"
|
899
920
|
#endif
|
900
921
|
#ifdef HAVE_ST_SI_MSTATE
|
901
|
-
|
922
|
+
,"mstate"
|
902
923
|
#endif
|
903
|
-
|
904
|
-
|
924
|
+
,"entity", NULL
|
925
|
+
);
|
905
926
|
|
906
|
-
|
927
|
+
rb_define_module_function(rb_mProcess, "waitid", proc_waitid, -1);
|
907
928
|
|
908
929
|
#ifdef WCONTINUED
|
909
|
-
|
910
|
-
|
930
|
+
/* The status of any child that was stopped and then continued */
|
931
|
+
rb_define_const(rb_mProcess, "WCONTINUED", INT2FIX(WCONTINUED));
|
911
932
|
#endif
|
912
933
|
|
913
934
|
#ifdef WEXITED
|
914
|
-
|
915
|
-
|
935
|
+
/* The status of any child that has terminated */
|
936
|
+
rb_define_const(rb_mProcess, "WEXITED", INT2FIX(WEXITED));
|
916
937
|
#endif
|
917
938
|
|
918
939
|
#ifdef WNOWAIT
|
919
|
-
|
920
|
-
|
940
|
+
/* Keeps the process whose status was returned in a waitable state */
|
941
|
+
rb_define_const(rb_mProcess, "WNOWAIT", INT2FIX(WNOWAIT));
|
921
942
|
#endif
|
922
943
|
|
923
944
|
#ifdef WSTOPPED
|
924
|
-
|
925
|
-
|
945
|
+
/* The status of any child that has stopped as the result of a signal */
|
946
|
+
rb_define_const(rb_mProcess, "WSTOPPED", INT2FIX(WSTOPPED));
|
926
947
|
#endif
|
927
948
|
|
928
949
|
#ifdef WTRAPPED
|
929
|
-
|
930
|
-
|
950
|
+
/* Waits for any child process to become trapped or reach a breakpoint */
|
951
|
+
rb_define_const(rb_mProcess, "WTRAPPED", INT2FIX(WTRAPPED));
|
931
952
|
#endif
|
932
953
|
#endif
|
933
954
|
|
934
|
-
|
935
|
-
|
936
|
-
|
955
|
+
/* Because core Ruby already defines a Process::GID and Process::UID,
|
956
|
+
* I am forced to keep the leading 'P_' for these constants.
|
957
|
+
*/
|
937
958
|
|
938
959
|
#ifdef HAVE_CONST_P_ALL
|
939
|
-
|
940
|
-
|
960
|
+
/* Any child */
|
961
|
+
rb_define_const(rb_mProcess, "P_ALL", INT2FIX(P_ALL));
|
941
962
|
#endif
|
942
963
|
|
943
964
|
#ifdef HAVE_CONST_P_PGID
|
944
|
-
|
945
|
-
|
965
|
+
/* Process group ID */
|
966
|
+
rb_define_const(rb_mProcess, "P_PGID", INT2FIX(P_PGID));
|
946
967
|
#endif
|
947
968
|
|
948
969
|
#ifdef HAVE_CONST_P_PID
|
949
|
-
|
950
|
-
|
970
|
+
/* Process ID */
|
971
|
+
rb_define_const(rb_mProcess, "P_PID", INT2FIX(P_PID));
|
951
972
|
#endif
|
952
973
|
|
953
974
|
#ifdef HAVE_CONST_P_CID
|
954
|
-
|
955
|
-
|
975
|
+
/* Process scheduler class ID */
|
976
|
+
rb_define_const(rb_mProcess, "P_CID", INT2FIX(P_CID));
|
956
977
|
#endif
|
957
978
|
|
958
979
|
#ifdef HAVE_CONST_P_GID
|
959
|
-
|
960
|
-
|
980
|
+
/* Non-system process effective group ID */
|
981
|
+
rb_define_const(rb_mProcess, "P_GID", INT2FIX(P_GID));
|
961
982
|
#endif
|
962
983
|
|
963
984
|
#ifdef HAVE_CONST_P_MYID
|
964
|
-
|
965
|
-
|
985
|
+
/* Process ID of the calling process */
|
986
|
+
rb_define_const(rb_mProcess, "P_MYID", INT2FIX(P_MYID));
|
966
987
|
#endif
|
967
988
|
|
968
989
|
#ifdef HAVE_CONST_P_SID
|
969
|
-
|
970
|
-
|
990
|
+
/* Non-system process session ID */
|
991
|
+
rb_define_const(rb_mProcess, "P_SID", INT2FIX(P_SID));
|
971
992
|
#endif
|
972
993
|
|
973
994
|
#ifdef HAVE_CONST_P_UID
|
974
|
-
|
975
|
-
|
995
|
+
/* Non-system process effective user ID */
|
996
|
+
rb_define_const(rb_mProcess, "P_UID", INT2FIX(P_UID));
|
976
997
|
#endif
|
977
998
|
|
978
999
|
#ifdef HAVE_CONST_P_TASKID
|
979
|
-
|
980
|
-
|
1000
|
+
/* Process task ID */
|
1001
|
+
rb_define_const(rb_mProcess, "P_TASKID", INT2FIX(P_TASKID));
|
981
1002
|
#endif
|
982
1003
|
|
983
1004
|
#ifdef HAVE_CONST_P_PROJID
|
984
|
-
|
985
|
-
|
1005
|
+
/* Process project ID */
|
1006
|
+
rb_define_const(rb_mProcess, "P_PROJID", INT2FIX(P_PROJID));
|
986
1007
|
#endif
|
987
1008
|
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
1009
|
+
/* Constants for getrlimit, setrlimit. It appears that these are defined
|
1010
|
+
* by Ruby as of 1.8.5. We'll only set the RLIMIT constants for Ruby 1.8.4
|
1011
|
+
* or earlier.
|
1012
|
+
*/
|
992
1013
|
#ifndef RUBY_HAS_RLIMIT
|
993
|
-
|
994
|
-
|
1014
|
+
/* Maximum size of the process' mapped address space, in bytes */
|
1015
|
+
rb_define_const(rb_mProcess, "RLIMIT_AS", INT2FIX(RLIMIT_AS));
|
995
1016
|
|
996
|
-
|
997
|
-
|
1017
|
+
/* Maximum size of a core file in bytes that may be created */
|
1018
|
+
rb_define_const(rb_mProcess, "RLIMIT_CORE", INT2FIX(RLIMIT_CORE));
|
998
1019
|
|
999
|
-
|
1000
|
-
|
1020
|
+
/* Maximum amount of CPU time, in seconds, the process is allowed to use */
|
1021
|
+
rb_define_const(rb_mProcess, "RLIMIT_CPU", INT2FIX(RLIMIT_CPU));
|
1001
1022
|
|
1002
|
-
|
1003
|
-
|
1023
|
+
/* Maximum size of the process' heap, in bytes */
|
1024
|
+
rb_define_const(rb_mProcess, "RLIMIT_DATA", INT2FIX(RLIMIT_DATA));
|
1004
1025
|
|
1005
|
-
|
1006
|
-
|
1026
|
+
/* Maximum size of a file, in bytes, that the process may create */
|
1027
|
+
rb_define_const(rb_mProcess, "RLIMIT_FSIZE", INT2FIX(RLIMIT_FSIZE));
|
1007
1028
|
|
1008
|
-
|
1009
|
-
|
1029
|
+
/* The maximum value that the kernel may assign to a file descriptor */
|
1030
|
+
rb_define_const(rb_mProcess, "RLIMIT_NOFILE", INT2FIX(RLIMIT_NOFILE));
|
1010
1031
|
|
1011
|
-
|
1012
|
-
|
1032
|
+
/* The maximum size of the process' stack, in bytes */
|
1033
|
+
rb_define_const(rb_mProcess, "RLIMIT_STACK", INT2FIX(RLIMIT_STACK));
|
1013
1034
|
|
1014
|
-
|
1015
|
-
|
1035
|
+
/* No limit on the resource */
|
1036
|
+
rb_define_const(rb_mProcess, "RLIM_INFINITY", RLIM2NUM(RLIM_INFINITY));
|
1016
1037
|
|
1017
|
-
|
1018
|
-
|
1038
|
+
/* Set the limit to the corresponding saved hard limit */
|
1039
|
+
rb_define_const(rb_mProcess, "RLIM_SAVED_MAX", RLIM2NUM(RLIM_SAVED_MAX));
|
1019
1040
|
|
1020
|
-
|
1021
|
-
|
1041
|
+
/* Set the limit to the corresponding saved soft limit */
|
1042
|
+
rb_define_const(rb_mProcess, "RLIM_SAVED_CUR", RLIM2NUM(RLIM_SAVED_CUR));
|
1022
1043
|
|
1023
1044
|
#ifdef RLIMIT_MEMLOCK
|
1024
|
-
|
1025
|
-
|
1045
|
+
/* The maximum number of bytes that may be locked into RAM */
|
1046
|
+
rb_define_const(rb_mProcess, "RLIMIT_MEMLOCK", INT2FIX(RLIMIT_MEMLOCK));
|
1026
1047
|
#endif
|
1027
1048
|
|
1028
1049
|
#ifdef RLIMIT_VMEM
|
1029
|
-
|
1030
|
-
|
1050
|
+
/* Synonym for RLIMIT_AS */
|
1051
|
+
rb_define_const(rb_mProcess, "RLIMIT_VMEM", INT2FIX(RLIMIT_VMEM));
|
1031
1052
|
#endif
|
1032
1053
|
#endif
|
1033
1054
|
|
1034
|
-
|
1035
|
-
|
1055
|
+
/* 1.5.6: The version of the proc-wait3 library */
|
1056
|
+
rb_define_const(rb_mProcess, "WAIT3_VERSION", rb_str_new2("1.5.6"));
|
1036
1057
|
|
1037
|
-
|
1038
|
-
|
1058
|
+
/* Define this last in our Init_wait3 function */
|
1059
|
+
rb_define_readonly_variable("$?", &v_last_status);
|
1039
1060
|
}
|