1

I want to write the process id and command of all processes with some name and from some user (for example root and init).

What should I do?

ps -f -u root -C init 

or

ps -f -U root -C init

writes more then just init the process.

2

If you only want the process ids, why not use pgrep:

pgrep -u root init

Or:

pgrep -U root init

Which switch you use (-u/-U) depends on what you want. The difference is, -u matches the effective uid and -U the real uid:

  • The effective uid describes the user whose file access permissions are used by the process.
  • The real uid is from the user who created the process.

Edit: to list the name too, add -l

$ pgrep -l -u root init
1 init
  • I want command too, can you do that with pgrep? – TGar May 1 '15 at 10:50
  • @TedGar yes add -l to the parameters – chaos May 1 '15 at 11:59

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.