Skip to content

Instantly share code, notes, and snippets.

@pricees
Last active April 25, 2017 05:51
Show Gist options
  • Save pricees/e78df9b1b709bfe85a0dde24617231f1 to your computer and use it in GitHub Desktop.
Save pricees/e78df9b1b709bfe85a0dde24617231f1 to your computer and use it in GitHub Desktop.
Show Ruby Native Threads
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