Is there a way to find out information about a process based on the command used to run it?
Ideally I would like to get processes ID %CPU and memory usage back.
I have written a short shell script which does this but I wonderd was there a command that did this.
Here's my shell script
Code:
#!/bin/bash
ExpectedArgs=1
ARGS=$#
if [ $ARGS != $ExpectedArgs ]
then
echo "Incorrect number of arguments"
echo "Usage: PSscript <process name>"
else
ps -eo pid,comm,pcpu,pmem,rsz,vsz | awk -v proc=$1 \
'NR == 1 {print} \
{if ($2 == proc) {print}} \
'
fi
I would also like any feedback if possible on ways to make my code better (better input validation or better code layout etc.)
Thanks in advance