Created
April 27, 2017 16:07
-
-
Save pricees/8a57737b26758cfc4a3232e98a76cc48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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