1753947 Members
7190 Online
108811 Solutions
New Discussion юеВ

Re: Process memory usage

 
jpcast_real
Regular Advisor

Process memory usage

I have look at the ps and fuser options to know if it is possible to know the amount of memory a process is using , but I havn't found anything. I need the same information of a process I get with the TOP command but with a tool which lend me integrate it into a script..

Thanks
Here rests one who was not what he wanted and didn't want what he was
7 REPLIES 7
Nicolas Dumeige
Esteemed Contributor

Re: Process memory usage

Hello,

Look at the ps -o option.
Consider also glance.

Cheees
All different, all Unix
jpcast_real
Regular Advisor

Re: Process memory usage

the option:

ps -o does not work in my hp-ux 11i...
Here rests one who was not what he wanted and didn't want what he was
Geoff Wild
Honored Contributor

Re: Process memory usage

Try this script:

# cat usermem


#!/bin/ksh
# usermem - display memory claimed by a user
# gwild 06232003
#
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "usermem \"userid\""
echo "Example:"
echo "usermem gwild"
exit 1
fi
echo " "

USER=$1
t=0
for j in `UNIX95= ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line | sort -rnk1 | grep -v Kbytes | grep $USER | awk '{print $1}'`
do
t=`expr $t + $j`
done
echo "\nMemory claimed by $USER: $t Kbytes.\n"



Or this one:

# cat processmem
#!/bin/sh
# processmem - display memory claimed by a process
# gwild 03192004
#
if [ $# -lt 1 -o \( $# -gt 1 -a $# -lt 4 \) ]
then
echo "Usage:"
echo "processmem \"process\""
echo "Example:"
echo "processmem rpc"
exit 1
fi
echo " "

PROCESS=$1

mps=0
#for sz in `ps -elf | grep $PROCESS | grep -v grep | awk '{print $10}'`
for sz in `UNIX95= ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line | sort -rnk1 | grep -v Kbytes | grep $PROCESS | awk '{print $1}'`
do
mps=`expr $mps + $sz`
done
#echo `expr $mps \* 4096`
echo "\nMemory claimed by $PROCESS: $mps Kbytes.\n"



Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
RAC_1
Honored Contributor

Re: Process memory usage

UNIX95= ps -C "Your_process" -o "vsz,args,ruser,pid"

Will give you memory size in KB. Also you can check text mem size of your process with
ps -efl|grep your_process. The SZ colums is size in pages. Check man page of ps.

Also you can get that with glance.

Anil
There is no substitute to HARDWORK
jpcast_real
Regular Advisor

Re: Process memory usage

This is what I get when I execute the option -o :

Dartanan:/etc> ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line
ps: illegal option -- o
usage: ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup]
[-Z psetidlist]
Dartanan:/etc> ps -e -o vsz=Kbytes -o ruser -o pid,args=Command-Line
ps: illegal option -- o
usage: ps [-edaxzflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup]
[-Z psetidlist]
Here rests one who was not what he wanted and didn't want what he was
Geoff Wild
Honored Contributor

Re: Process memory usage

Ok - do a

which ps

Should be:
/usr/bin/ps

Now do a

what /usr/bin/ps

Should be something like:
/usr/bin/ps:
$Revision: B.11.11_LR
Wed Nov 8 18:28:10 PST 2000 $

Rgds...Geoff

Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
jpcast_real
Regular Advisor

Re: Process memory usage

Ok ,

It was the UNIX95 environment , Thanks a lot
Here rests one who was not what he wanted and didn't want what he was