Last active
April 25, 2017 05:51
-
-
Save pricees/e78df9b1b709bfe85a0dde24617231f1 to your computer and use it in GitHub Desktop.
Show Ruby Native Threads
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
t = Thread.new do | |
loop do | |
puts "Thread 1" | |
sleep rand(3) | |
end | |
end | |
t1 = Thread.new do | |
loop do | |
puts "\tThread 2" | |
sleep rand(3) | |
end | |
end | |
t2 = Thread.new do | |
loop do | |
puts "Check for 3 native threads\n\t$ ps -T -p #{Process.pid}" | |
sleep 1 | |
end | |
end | |
[t, t1, 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