Skip to content

Instantly share code, notes, and snippets.

@felipec
Last active November 22, 2020 04:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipec/7303244 to your computer and use it in GitHub Desktop.
Save felipec/7303244 to your computer and use it in GitHub Desktop.
Display a list of all the processes listed by their autogroup (CONFIG_SCHED_AUTOGROUP)
#!/usr/bin/env ruby
$autogroups = Hash.new { |h,k| h[k] = [] }
Dir.glob('/proc/*').each do |e|
pid = File.basename(e).to_i
next if pid == 0
begin
cmdline = File.read(e + '/cmdline').split("\0").join(" ")
next if cmdline.empty?
if File.read(e + '/autogroup') =~ %r{^/autogroup-(\d+)}
autogroup = $1.to_i
else
autogroup = nil
end
$autogroups[autogroup] << [pid, cmdline]
rescue Errno::ENOENT
next
end
end
$autogroups.values.each do |e|
puts '-' * 80
e.each { |cmd| puts "%s\t%s" % cmd }
end
puts '-' * 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment