I know use ps -ef | grep test| grep -v grep |wc -l can list the num of process test,and now i plan to list the test processes belong to user :forme.is this right as below :
ps -ef | grep test|grep -x forme| grep -v grep |wc -l
Asked
Active
Viewed 43 times
0
Ipor Sircer
- 3,069
- 3
- 10
- 15
James
- 85
- 8
1 Answers
3
For a start, grep test| grep -v grep can be replaced with grep '[t]est'. See here for an explanation.
Secondly, if you want to limit the processes to a single user, that's what the -u option to ps is for:
ps -fu forme | grep '[t]est' | wc -l
And, finally, grep already has a -c option to count lines, so you can ditch the wc part of the pipeline:
ps -fu forme | grep -c '[t]est'
paxdiablo
- 854,327
- 234
- 1,573
- 1,953
-
2You can skip `wc -l` with `grep -c [t]est`. – Ipor Sircer Sep 27 '18 at 02:59