Skip to content

Instantly share code, notes, and snippets.

@pricees
Created April 27, 2017 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pricees/8a57737b26758cfc4a3232e98a76cc48 to your computer and use it in GitHub Desktop.
Save pricees/8a57737b26758cfc4a3232e98a76cc48 to your computer and use it in GitHub Desktop.
count = (ARGV.first || 3).to_i
puts "Creating #{count} threads"
threads = count.times.map do |n|
num = n + 1
puts "Creating thread #{num}"
t = Thread.new do
loop do
puts "Thread #{num}"
sleep rand(2..5)
end
end
end
t2 = Thread.new do
loop do
puts %{sudo dtruss -ap #{Process.pid} 2>&1 | sed -e "s/:.*//g"}
sleep 1
end
end
(threads + [t2]).each(&:join)
# PID SPID TTY TIME CMD
# 11947 11947 pts/1 00:00:00 ruby
# 11947 11975 pts/1 00:00:00 ruby-timer-thr
# 11947 11976 pts/1 00:00:00 threads.rb:1
# 11947 11977 pts/1 00:00:00 threads.rb:8
# 11947 11978 pts/1 00:00:00 threads.rb:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment