Skip to content

Instantly share code, notes, and snippets.

@nelhage
Created March 28, 2014 06:12
Show Gist options
  • Save nelhage/9826397 to your computer and use it in GitHub Desktop.
Save nelhage/9826397 to your computer and use it in GitHub Desktop.
Is this pid (using epoll, on amd64, on EM 1.0.0) currently blocked in the EM mainloop?
def is_in_eventmachine(pid)
begin
syscall = File.read("/proc/#{pid}/syscall")
rescue Errno::ENOENT
return false
end
words = syscall.split(" ")
if words.length != 9
# Running, or in an fault handler
return false
end
scno = words[0].to_i
if scno != 23
# 23 is select on amd64
return false
end
if !words[3].to_i(16).zero? || !words[4].to_i(16).zero?
# Non-empty writer or exception lists -- not eventmachine
return false
end
if words[5].to_i(16).zero?
# NULL timeout -- not eventmachine
return false
end
maxfd = words[1].to_i(16)
emfd = maxfd - 1
begin
fd = File.readlink("/proc/#{pid}/fd/#{emfd}")
rescue Errno::ENOENT
return false
end
return fd == "anon_inode:[eventpoll]"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment