multithreading - Kill system process in Thread ruby -
how can kill ping (or other longest without timeout , etc system process)(ping - it's simple example) in ruby thread:
a = thread.new system 'ping localhost' end a.kill a.exit a.terminate while true sleep 5 p a.alive? end output:=>
ping localhost.localdomain (127.0.0.1) 56(84) bytes of data. 64 bytes localhost.localdomain (127.0.0.1): icmp_req=1 ttl=64 time=0.023 ms .... true 64 bytes localhost.localdomain (127.0.0.1): icmp_req=7 ttl=64 time=0.022 ms ..... true ...... so need stop ping process thread, don't know how it.
system not give pid.
use process::spawn instead. , use process::kill kill process using pid returned process::spawn.
for example:
pid = process.spawn('ping localhost') sleep 3 process.kill(:term, pid) process.wait(pid)
Comments
Post a Comment