LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-16-2010, 10:56 PM   #1
archShade
Member
 
Registered: Mar 2006
Location: Delft NL
Distribution: Debian; Slackware; windows 7
Posts: 218

Rep: Reputation: 53
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

Last edited by archShade; 05-16-2010 at 10:58 PM.
 
Old 05-17-2010, 12:17 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
<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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find out indone information and datablocks information in a file system chaitanya1982 Linux - Newbie 1 09-24-2008 01:58 AM
How to get the current process information balasquare@yahoo.com Programming 4 09-29-2005 04:39 AM
How to use task_struct to get process information?? Pratik H Pandya Programming 2 09-15-2005 03:40 AM
get information when a process run?????? hungnt Linux - Newbie 6 07-16-2005 10:57 AM
process information application? YBA^[x] Slackware 6 01-13-2005 10:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration