Strange consumption CPU for a quite small program

Hello,

Below my little program for Linux (because I use ps command)

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
require ‘socket’

Thread.abort_on_exception=true

pid=Process.fork do
##Processus 1
thread=Thread.new do
tcp_server = TCPServer.new(‘0.0.0.0’,10000)
socket = tcp_server.accept
end
thread.join
end

#Porcessus 2
while true
output=’’
IO.popen(“ps -p #{pid} -o pcpu,size”) do |pipe|
output=pipe.read
end
puts output
sleep(1)
end
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

When I execute this program (with ruby 1.8.7 or 1.9.2) and after 10
steps, I can see process 1 consumes CPU, why ?

Best regards

On Fri, Oct 22, 2010 at 2:58 PM, Guillaume Ebuprofen
[email protected] wrote:

##Processus 1
IO.popen(“ps -p #{pid} -o pcpu,size”) do |pipe|
output=pipe.read
end
puts output
sleep(1)
end
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

When I execute this program (with ruby 1.8.7 or 1.9.2) and after 10
steps, I can see process 1 consumes CPU, why ?

I see

15:08:16 Temp$ ruby19 so.rb
so.rb:8: [BUG] native_mutex_unlock return non-zero: 1
ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-cygwin]

– control frame ----------
c:0005 p:---- s:0015 b:0015 l:000014 d:000014 CFUNC :initialize
c:0004 p:---- s:0013 b:0013 l:000012 d:000012 CFUNC :new
c:0003 p:0019 s:0008 b:0008 l:000764 d:000007 BLOCK so.rb:8
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP

– Ruby level backtrace
information-----------------------------------------
so.rb:8:in initialize' so.rb:8:innew’
so.rb:8:in `block (2 levels) in ’

[NOTE]
You may encounter a bug of Ruby interpreter. Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Btw, why don’t you just do

require ‘socket’

Thread.abort_on_exception=true

pid=fork do
tcp_server = TCPServer.new(‘0.0.0.0’,10000)
socket = tcp_server.accept
end

#Porcessus 2
loop do
system “ps”, “-p”, pid.to_s, “-o”, “pcpu,size”
sleep(1)
end

Kind regards

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs