Avatar of MichaelBalack
MichaelBalack
Flag for Singapore asked on

How to create a bash script with the given full command of pmap?

This is using SuSE 11 with SP4. Recently, I came across an online article discussed about how to use pmap to display the actual mapping, memory in active/cached and so on.
Please see the full command below,

 for i in `ps -eaf | grep “any application process” | grep -v grep | awk '{print $2}'`; do echo -n "PID $i actual memory usage is :" >> totaluse.txt; pmap -d $i | grep -i "writeable/private: " >> totaluse.txt; done

I was ended up with "nothing" when copy and paste the whole command to the terminal. Can I create a bash script? if so, please enlighten how, thanks.
LinuxShell Scripting

Avatar of undefined
Last Comment
skullnobrains

8/22/2022 - Mon
David Favor

Most likely you're finding no PIDs or the PIDs have already died at time pmap is called.

Try this command, which will work on any running machine.

pmap -d 1

Open in new window


Now break your script into sections + print debug info...

So... get your PID list + print out all the PIDs + command/args.

Then cycle through your PID list printing every pmap command before running the command.

Basic, incremental debugging, will provide enough data to fix your code.

Tip: Also print out information messages, like PID count + a warning each time pmap runs on a PID + returns no result. Be sure to add additional code to test if PID is still alive, when you get no return data from pmap.
skullnobrains

did you replace "any application process" with the name of a runniing process ?
ASKER CERTIFIED SOLUTION
skullnobrains

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
David Favor

Better to just pick a solution and allow this question/comments to persist, as this may help someone down the road.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
MichaelBalack

ASKER
Thanks for both experts. Your suggestions are helpful.
skullnobrains

I'd rather be actually helpful. If you want, i have a script that can gather the real memory usage of each process systemwide based on pmap output.