Project

General

Profile

« Previous | Next » 

Revision 2b1dcc1d

Added by Eric Wong almost 7 years ago

thread_pthread.c: fix memory leak from fork loop leapfrog

Constantly forking a single-threaded process in a loop leads to
a memory leak when using POSIX timers.

==> fork_leapfrog.rb <==
require 'io/wait'
Dir.chdir '/proc'
prev = 0
loop do
pid = fork
exit!(0) if pid

show the number of 4K pages used (Linux-only)

n = File.read("#$$/statm").split(-' ')[1].to_i
if n > prev
puts "#{prev} => #{n}"
prev = n
end

since Ctrl-C from a terminal can't stop this loop,

allow the user to just hit any key to stop

break if STDIN.wait(0)
end

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e