#!/usr/bin/python -t
# -*- coding: utf-8 -*-
#Author: James Antill <james.antill@redhat.com>
#Contributors:
#    Sam Gleske <sag47@drexel.edu>

#Source1: http://www.redhat.com/archives/rhl-list/2009-July/msg00228.html
#Source2: http://markmail.org/message/dodinyrhwgey35mh
#Acquired Fri Nov  9 09:09:28 EST 2012

#Successfully tested environments:
#  Ubuntu 12.04.1 LTS (Kubuntu)
#    Python 2.7.3
#  Red Hat Enterprise Linux Server release 6.3 (Santiago)
#    Python 2.6.6

#DESCRIPTION:
#  Check /proc directory for programs with open file handles to
#  deleted files.  Meaning the program is using the file in memory but the
#  it has been removed from the filesystem (such as a library).
#  
#  The purpose of this script is to safely determine which services should
#  be restarted after updating many packages on a server.
#
#  Note that a few entries in this list are "normal" e.g. a program opens a 
#  file for temporary storage, and then deletes it (but keeps the handle), 
#  but most will indicate a process that needs to be restarted to reload 
#  files from a new package.


#USAGE: 
#  Run with default behavior.  This will group by file name.
#    python wasted-ram-updates.py
#  Group output by pids so that you can see which files the process has open.
#    python wasted-ram-updates.py pids
#  Only show a summary.
#    python wasted-ram-updates.py summary

import os
import sys


# Decent (UK/US English only) number formatting.
import locale
locale.setlocale(locale.LC_ALL, '') 

#help documentation
if len(sys.argv) > 1 and (sys.argv[1] == "-h" or sys.argv[1] == "--help"):
  print """
NAME: