LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Find process information by name. (https://www.linuxquestions.org/questions/linux-software-2/find-process-information-by-name-808236/)

archShade 05-16-2010 10:56 PM

Find process information by name.
 
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 :)

kbp 05-17-2010 12:17 AM

<plug> I wrote a little script a while back - http://killboy.yourdevlab.com/scripts/processinfo.pl

You could do:

Code:

pgrep <name> | processinfo.pl
hth


All times are GMT -5. The time now is 12:33 AM.