#!/bin/sh1PAGESIZE=`getconf PAGESIZE`;2TOTAL_MEMORY=`cat /proc/meminfo | head -n 1 | awk '{print $2}'`;34# Mimic the output of ps -ax -o pid=,ppid=,pcpu=,pmem=,command=5# Read all numeric subdirectories in /proc6for pid in `cd /proc && ls -d [0-9]*`7do {8if [ -e /proc/$pid/stat ]9then10echo $pid;1112# ppid is the word at index 4 in the stat file for the process13awk '{print $4}' /proc/$pid/stat;1415# pcpu - calculation will be done later, this is a placeholder value16echo "0.0"1718# pmem - ratio of the process's working set size to total memory.19# use the page size to convert to bytes, total memory is in KB20# multiplied by 100 to get percentage, extra 10 to be able to move21# the decimal over by one place22RESIDENT_SET_SIZE=`awk '{print $24}' /proc/$pid/stat`;23PERCENT_MEMORY=$(((1000 * $PAGESIZE * $RESIDENT_SET_SIZE) / ($TOTAL_MEMORY * 1024)));24if [ $PERCENT_MEMORY -lt 10 ]25then26# replace the last character with 0. the last character27echo $PERCENT_MEMORY | sed 's/.$/0.&/'; #pmem28else29# insert . before the last character30echo $PERCENT_MEMORY | sed 's/.$/.&/';31fi3233# cmdline34xargs -0 < /proc/$pid/cmdline;35fi36} | tr "\n" "\t"; # Replace newlines with tab so that all info for a process is shown on one line37echo; # But add new lines between processes38done394041