⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (562 Bytes)
Bug #6725
ยป test-signal.rb
375gnu (Hleb Valoshka)
, 07/12/2012 04:59 PM
require
'dl/import'
module
LibC
extend
DL
::
Importer
dlload
'libc.so.6'
extern
'int alarm(int)'
end
alarm
=
0
interval
=
(
ENV
[
'interval'
]
or
1
).
to_i
delta
=
interval
+
0.01
# on my box it's 0.001 for 1.9.3p194 and 0.01 for 2.0.0dev
t0
=
t1
=
Time
.
now
trap
(
:ALRM
)
{
alarm
+=
1
;
t1
=
Time
.
now
}
LibC
::
alarm
(
interval
)
ret
=
IO
.
readlines
(
ARGV
[
0
])
rescue
nil
puts
"alarm=
#{
alarm
}
, time=
#{
t1
}
, interval=
#{
t1
-
t0
}
"
sleep
0
if
ENV
[
'sleep'
]
# [1]
while
Time
.
now
-
t0
<
delta
;
end
if
ENV
[
'interval'
]
# [2]
puts
"alarm=
#{
alarm
}
, time=
#{
t1
}
, interval=
#{
t1
-
t0
}
"
(1-1/1)
Loading...