1

I can track the process launched by the user4 with awk:

ps aux | awk '$1~/user4/'

And also to track what process consume more than 10% CPU:

ps aux | awk '$3> 10'

How can I combine both with awk, aka search for process launched by user4 which are consumming more than 10% CPU?

1

Ok ... I found it reading more awk documentation, sorry for disturbing:

ps aux | awk '$1~/user4/ && $3> 0'
  • 1
    since ~ is pattern-matching, be careful if you ever end up with a "user44" or "ruser4" – Jeff Schaller Mar 22 '16 at 11:01
  • this is completely true! I went for '$1~/user4$/ && $3> 0' to avoid this – Colonel Beauvel Mar 22 '16 at 11:22
  • 1
    Consider == as well – Jeff Schaller Mar 22 '16 at 11:31
1

or as an alternative

ps -u user4 -o pcpu,args | awk '$1>0' 

see man ps for arguement of -o , some argument might be cputime,etime,args,comm,tty

  • hum despite I like the idea, the totla command returns nothing on my side, but when I only do ps -u user4 I have the PID, TTY, TIME and CMD. – Colonel Beauvel Mar 22 '16 at 11:25
  • try adding XPG4= or UNIX95= before ps – Archemar Mar 22 '16 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.