This post was originally published on go2linux.org, a Linux blog I ran from 2007 to 2011. The domain is no longer mine, but I am the original author. I am republishing it here on garron.me with corrections and improvements.

Introduction

How to know how many processes each user is running?, there are lots of ways to do this, I've found this some time ago in the ubuntu forums I think.

I can not find right now a real scenario when you may need this, but it is a good example about how to use pipes to get a different output, with a whole different purpose.

Have fun:

How to count how many processes each user is running in Linux

ps hax -o user | sort | uniq -c

ps will list the processes, h will remove the header, -o user prints only the user column, sort sorts in alphabetical order, so uniq can count each occurrence and show the number of occurrences instead of all the occurrences themselves.