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

0

1 Answer 1

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'
Sign up to request clarification or add additional context in comments.

1 Comment

You can skip wc -l with grep -c [t]est.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.