0

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

Ipor Sircer
  • 3,069
  • 3
  • 10
  • 15
James
  • 85
  • 8

1 Answers1

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