2

I am looking for a command or a script to get the processes currently run by users in the system. I tried the ps -Af command, however, all the processes including the root processes pop up. Is there any command to get the processes run only by user? Otherwise I need some help in writing a script to take out the root processes from the ps -Af command.

migrated from stackoverflow.com Nov 15 '13 at 7:02

This question came from our site for professional and enthusiast programmers.

  • pipe the results through grep. – Preet Sangha Nov 14 '13 at 23:33
  • @Preet: For that to be useful, you'd need to show a way to check just the username and not match filenames and commander-line arguments. – Ben Voigt Nov 14 '13 at 23:41
  • Question belongs on Super User or Unix & Linux – Stephen P Nov 15 '13 at 2:06
0

If you want to remove root, just do your ps -Af and pipe it though grep:

ps -Af | grep -v root

Of course, this is sloppy. If you're running a program called troot, you'll lose that as well. You can be more precise using awk and removing any line that has root in the right column. I don't have the output from ps -Af in front of me, but for the sake of argument, let's assume the userid is in the 3rd column. In that case, you'd want to do this:

ps -Af | awk '$3 != "root" { print $0 }'
  • 1
    On my system the user is in the first column, so a simple ps -Af | grep -v '^root' would do. – pfnuesel Nov 15 '13 at 0:06
3

This will give you every process NOT owned by root:

ps -N -u root 
1

ps --deselect -U root. The --deselect inverts the logic of -U root.

0

how about ps -U <username> (works on MacOSX) or pipe through grep

ps -Af | grep -v 'root' should show all processes not owned by root. But beware, grep will not be limited to the username. A process exposing some path containing "root" will also be removed from the result.

0

You shoud try whowatch

It gives you a nice overview of which users are logged in, which processed they currently run and so on

-1

ps -Af | grep -v root is not perfect. try ps -Af | awk '$1 != "root" {print $0}'

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.