1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#!/usr/bin/env oo-ruby # # # require 'etc' def get_ps_users() uids = %x[ps -o user -e].split("\n").grep(/^[1-6]{4}/).uniq! usernames = uids.collect do |uid| Etc.getpwuid(uid.to_i).name end return usernames end def main() kernel_sem = %x[/sbin/sysctl kernel.sem].split[-1] results = %x[ /usr/bin/ipcs -s -c].split("\n")[1..-1] user_semaphores = Hash.new(Array.new) results.each do |result| values = result.split next unless values[2] =~ /[a-z0-9]{24}/ user_semaphores[values[2]] += [values[0]] end users_with_procs = get_ps_users() users_without_procs = user_semaphores.keys - users_with_procs all_semaphores = [] users_without_procs.collect do |user| all_semaphores += user_semaphores[user] end cmd_str = ("-s %s " * all_semaphores.size) % all_semaphores puts %x[/usr/bin/ipcrm #{cmd_str}] puts "Cleaned #{all_semaphores.size} semaphores." end if __FILE__ == $0 main() end |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021