Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display a list of all the processes listed by their autogroup (CONFIG_SCHED_AUTOGROUP).
#!/usr/bin/env ruby
$autogroups = {}
Dir.glob('/proc/*').each do |e|
pid = File.basename(e).to_i
next if pid == 0
begin
cmdline = File.read(e + '/cmdline').split("\0")
cmdline = cmdline.first.split(" ") if cmdline.size == 1
next if cmdline.empty?
tmp = File.read(e + '/autogroup')
if tmp =~ %r{^/autogroup-(\d+) nice (\d)+$}
autogroup = $1
else
autogroup = nil
end
$autogroups[autogroup] ||= []
$autogroups[autogroup] << [pid, cmdline]
rescue Errno::ENOENT
next
end
end
$autogroups.each do |group, values|
puts '------------------------------------------------------------------------------'
values.each do |pid, cmd|
printf("%s\t%s\n", pid, cmd.join(' ')) if cmd
end
end
puts '------------------------------------------------------------------------------'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment