ps_mem.py

This commit is contained in:
milisarge 2017-06-05 05:11:52 +03:00
parent c89cac6aab
commit 3bac0f5a52
12 changed files with 611 additions and 2752 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,40 +0,0 @@
#!/bin/bash
#Milis-Linux kurulum yardımcısı
umount /mnt
clear
echo "Milis Linux Kurulumu"
echo ""
echo "Yeni kullanıcı adını giriniz:"
read user
useradd $user
passwd $user
clear
echo "Milis Linux Kurulumu"
echo ""
echo "hangi diske kurulum yapacaksınız:"
ls /dev/sd*
read disk
clear
echo "Milis Linux Kurulumu"
echo ""
echo "Grubu nereye kuracaksınız:"
ls /dev/sd*
read grub
clear
echo "Milis Linux Kurulumu"
echo ""
echo "Kurulum başlıyor"
mkfs.ext4 /dev/$disk
mount $disk /mnt
echo "Dosyalar Kopyalanıyor"
cp -axvnu / /mnt
echo "Kernel ayarları yapılıyor"
chroot /mnt dracut --no-hostonly --add-drivers "ahci" -f /boot/initramfs
echo "Grub ayarlanıyor"
grub-install --boot-directory=/mnt/boot /$grub
grub-mkconfig -o /mnt/boot/grub/grub.cfg
clear
echo "Milis Linux Kurulumu"
echo ""
clear
echo "Milis kuruldu bilgisayarınızı yeniden başlatınız..."

View File

@ -1,2 +0,0 @@
mpsd -d -cf /etc/mpsd.conf
for PACK in *.xz; do /tools/bin/pkgadd -r / $PACK;done

View File

@ -1 +0,0 @@
python setup.py install

View File

