Issue
I am trying to get the process id in PID and then get the cpu and memory usage with all the process id that the grep command has listed but I am facing an error. Any help would be appreciated
#!/bin/bash
PID=`ps -eaf | grep firefox | grep -v grep | awk '{print $2}'`
usage= `ps -p $PID -o %cpu,%mem`
error:
error: process ID list syntax error
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
Solution
To do one at a time
#!/bin/bash
for PID in `ps -eaf | grep firefox | grep -v grep | awk '{print $2}'` ; do
usage=`ps -p $PID -o %cpu,%mem`
done
Answered By - stark Answer Checked By - Cary Denson (WPSolving Admin)