kill_process 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/ext/extconf.rb +1 -1
- data/ext/kill_process_native.c +36 -30
- data/lib/kill_process.rb +4 -1
- data/lib/kill_process/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78d656160b9d6418bed23e50ad351e6623d2707d
|
4
|
+
data.tar.gz: e6b27120a7ea1f5536ddfed99a08d912eae14505
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc2bcc06c8bc517d054672dce90ba7c2c0213d4d59b12ec333e01b1e1a760636409fd0ab9db3531ff6bf9a4878e29c8446c61e42670ba650f0916feeb553296f
|
7
|
+
data.tar.gz: e715680a2811e3afde35bfcf831c31c9f72c0259f8b214b802b64365e26706058bb552b5fc2160f3dccc5686732ab7a0c18bea74caf4346733c2f971d6138af4
|
data/README.md
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
# KillProcess
|
2
2
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kill_process`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
|
-
|
7
3
|
## Installation
|
8
4
|
|
9
5
|
Add this line to your application's Gemfile:
|
data/ext/extconf.rb
CHANGED
data/ext/kill_process_native.c
CHANGED
@@ -4,38 +4,44 @@
|
|
4
4
|
#include <time.h>
|
5
5
|
#include <pthread.h>
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
7
|
+
#if _POSIX_C_SOURCE >= 199309L
|
8
|
+
VALUE rb_posix_timer_set(VALUE self, VALUE seconds) {
|
9
|
+
struct sigevent sev;
|
10
|
+
timer_t tidlist;
|
11
|
+
int return_val;
|
12
|
+
struct timespec zero_time;
|
13
|
+
struct timespec timeout_value;
|
14
|
+
struct itimerspec timer_spec;
|
15
|
+
double dbl_seconds = NUM2DBL(seconds);
|
16
|
+
|
17
|
+
zero_time.tv_sec = 0;
|
18
|
+
zero_time.tv_nsec = 0;
|
19
|
+
|
20
|
+
timeout_value.tv_sec = (int)floor(dbl_seconds);
|
21
|
+
timeout_value.tv_nsec = 0;
|
22
|
+
|
23
|
+
timer_spec.it_interval = zero_time;
|
24
|
+
timer_spec.it_value = timeout_value;
|
25
|
+
|
26
|
+
sev.sigev_notify = SIGEV_SIGNAL;
|
27
|
+
sev.sigev_signo = 9; //SIGKILL
|
28
|
+
|
29
|
+
return_val = timer_create(CLOCK_REALTIME, &sev, &tidlist);
|
30
|
+
if (return_val != 0) {
|
31
|
+
rb_sys_fail(0);
|
32
|
+
}
|
33
|
+
return_val = timer_settime(tidlist, 0, &timer_spec, NULL);
|
34
|
+
if (return_val != 0) {
|
35
|
+
rb_sys_fail(0);
|
36
|
+
}
|
37
|
+
|
38
|
+
return Qtrue;
|
31
39
|
}
|
32
|
-
|
33
|
-
|
34
|
-
|
40
|
+
#else
|
41
|
+
VALUE rb_posix_timer_set(VALUE self, VALUE seconds) {
|
42
|
+
return Qfalse;
|
35
43
|
}
|
36
|
-
|
37
|
-
return Qtrue;
|
38
|
-
}
|
44
|
+
#endif
|
39
45
|
|
40
46
|
void Init_kill_process_native(void) {
|
41
47
|
VALUE kill_process_module = rb_const_get(rb_cObject, rb_intern("KillProcess"));
|
data/lib/kill_process.rb
CHANGED
@@ -4,7 +4,10 @@ module KillProcess
|
|
4
4
|
require_relative './kill_process_native'
|
5
5
|
|
6
6
|
def self.after(seconds)
|
7
|
-
posix_timer_set(seconds)
|
7
|
+
success = posix_timer_set(seconds)
|
8
|
+
if !success
|
9
|
+
Kernel.warn "WARNING: KillProcess#after will not do anything because your system does not support POSIX advanced realtime timers"
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
end
|
data/lib/kill_process/version.rb
CHANGED