@ -1,620 +0,0 @@
#!/bin/bash
#
# pkgutils
#
# Copyright (c) 2000-2005 Per Liden
# Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
#
info() {
echo "=======> $1"
}
warning() {
info "WARNING: $1" >&2
}
error() {
info "ERROR: $1" >&2
}
get_filename() {
local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
if [ "$FILE" != "$1" ]; then
FILE="$PKGMK_SOURCE_DIR/$FILE"
fi
echo $FILE
}
get_basename() {
local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
echo $FILE
}
check_pkgfile() {
if [ "`type -t build`" != "function" ]; then
error "Function 'build' not specified in $PKGMK_PKGFILE."
exit 1
fi
}
check_directory() {
if [ ! -d $1 ]; then
error "Directory '$1' does not exist."
exit 1
# elif [ ! -w $1 ]; then
# error "Directory '$1' not writable."
# exit 1
elif [ ! -x $1 ] || [ ! -r $1 ]; then
error "Directory '$1' not readable."
exit 1
fi
}
download_file() {
info "Downloading '$1'."
if [ ! "`type -p wget`" ]; then
error "Command 'wget' not found."
exit 1
fi
LOCAL_FILENAME=`get_filename $1`
LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial"
DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \
--directory-prefix=$PKGMK_SOURCE_DIR \
--output-document=$LOCAL_FILENAME_PARTIAL"
if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
info "Partial download found, trying to resume"
RESUME_CMD="-c"
fi
error=1
BASENAME=`get_basename $1`
for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do
REPO="`echo $REPO | sed 's|/$||'`"
wget $RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME
error=$?
if [ $error == 0 ]; then
break
fi
done
if [ $error != 0 ]; then
while true; do
wget $RESUME_CMD $DOWNLOAD_OPTS $1
error=$?
if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
info "Partial download failed, restarting"
rm -f "$LOCAL_FILENAME_PARTIAL"
RESUME_CMD=""
else
break
fi
done
fi
if [ $error != 0 ]; then
error "Downloading '$1' failed."
exit 1
fi
mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
}
download_source() {
local FILE LOCAL_FILENAME
for FILE in ${source[@]}; do
LOCAL_FILENAME=`get_filename $FILE`
if [ ! -e $LOCAL_FILENAME ]; then
if [ "$LOCAL_FILENAME" = "$FILE" ]; then
error "Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
exit 1
else
if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
download_file $FILE
else
error "Source file '$LOCAL_FILENAME' not found (use option -d to download)."
exit 1
fi
fi
fi
done
}
unpack_source() {
local FILE LOCAL_FILENAME COMMAND
for FILE in ${source[@]}; do
LOCAL_FILENAME=`get_filename $FILE`
case $LOCAL_FILENAME in
*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
COMMAND="tar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
*)
COMMAND="cp $LOCAL_FILENAME $SRC" ;;
esac
echo "$COMMAND"
$COMMAND
if [ $? != 0 ]; then
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
error " '$TARGET' derlenmesi basarisiz"
exit 1
fi
done
}
make_md5sum() {
local FILE LOCAL_FILENAMES
if [ "$source" ]; then
for FILE in ${source[@]}; do
LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`"
done
md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
fi
}
make_footprint() {
pkginfo --footprint $TARGET | \
sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
sort -k 3
}
check_md5sum() {
local FILE="$PKGMK_WORK_DIR/.tmp"
cd $PKGMK_ROOT
if [ -f $PKGMK_MD5SUM ]; then
make_md5sum > $FILE.md5sum
sort -k 2 $PKGMK_MD5SUM > $FILE.md5sum.orig
diff -w -t -U 0 $FILE.md5sum.orig $FILE.md5sum | \
sed '/^@@/d' | \
sed '/^+++/d' | \
sed '/^---/d' | \
sed 's/^+/NEW /g' | \
sed 's/^-/MISSING /g' > $FILE.md5sum.diff
if [ -s $FILE.md5sum.diff ]; then
error "Md5sum mismatch found:"
cat $FILE.md5sum.diff >&2
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
error "Md5sum not ok."
exit 1
fi
error "Building '$TARGET' failed."
exit 1
fi
else
if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
info "Md5sum not found."
exit 1
fi
warning "Md5sum not found, creating new."
make_md5sum > $PKGMK_MD5SUM
fi
if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
info "Md5sum ok."
exit 0
fi
}
strip_files() {
local FILE FILTER
cd $PKG
if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
else
FILTER="cat"
fi
find . -type f -printf "%P\n" | $FILTER | while read FILE; do
case $(file -b "$FILE") in
*ELF*executable*not\ stripped)
strip --strip-all "$FILE"
;;
*ELF*shared\ object*not\ stripped)
strip --strip-unneeded "$FILE"
;;
current\ ar\ archive)
strip --strip-debug "$FILE"
esac
done
}
compress_manpages() {
local FILE DIR TARGET
cd $PKG
find . -type f -path "*/man/man*/*" | while read FILE; do
if [ "$FILE" = "${FILE%%.gz}" ]; then
gzip -9 "$FILE"
fi
done
find . -type l -path "*/man/man*/*" | while read FILE; do
TARGET=`readlink -n "$FILE"`
TARGET="${TARGET##*/}"
TARGET="${TARGET%%.gz}.gz"
rm -f "$FILE"
FILE="${FILE%%.gz}.gz"
DIR=`dirname "$FILE"`
if [ -e "$DIR/$TARGET" ]; then
ln -sf "$TARGET" "$FILE"
fi
done
}
check_footprint() {
local FILE="$PKGMK_WORK_DIR/.tmp"
cd $PKGMK_ROOT
if [ -f $TARGET ]; then
make_footprint > $FILE.footprint
if [ -f $PKGMK_FOOTPRINT ]; then
sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
diff -w -t -U 0 $FILE.footprint.orig $FILE.footprint | \
sed '/^@@/d' | \
sed '/^+++/d' | \
sed '/^---/d' | \
sed 's/^+/NEW /g' | \
sed 's/^-/MISSING /g' > $FILE.footprint.diff
if [ -s $FILE.footprint.diff ]; then
error "Footprint mismatch found:"
cat $FILE.footprint.diff >&2
BUILD_SUCCESSFUL="no"
fi
else
warning "Footprint not found, creating new."
mv $FILE.footprint $PKGMK_FOOTPRINT
fi
else
error "Package '$TARGET' was not found."
BUILD_SUCCESSFUL="no"
fi
}
build_package() {
local BUILD_SUCCESSFUL="no"
export PKG="/"
export SRC="$PKGMK_WORK_DIR/src"
umask 022
cd $PKGMK_ROOT
rm -rf $PKGMK_WORK_DIR
mkdir -p $SRC
info "Building '$TARGET'."
if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
download_source
fi
unpack_source
cd $SRC
(set -e -x ; build)
# cd $PKG
if [ $? = 0 ]; then
BUILD_SUCCESSFUL="yes"
fi
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
info " '$TARGET' derleme basarili"
else
if [ -f $TARGET ]; then
touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null
fi
error " '$TARGET' derleme basarisiz"
exit 1
fi
}
install_package() {
local COMMAND
info "Installing '$TARGET'."
if [ "$PKGMK_INSTALL" = "install" ]; then
COMMAND="pkgadd $TARGET"
else
COMMAND="pkgadd -u $TARGET"
fi
cd $PKGMK_ROOT
echo "$COMMAND"
$COMMAND
if [ $? = 0 ]; then
info "Installing '$TARGET' succeeded."
else
error "Installing '$TARGET' failed."
exit 1
fi
}
recursive() {
local ARGS FILE DIR
ARGS=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
for FILE in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
DIR="`dirname $FILE`/"
if [ -d $DIR ]; then
info "Entering directory '$DIR'."
(cd $DIR && $PKGMK_COMMAND $ARGS)
info "Leaving directory '$DIR'."
fi
done
}
clean() {
local FILE LOCAL_FILENAME
if [ -f $TARGET ]; then
info "Removing $TARGET"
rm -f $TARGET
fi
for FILE in ${source[@]}; do
LOCAL_FILENAME=`get_filename $FILE`
if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
info "Removing $LOCAL_FILENAME"
rm -f $LOCAL_FILENAME
fi
done
}
update_footprint() {
if [ ! -f $TARGET ]; then
error "Unable to update footprint. File '$TARGET' not found."
exit 1
fi
make_footprint > $PKGMK_FOOTPRINT
touch $TARGET
info "Footprint updated."
}
build_needed() {
local FILE RESULT
RESULT="yes"
if [ -f $TARGET ]; then
RESULT="no"
for FILE in $PKGMK_PKGFILE ${source[@]}; do
FILE=`get_filename $FILE`
if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
RESULT="yes"
break
fi
done
fi
echo $RESULT
}
interrupted() {
echo ""
error "Interrupted."
if [ "$PKGMK_KEEP_WORK" = "no" ]; then
rm -rf $PKGMK_WORK_DIR
fi
exit 1
}
print_help() {
echo "usage: `basename $PKGMK_COMMAND` [options]"
echo "options:"
echo " -i, --install build and install package"
echo " -u, --upgrade build and install package (as upgrade)"
echo " -r, --recursive search for and build packages recursively"
echo " -d, --download download missing source file(s)"
echo " -do, --download-only do not build, only download missing source file(s)"
echo " -utd, --up-to-date do not build, only check if package is up to date"
echo " -uf, --update-footprint update footprint using result from last build"
echo " -if, --ignore-footprint build package without checking footprint"
echo " -um, --update-md5sum update md5sum"
echo " -im, --ignore-md5sum build package without checking md5sum"
echo " -cm, --check-md5sum do not build, only check md5sum"
echo " -ns, --no-strip do not strip executable binaries or libraries"
echo " -f, --force build package even if it appears to be up to date"
echo " -c, --clean remove package and downloaded files"
echo " -kw, --keep-work keep temporary working directory"
echo " -cf, --config-file <file> use alternative configuration file"
echo " -v, --version print version and exit "
echo " -h, --help print help and exit"
}
remove_locale() {
cd $PKG/usr/share
if [ -d locale/fr ]; then
mv locale/fr fr
fi
rm -rf locale
if [ -d fr ]; then
mkdir locale
mv fr locale/
fi
}
parse_options() {
while [ "$1" ]; do
case $1 in
-i|--install)
PKGMK_INSTALL="install" ;;
-u|--upgrade)
PKGMK_INSTALL="upgrade" ;;
-r|--recursive)
PKGMK_RECURSIVE="yes" ;;
-d|--download)
PKGMK_DOWNLOAD="yes" ;;
-do|--download-only)
PKGMK_DOWNLOAD="yes"
PKGMK_DOWNLOAD_ONLY="yes" ;;
-utd|--up-to-date)
PKGMK_UP_TO_DATE="yes" ;;
-uf|--update-footprint)
PKGMK_UPDATE_FOOTPRINT="yes" ;;
-if|--ignore-footprint)
PKGMK_IGNORE_FOOTPRINT="yes" ;;
-um|--update-md5sum)
PKGMK_UPDATE_MD5SUM="yes" ;;
-im|--ignore-md5sum)
PKGMK_IGNORE_MD5SUM="yes" ;;
-cm|--check-md5sum)
PKGMK_CHECK_MD5SUM="yes" ;;
-ns|--no-strip)
PKGMK_NO_STRIP="yes" ;;
-f|--force)
PKGMK_FORCE="yes" ;;
-c|--clean)
PKGMK_CLEAN="yes" ;;
-kw|--keep-work)
PKGMK_KEEP_WORK="yes" ;;
-kl|--keep-locale)
PKGMK_KEEP_LOCALE="yes" ;;
-cf|--config-file)
if [ ! "$2" ]; then
echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
exit 1
fi
PKGMK_CONFFILE="$2"
shift ;;
-v|--version)
echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
exit 0 ;;
-h|--help)
print_help
exit 0 ;;
*)
echo "`basename $PKGMK_COMMAND`: invalid option $1"
exit 1 ;;
esac
shift
done
}
main() {
local FILE TARGET
parse_options "$@"
if [ "$PKGMK_RECURSIVE" = "yes" ]; then
recursive "$@"
exit 0
fi
for FILE in $PKGMK_CONFFILE $PKGMK_PKGFILE ; do
if [ ! -f $FILE ]; then
error "File '$FILE' not found."
exit 1
fi
. $FILE
done
check_directory "$PKGMK_SOURCE_DIR"
check_directory "$PKGMK_PACKAGE_DIR"
check_directory "`dirname $PKGMK_WORK_DIR`"
check_pkgfile
TARGET="$PKGMK_PACKAGE_DIR/$PKGMK_PKGFILE"
if [ "$PKGMK_CLEAN" = "yes" ]; then
clean
exit 0
fi
build_package
exit 0
}
trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
export LC_ALL=POSIX
readonly PKGMK_VERSION="5.32.0"
readonly PKGMK_COMMAND="$0"
readonly PKGMK_ROOT="$PWD"
PKGMK_CONFFILE="paketci.conf"
PKGMK_PKGFILE="talimat"
PKGMK_FOOTPRINT=".footprint"
PKGMK_MD5SUM=".md5sum"
PKGMK_NOSTRIP=".nostrip"
PKGMK_SOURCE_MIRRORS=()
PKGMK_SOURCE_DIR="/mnt/lfs/sources"
PKGMK_PACKAGE_DIR="$PWD"
PKGMK_WORK_DIR="/tmp/work"
PKGMK_RECURSIVE="no"
PKGMK_DOWNLOAD="no"
PKGMK_DOWNLOAD_ONLY="no"
PKGMK_UP_TO_DATE="no"
PKGMK_UPDATE_FOOTPRINT="no"
PKGMK_IGNORE_FOOTPRINT="no"
PKGMK_FORCE="no"
PKGMK_KEEP_WORK="no"
PKGMK_UPDATE_MD5SUM="no"
PKGMK_IGNORE_MD5SUM="yes"
PKGMK_CHECK_MD5SUM="no"
PKGMK_NO_STRIP="no"
PKGMK_CLEAN="no"
PKGMK_KEEP_LOCALE="no"
main "$@"
# End of file

View File

@ -1,3 +0,0 @@
perl Makefile.PL PREFIX=/tools
make test
make install

View File

@ -1 +0,0 @@
python setup.py install --prefix=/tools

View File

@ -1,414 +0,0 @@
#! /bin/bash
usage()
{
cat <<EOF
Usage: $pname [OPTION]
Known values for OPTION are:
--prefix=DIR change the output directory for catalog files
[default $DIR]
--show display the output filenames and paths
--version=x.y.z change the DocBook version [default $VERSION]
--debug display script action information
--help display this help and exit
EOF
}
setdefault()
{
echo Unable to update root catalog $ROOTCATALOG
ROOTCATALOG=$HOME/xmlcatalog
CATALOG=$HOME/dbkxmlcatalog
DIR=$HOME
CAT=xmlcatalog
echo Using $ROOTCATALOG as the root catalog
echo Remember to export XML_CATALOG_FILES=$ROOTCATALOG
echo
prefix=1
}
fixname()
{
#
# ROOTCATALOG contains the full pathname for the catalog. We will
# split that into the directory name and the filename, then we will
# see if the directory exists. If it does not, we will attempt to
# create it.
#
if test $verbose = 1
then
echo Checking path $ROOTCATALOG for permissions
fi
# First we split the filename and directory name
CAT=`basename $ROOTCATALOG`
DIR=`dirname $ROOTCATALOG`
if test "$DIR" = ""
then
echo Unable to isolate directory name from '$ROOTCATALOG' - exiting
exit 1
fi
CATALOG=${DIR}/docbook
parent=`dirname $DIR`
if test "$parent" == ""
then
parent=/
fi
if [ ! -d $DIR ]
then
if test $verbose = 1
then
echo Directory $DIR missing - I will try to create it
fi
if [ ! -w $parent ]
then
if test $verbose = 1
then
echo No write permission for directory $parent
fi
setdefault
else
newdir=1
fi
else
if [ -f $ROOTCATALOG -a ! -w $ROOTCATALOG ] ||
[ -e $ROOTCATALOG -a ! -f $ROOTCATALOG ] ||
[ ! -e $ROOTCATALOG -a ! -w $DIR ]
then
setdefault
fi
fi
}
finddbx()
{
dtd421=""
s="//OASIS//DTD DocBook XML V${VERSION}//EN"
found=`find $1 -name docbookx.dtd -exec grep -l "$s" {} \;`
for dtd in $found; do
docbookdir=`dirname $dtd`
echo Found DocBook XML $VERSION DTD in $docbookdir
#
# The original script had a check for write permission on the file
# but I can't see why it should be necessary
#
dtd421=$dtd
break
done
}
#
# Preset script control params
show=0
prefix=0
newdir=0
verbose=0
#
# Isolate the script name for messages
pname=`basename $0`
VERSION=4.1.2
if test "$XML_CATALOG_FILES" != ""
then
ROOTCATALOG=$XML_CATALOG_FILES
else
ROOTCATALOG=/etc/xml/catalog
fi
#
# Interpret script parameters
while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
esac
case "$1" in
-p=* | --prefix=*)
ROOTCATALOG=$optarg/catalog
prefix=1
;;
-s | --show)
show=1
;;
-v=* | --version=*)
VERSION=$optarg
;;
-d | --debug)
verbose=1
;;
-h | --help)
usage
exit 0
;;
* )
echo Invalid argument "$1"
usage
exit 1
;;
esac
shift
done
fixname
if test $prefix != 0
then
export XML_CATALOG_FILES=$ROOTCATALOG
fi
if test $show != 0
then
echo XML Catalog is $ROOTCATALOG
echo Docbook Catalog is $CATALOG
exit 0
fi
if test $newdir!=0
then
mkdir -p $DIR
chmod 755 $DIR
fi
echo Starting run
#
# create the catalogs root and docbook specific
#
if [ ! -r $ROOTCATALOG ] ; then
echo creating XML Catalog root $ROOTCATALOG
xmlcatalog --noout --create $ROOTCATALOG
fi
if [ ! -r $ROOTCATALOG ] ; then
echo Failed creating XML Catalog root $ROOTCATALOG
exit 1
fi
if [ ! -r $CATALOG ] ; then
echo creating DocBook XML Catalog $CATALOG
xmlcatalog --noout --create $CATALOG
fi
if [ ! -r $CATALOG ] ; then
echo Failed creating DocBook XML Catalog $CATALOG
exit 1
fi
#
# find the prefix for DocBook DTD
#
finddbx /usr/share/xml
if [ "$dtd421" = "" ] ; then
finddbx $HOME
fi
if [ "$dtd421" = "" ] ; then
finddbx /usr/local
fi
if [ "$dtd421" = "" ] ; then
finddbx /usr/share/sgml
fi
if [ "$dtd421" = "" ] ; then
echo could not locate version $VERSION of DocBook XML
exit 1
fi
xmlcatalog --noout --add "public" \
"-//OASIS//ELEMENTS DocBook XML Information Pool V${VERSION}//EN" \
"file://$docbookdir/dbpoolx.mod" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//DTD DocBook XML V${VERSION}//EN" \
"file://$docbookdir/docbookx.dtd" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//ENTITIES DocBook XML Character Entities V${VERSION}//EN" \
"file://$docbookdir/dbcentx.mod" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//ENTITIES DocBook XML Notations V${VERSION}//EN" \
"file://$docbookdir/dbnotnx.mod" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//ENTITIES DocBook XML Additional General Entities V${VERSION}//EN" \
"file://$docbookdir/dbgenent.mod" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${VERSION}//EN" \
"file://$docbookdir/dbhierx.mod" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
"file://$docbookdir/soextblx.dtd" $CATALOG
xmlcatalog --noout --add "public" \
"-//OASIS//DTD DocBook XML CALS Table Model V${VERSION}//EN" \
"file://$docbookdir/calstblx.dtd" $CATALOG
xmlcatalog --noout --add "rewriteSystem" \
"http://www.oasis-open.org/docbook/xml/${VERSION}" \
"file://$docbookdir" $CATALOG
xmlcatalog --noout --add "rewriteURI" \
"http://www.oasis-open.org/docbook/xml/${VERSION}" \
"file://$docbookdir" $CATALOG
xmlcatalog --noout --add "delegatePublic" \
"-//OASIS//ENTITIES DocBook XML" \
"file://$CATALOG" $ROOTCATALOG
xmlcatalog --noout --add "delegatePublic" \
"-//OASIS//DTD DocBook XML" \
"file://$CATALOG" $ROOTCATALOG
xmlcatalog --noout --add "delegateSystem" \
"http://www.oasis-open.org/docbook/" \
"file://$CATALOG" $ROOTCATALOG
xmlcatalog --noout --add "delegateURI" \
"http://www.oasis-open.org/docbook/" \
"file://$CATALOG" $ROOTCATALOG
#
# find the prefix for ISO DocBook entities
#
top=`dirname $docbookdir`
found=`find $top -name isoamsb.ent`
if [ "$found" = "" ] ; then
found=`find /usr/share/xml -name isoamsb.ent`
fi
if [ "$found" = "" ] ; then
found=`find $HOME -name isoamsb.ent`
fi
if [ "$found" = "" ] ; then
found=`find /usr/local -name isoamsb.ent`
fi
if [ "$found" = "" ] ; then
found=`find /usr/share/sgml -name isoamsb.ent`
fi
if [ "$found" = "" ] ; then
echo could not locate isoamsb.ent of ISO DocBook entities
exit 1
fi
entxml=""
for tst in $found; do
check=`grep '<!ENTITY ominus' $tst`
if [ "$check" != "" ] ; then
entxml=$tst
break
fi
done
if [ "$entxml" = "" ] ; then
echo could not locate ISO DocBook entities
exit 1
fi
isodir=`dirname $entxml`
echo Found ISO DocBook entities in $isodir
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Publishing//EN" \
"file://$isodir/isopub.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Greek Letters//EN" \
"file://$isodir/isogrk1.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Box and Line Drawing//EN" \
"file://$isodir/isobox.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Greek Symbols//EN" \
"file://$isodir/isogrk3.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN" \
"file://$isodir/isoamsn.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN" \
"file://$isodir/isonum.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN" \
"file://$isodir/isogrk4.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Diacritical Marks//EN" \
"file://$isodir/isodia.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Monotoniko Greek//EN" \
"file://$isodir/isogrk2.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN" \
"file://$isodir/isoamsa.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN" \
"file://$isodir/isoamso.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Russian Cyrillic//EN" \
"file://$isodir/isocyr1.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES General Technical//EN" \
"file://$isodir/isotech.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN" \
"file://$isodir/isoamsc.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Latin 1//EN" \
"file://$isodir/isolat1.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN" \
"file://$isodir/isoamsb.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Latin 2//EN" \
"file://$isodir/isolat2.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN" \
"file://$isodir/isoamsr.ent" $CATALOG
xmlcatalog --noout --add "public" \
"ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN" \
"file://$isodir/isocyr2.ent" $CATALOG
xmlcatalog --noout --add "delegatePublic" \
"ISO 8879:1986" \
"file://$CATALOG" $ROOTCATALOG
#
# find the prefix for XSLT stylesheets
#
top=`dirname $docbookdir`
found=`find $top -name chunk.xsl`
if [ "$found" = "" ] ; then
found=`find /usr/share/xml -name chunk.xsl`
fi
if [ "$found" = "" ] ; then
found=`find $HOME -name chunk.xsl`
fi
if [ "$found" = "" ] ; then
found=`find /usr/local -name chunk.xsl`
fi
if [ "$found" = "" ] ; then
found=`find /usr/share/sgml -name chunk.xsl`
fi
if [ "$found" = "" ] ; then
echo could not locate chunk-common.xsl of DocBook XSLT stylesheets
exit 1
fi
xsldir=""
for tst in $found; do
dir=`dirname $tst`
dir=`dirname $dir`
if [ -r $dir/html/docbook.xsl -a -r $dir/common/l10n.xml ]; then
xsldir=$dir
break
fi
done
if [ "$xsldir" = "" ] ; then
echo could not locate DocBook XSLT stylesheets
exit 1
fi
echo Found DocBook XSLT stylesheets in $xsldir
for version in current 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 \
1.48 1.49 1.50
do
xmlcatalog --noout --add "rewriteSystem" \
"http://docbook.sourceforge.net/release/xsl/$version" \
"file://$xsldir" $CATALOG
xmlcatalog --noout --add "rewriteURI" \
"http://docbook.sourceforge.net/release/xsl/$version" \
"file://$xsldir" $CATALOG
done
xmlcatalog --noout --add "delegateSystem" \
"http://docbook.sourceforge.net/release/xsl/" \
"file://$CATALOG" $ROOTCATALOG
xmlcatalog --noout --add "delegateURI" \
"http://docbook.sourceforge.net/release/xsl/" \
"file://$CATALOG" $ROOTCATALOG
#
#

View File

@ -1,2 +0,0 @@
ln -s /usr/lib/libffi.la /usr/lib64/
ln -s /usr/lib/libffi.so /usr/lib64/

View File

@ -1,2 +0,0 @@
cp /lib/ncurses/terminfo/x/xterm /usr/share/terminfo/x/
echo "export TERM='xterm' " >> /root/.bashrc

View File

@ -1,14 +0,0 @@
#ustversion=1.6.2
ustversion=$1
cd /tmp
if [ ! -f go${ustversion}.src.tar.gz ];then
wget https://storage.googleapis.com/golang/go${ustversion}.src.tar.gz
fi
tar xf /sources/go${ustversion}.src.tar.gz -C .
ln -s /opt/go /$HOME/go1.4
cd go/src/
CGO_ENABLED=0; GOROOT_BOOTSTRAP=/opt/go
./make.bash
go version
rm /$HOME/go1.4
cd -

611
bin/ps_mem.py Executable file
View File

@ -0,0 +1,611 @@
#!/usr/bin/env python
# Try to determine how much RAM is currently being used per program.
# Note per _program_, not per process. So for example this script
# will report RAM used by all httpd process together. In detail it reports:
# sum(private RAM for program processes) + sum(Shared RAM for program processes)
# The shared RAM is problematic to calculate, and this script automatically
# selects the most accurate method available for your kernel.
# Licence: LGPLv2
# Author: P@draigBrady.com
# Source: http://www.pixelbeat.org/scripts/ps_mem.py
# V1.0 06 Jul 2005 Initial release
# V1.1 11 Aug 2006 root permission required for accuracy
# V1.2 08 Nov 2006 Add total to output
# Use KiB,MiB,... for units rather than K,M,...
# V1.3 22 Nov 2006 Ignore shared col from /proc/$pid/statm for
# 2.6 kernels up to and including 2.6.9.
# There it represented the total file backed extent
# V1.4 23 Nov 2006 Remove total from output as it's meaningless
# (the shared values overlap with other programs).
# Display the shared column. This extra info is
# useful, especially as it overlaps between programs.
# V1.5 26 Mar 2007 Remove redundant recursion from human()
# V1.6 05 Jun 2007 Also report number of processes with a given name.
# Patch from riccardo.murri@gmail.com
# V1.7 20 Sep 2007 Use PSS from /proc/$pid/smaps if available, which
# fixes some over-estimation and allows totalling.
# Enumerate the PIDs directly rather than using ps,
# which fixes the possible race between reading
# RSS with ps, and shared memory with this program.
# Also we can show non truncated command names.
# V1.8 28 Sep 2007 More accurate matching for stats in /proc/$pid/smaps
# as otherwise could match libraries causing a crash.
# Patch from patrice.bouchand.fedora@gmail.com
# V1.9 20 Feb 2008 Fix invalid values reported when PSS is available.
# Reported by Andrey Borzenkov <arvidjaar@mail.ru>
# V3.9 07 Mar 2017
# http://github.com/pixelb/scripts/commits/master/scripts/ps_mem.py
# Notes:
#
# All interpreted programs where the interpreter is started
# by the shell or with env, will be merged to the interpreter
# (as that's what's given to exec). For e.g. all python programs
# starting with "#!/usr/bin/env python" will be grouped under python.
# You can change this by using the full command line but that will
# have the undesirable affect of splitting up programs started with
# differing parameters (for e.g. mingetty tty[1-6]).
#
# For 2.6 kernels up to and including 2.6.13 and later 2.4 redhat kernels
# (rmap vm without smaps) it can not be accurately determined how many pages
# are shared between processes in general or within a program in our case:
# http://lkml.org/lkml/2005/7/6/250
# A warning is printed if overestimation is possible.
# In addition for 2.6 kernels up to 2.6.9 inclusive, the shared
# value in /proc/$pid/statm is the total file-backed extent of a process.
# We ignore that, introducing more overestimation, again printing a warning.
# Since kernel 2.6.23-rc8-mm1 PSS is available in smaps, which allows
# us to calculate a more accurate value for the total RAM used by programs.
#
# Programs that use CLONE_VM without CLONE_THREAD are discounted by assuming
# they're the only programs that have the same /proc/$PID/smaps file for
# each instance. This will fail if there are multiple real instances of a
# program that then use CLONE_VM without CLONE_THREAD, or if a clone changes
# its memory map while we're checksumming each /proc/$PID/smaps.
#
# I don't take account of memory allocated for a program
# by other programs. For e.g. memory used in the X server for
# a program could be determined, but is not.
#
# FreeBSD is supported if linprocfs is mounted at /compat/linux/proc/
# FreeBSD 8.0 supports up to a level of Linux 2.6.16
import getopt
import time
import errno
import os
import sys
# The following exits cleanly on Ctrl-C or EPIPE
# while treating other exceptions as before.
def std_exceptions(etype, value, tb):
sys.excepthook = sys.__excepthook__
if issubclass(etype, KeyboardInterrupt):
pass
elif issubclass(etype, IOError) and value.errno == errno.EPIPE:
pass
else:
sys.__excepthook__(etype, value, tb)
sys.excepthook = std_exceptions
#
# Define some global variables
#
PAGESIZE = os.sysconf("SC_PAGE_SIZE") / 1024 #KiB
our_pid = os.getpid()
have_pss = 0
have_swap_pss = 0
class Proc:
def __init__(self):
uname = os.uname()
if uname[0] == "FreeBSD":
self.proc = '/compat/linux/proc'
else:
self.proc = '/proc'
def path(self, *args):
return os.path.join(self.proc, *(str(a) for a in args))
def open(self, *args):
try:
if sys.version_info < (3,):
return open(self.path(*args))
else:
return open(self.path(*args), errors='ignore')
except (IOError, OSError):
val = sys.exc_info()[1]
if (val.errno == errno.ENOENT or # kernel thread or process gone
val.errno == errno.EPERM or
val.errno == errno.EACCES):
raise LookupError
raise
proc = Proc()
#
# Functions
#
def parse_options():
try:
long_options = [
'split-args',
'help',
'total',
'discriminate-by-pid',
'swap'
]
opts, args = getopt.getopt(sys.argv[1:], "shtdSp:w:", long_options)
except getopt.GetoptError:
sys.stderr.write(help())
sys.exit(3)
if len(args):
sys.stderr.write("Extraneous arguments: %s\n" % args)
sys.exit(3)
# ps_mem.py options
split_args = False
pids_to_show = None
discriminate_by_pid = False
show_swap = False
watch = None
only_total = False
for o, a in opts:
if o in ('-s', '--split-args'):
split_args = True
if o in ('-t', '--total'):
only_total = True
if o in ('-d', '--discriminate-by-pid'):
discriminate_by_pid = True
if o in ('-S', '--swap'):
show_swap = True
if o in ('-h', '--help'):
sys.stdout.write(help())
sys.exit(0)
if o in ('-p',):
try:
pids_to_show = [int(x) for x in a.split(',')]
except:
sys.stderr.write(help())
sys.exit(3)
if o in ('-w',):
try:
watch = int(a)
except:
sys.stderr.write(help())
sys.exit(3)
return (
split_args,
pids_to_show,
watch,
only_total,
discriminate_by_pid,
show_swap
)
def help():
help_msg = 'Usage: ps_mem [OPTION]...\n' \
'Show program core memory usage\n' \
'\n' \
' -h, -help Show this help\n' \
' -p <pid>[,pid2,...pidN] Only show memory usage PIDs in the '\
'specified list\n' \
' -s, --split-args Show and separate by, all command line'\
' arguments\n' \
' -t, --total Show only the total value\n' \
' -d, --discriminate-by-pid Show by process rather than by program\n' \
' -S, --swap Show swap information\n' \
' -w <N> Measure and show process memory every'\
' N seconds\n'
return help_msg
# (major,minor,release)
def kernel_ver():
kv = proc.open('sys/kernel/osrelease').readline().split(".")[:3]
last = len(kv)
if last == 2:
kv.append('0')
last -= 1
while last > 0:
for char in "-_":
kv[last] = kv[last].split(char)[0]
try:
int(kv[last])
except:
kv[last] = 0
last -= 1
return (int(kv[0]), int(kv[1]), int(kv[2]))
#return Private,Shared
#Note shared is always a subset of rss (trs is not always)
def getMemStats(pid):
global have_pss
global have_swap_pss
mem_id = pid #unique
Private_lines = []
Shared_lines = []
Pss_lines = []
Rss = (int(proc.open(pid, 'statm').readline().split()[1])
* PAGESIZE)
Swap_lines = []
Swap_pss_lines = []
Swap = 0
Swap_pss = 0
if os.path.exists(proc.path(pid, 'smaps')): # stat
lines = proc.open(pid, 'smaps').readlines() # open
# Note we checksum smaps as maps is usually but
# not always different for separate processes.
mem_id = hash(''.join(lines))
for line in lines:
if line.startswith("Shared"):
Shared_lines.append(line)
elif line.startswith("Private"):
Private_lines.append(line)
elif line.startswith("Pss"):
have_pss = 1
Pss_lines.append(line)
elif line.startswith("Swap:"):
Swap_lines.append(line)
elif line.startswith("SwapPss:"):
have_swap_pss = 1
Swap_pss_lines.append(line)
Shared = sum([int(line.split()[1]) for line in Shared_lines])
Private = sum([int(line.split()[1]) for line in Private_lines])
#Note Shared + Private = Rss above
#The Rss in smaps includes video card mem etc.
if have_pss:
pss_adjust = 0.5 # add 0.5KiB as this avg error due to truncation
Pss = sum([float(line.split()[1])+pss_adjust for line in Pss_lines])
Shared = Pss - Private
# Note that Swap = Private swap + Shared swap.
Swap = sum([int(line.split()[1]) for line in Swap_lines])
if have_swap_pss:
# The kernel supports SwapPss, that shows proportional swap share.
# Note that Swap - SwapPss is not Private Swap.
Swap_pss = sum([int(line.split()[1]) for line in Swap_pss_lines])
elif (2,6,1) <= kernel_ver() <= (2,6,9):
Shared = 0 #lots of overestimation, but what can we do?
Private = Rss
else:
Shared = int(proc.open(pid, 'statm').readline().split()[2])
Shared *= PAGESIZE
Private = Rss - Shared
return (Private, Shared, mem_id, Swap, Swap_pss)
def getCmdName(pid, split_args, discriminate_by_pid):
cmdline = proc.open(pid, 'cmdline').read().split("\0")
if cmdline[-1] == '' and len(cmdline) > 1:
cmdline = cmdline[:-1]
path = proc.path(pid, 'exe')
try:
path = os.readlink(path)
# Some symlink targets were seen to contain NULs on RHEL 5 at least
# https://github.com/pixelb/scripts/pull/10, so take string up to NUL
path = path.split('\0')[0]
except OSError:
val = sys.exc_info()[1]
if (val.errno == errno.ENOENT or # either kernel thread or process gone
val.errno == errno.EPERM or
val.errno == errno.EACCES):
raise LookupError
raise
if split_args:
return ' '.join(cmdline).replace('\n', ' ')
if path.endswith(" (deleted)"):
path = path[:-10]
if os.path.exists(path):
path += " [updated]"
else:
#The path could be have prelink stuff so try cmdline
#which might have the full path present. This helped for:
#/usr/libexec/notification-area-applet.#prelink#.fX7LCT (deleted)
if os.path.exists(cmdline[0]):
path = cmdline[0] + " [updated]"
else:
path += " [deleted]"
exe = os.path.basename(path)
cmd = proc.open(pid, 'status').readline()[6:-1]
if exe.startswith(cmd):
cmd = exe #show non truncated version
#Note because we show the non truncated name
#one can have separated programs as follows:
#584.0 KiB + 1.0 MiB = 1.6 MiB mozilla-thunder (exe -> bash)
# 56.0 MiB + 22.2 MiB = 78.2 MiB mozilla-thunderbird-bin
if sys.version_info >= (3,):
cmd = cmd.encode(errors='replace').decode()
if discriminate_by_pid:
cmd = '%s [%d]' % (cmd, pid)
return cmd
#The following matches "du -h" output
#see also human.py
def human(num, power="Ki", units=None):
if units is None:
powers = ["Ki", "Mi", "Gi", "Ti"]
while num >= 1000: #4 digits
num /= 1024.0
power = powers[powers.index(power)+1]
return "%.1f %sB" % (num, power)
else:
return "%.f" % ((num * 1024) / units)
def cmd_with_count(cmd, count):
if count > 1:
return "%s (%u)" % (cmd, count)
else:
return cmd
#Warn of possible inaccuracies
#2 = accurate & can total
#1 = accurate only considering each process in isolation
#0 = some shared mem not reported
#-1= all shared mem not reported
def shared_val_accuracy():
"""http://wiki.apache.org/spamassassin/TopSharedMemoryBug"""
kv = kernel_ver()
pid = os.getpid()
if kv[:2] == (2,4):
if proc.open('meminfo').read().find("Inact_") == -1:
return 1
return 0
elif kv[:2] == (2,6):
if os.path.exists(proc.path(pid, 'smaps')):
if proc.open(pid, 'smaps').read().find("Pss:")!=-1:
return 2
else:
return 1
if (2,6,1) <= kv <= (2,6,9):
return -1
return 0
elif kv[0] > 2 and os.path.exists(proc.path(pid, 'smaps')):
return 2
else:
return 1
def show_shared_val_accuracy( possible_inacc, only_total=False ):
level = ("Warning","Error")[only_total]
if possible_inacc == -1:
sys.stderr.write(
"%s: Shared memory is not reported by this system.\n" % level
)
sys.stderr.write(
"Values reported will be too large, and totals are not reported\n"
)
elif possible_inacc == 0:
sys.stderr.write(
"%s: Shared memory is not reported accurately by this system.\n" % level
)
sys.stderr.write(
"Values reported could be too large, and totals are not reported\n"
)
elif possible_inacc == 1:
sys.stderr.write(
"%s: Shared memory is slightly over-estimated by this system\n"
"for each program, so totals are not reported.\n" % level
)
sys.stderr.close()
if only_total and possible_inacc != 2:
sys.exit(1)
def get_memory_usage(pids_to_show, split_args, discriminate_by_pid,
include_self=False, only_self=False):
cmds = {}
shareds = {}
mem_ids = {}
count = {}
swaps = {}
shared_swaps = {}
for pid in os.listdir(proc.path('')):
if not pid.isdigit():
continue
pid = int(pid)
# Some filters
if only_self and pid != our_pid:
continue
if pid == our_pid and not include_self:
continue
if pids_to_show is not None and pid not in pids_to_show:
continue
try:
cmd = getCmdName(pid, split_args, discriminate_by_pid)
except LookupError:
#operation not permitted
#kernel threads don't have exe links or
#process gone
continue
try:
private, shared, mem_id, swap, swap_pss = getMemStats(pid)
except RuntimeError:
continue #process gone
if shareds.get(cmd):
if have_pss: #add shared portion of PSS together
shareds[cmd] += shared
elif shareds[cmd] < shared: #just take largest shared val
shareds[cmd] = shared
else:
shareds[cmd] = shared
cmds[cmd] = cmds.setdefault(cmd, 0) + private
if cmd in count:
count[cmd] += 1
else:
count[cmd] = 1
mem_ids.setdefault(cmd, {}).update({mem_id: None})
# Swap (overcounting for now...)
swaps[cmd] = swaps.setdefault(cmd, 0) + swap
if have_swap_pss:
shared_swaps[cmd] = shared_swaps.setdefault(cmd, 0) + swap_pss
else:
shared_swaps[cmd] = 0
# Total swaped mem for each program
total_swap = 0
# Total swaped shared mem for each program
total_shared_swap = 0
# Add shared mem for each program
total = 0
for cmd in cmds:
cmd_count = count[cmd]
if len(mem_ids[cmd]) == 1 and cmd_count > 1:
# Assume this program is using CLONE_VM without CLONE_THREAD
# so only account for one of the processes
cmds[cmd] /= cmd_count
if have_pss:
shareds[cmd] /= cmd_count
cmds[cmd] = cmds[cmd] + shareds[cmd]
total += cmds[cmd] # valid if PSS available
total_swap += swaps[cmd]
if have_swap_pss:
total_shared_swap += shared_swaps[cmd]
sorted_cmds = sorted(cmds.items(), key=lambda x:x[1])
sorted_cmds = [x for x in sorted_cmds if x[1]]
return sorted_cmds, shareds, count, total, swaps, shared_swaps, \
total_swap, total_shared_swap
def print_header(show_swap, discriminate_by_pid):
output_string = " Private + Shared = RAM used"
if show_swap:
if have_swap_pss:
output_string += " " * 5 + "Shared Swap"
output_string += " Swap used"
output_string += "\tProgram"
if discriminate_by_pid:
output_string += "[pid]"
output_string += "\n\n"
sys.stdout.write(output_string)
def print_memory_usage(sorted_cmds, shareds, count, total, swaps, total_swap,
shared_swaps, total_shared_swap, show_swap):
for cmd in sorted_cmds:
output_string = "%9s + %9s = %9s"
output_data = (human(cmd[1]-shareds[cmd[0]]),
human(shareds[cmd[0]]), human(cmd[1]))
if show_swap:
if have_swap_pss:
output_string += "\t%9s"
output_data += (human(shared_swaps[cmd[0]]),)
output_string += " %9s"
output_data += (human(swaps[cmd[0]]),)
output_string += "\t%s\n"
output_data += (cmd_with_count(cmd[0], count[cmd[0]]),)
sys.stdout.write(output_string % output_data)
if have_pss:
if show_swap:
if have_swap_pss:
sys.stdout.write("%s\n%s%9s%s%9s%s%9s\n%s\n" %
("-" * 61, " " * 24, human(total), " " * 7,
human(total_shared_swap), " " * 3,
human(total_swap), "=" * 61))
else:
sys.stdout.write("%s\n%s%9s%s%9s\n%s\n" %
("-" * 45, " " * 24, human(total), " " * 3,
human(total_swap), "=" * 45))
else:
sys.stdout.write("%s\n%s%9s\n%s\n" %
("-" * 33, " " * 24, human(total), "=" * 33))
def verify_environment(pids_to_show):
if os.geteuid() != 0 and not pids_to_show:
sys.stderr.write("Sorry, root permission required, or specify pids with -p\n")
sys.stderr.close()
sys.exit(1)
try:
kernel_ver()
except (IOError, OSError):
val = sys.exc_info()[1]
if val.errno == errno.ENOENT:
sys.stderr.write(
"Couldn't access " + proc.path('') + "\n"
"Only GNU/Linux and FreeBSD (with linprocfs) are supported\n")
sys.exit(2)
else:
raise
def main():
split_args, pids_to_show, watch, only_total, discriminate_by_pid, \
show_swap = parse_options()
verify_environment(pids_to_show)
if not only_total:
print_header(show_swap, discriminate_by_pid)
if watch is not None:
try:
sorted_cmds = True
while sorted_cmds:
sorted_cmds, shareds, count, total, swaps, shared_swaps, \
total_swap, total_shared_swap = \
get_memory_usage(pids_to_show, split_args,
discriminate_by_pid)
if only_total and have_pss:
sys.stdout.write(human(total, units=1)+'\n')
elif not only_total:
print_memory_usage(sorted_cmds, shareds, count, total,
swaps, total_swap, shared_swaps,
total_shared_swap, show_swap)
sys.stdout.flush()
time.sleep(watch)
else:
sys.stdout.write('Process does not exist anymore.\n')
except KeyboardInterrupt:
pass
else:
# This is the default behavior
sorted_cmds, shareds, count, total, swaps, shared_swaps, total_swap, \
total_shared_swap = get_memory_usage(pids_to_show, split_args,
discriminate_by_pid)
if only_total and have_pss:
sys.stdout.write(human(total, units=1)+'\n')
elif not only_total:
print_memory_usage(sorted_cmds, shareds, count, total, swaps,
total_swap, shared_swaps, total_shared_swap,
show_swap)
# We must close explicitly, so that any EPIPE exception
# is handled by our excepthook, rather than the default
# one which is reenabled after this script finishes.
sys.stdout.close()
vm_accuracy = shared_val_accuracy()
show_shared_val_accuracy( vm_accuracy, only_total )
if __name__ == '__main__': main()