General

Let’s Count The Running Processes In Linux

This article will show you how to count the running processes on your Linux system. Like many articles, it will show you how to use some tools that you may not yet know about.

The tools in question will be ‘ps‘ and ‘wc‘. The ‘ps’ command reports the current processes and the ‘wc’ stands for word count and has uses beyond just counting individual words, as this article will show you.

If you’re curious, the man page describes them as:

ps – report a snapshot of the current processes.

And:

wc – print newline, word, and byte counts for each file

We will be using both of these tools, not just to just count the running processes, but also to expose you to these tools. After all, it’s really not all that important to count the running processes. I suppose if you have resource constraints, but it’s not so important the number of running processes – but how computationally expensive those processes are.

So, this should actually be a pretty short article and it’s definitely in the beginner territory. If you’re an advanced user, it’s likely that you’ll have at least some familiarity with these tools. Even if you’re an expert, have some fun and read on!

Count The Running Processes:

Like many other articles on this site, we start with an open terminal. You can open your terminal with your keyboard – just press CTRL + ALT + T and your default terminal should open.

With the terminal now open, we’ll start with the ‘ps’ command. Running just ‘ps’ is pretty useless, so be sure to check man ps for more information. Instead, we’ll run it with the -e flag to show every running process.

ps -e

Tada! That shows you every running process. Now, let’s see the same command with the -U flag. You can’t just use the -U flag by itself, it requires a username. So, try this to show all the processes being run by a specific user:

ps -U <user>

Where you see <user>, put your username. In my case, the command would look like ps -U kgiii – and don’t forget that it is case sensitive and lowercase letters are all you can use in your username. Anyhow, that command will show the running processes owned by the user ‘kgiii’.

So, all that is well and good. How about we now count them? To do that, you just need to add a pipe and wc -l. We’ve used a pipe before, and the pipe is one of the greatest concepts in Linux – as it allows you to take the output from one command and pipe it into a new command.

Using the information above, we would then try:

ps -e | wc -l

And to count the processes from a specific user, you’d just use:

ps -U <user> | wc -l

An example output of the latter would look something like this:

Counting the processes owned by user ‘kgiii’. A nice even 200, strangely enough.

That’s about it, really. You can check the man pages for both ‘ps’ and ‘wc’ to learn more about them, but this would be how I’d count the running processes on my Linux boxes. 

Closure:

There you have it, another article – this one telling how to count the running processes. Hopefully, we all learned a little something today and hopefully we’ll all learn a little something new in two days – which is when the next article should come out.

We’re approaching the halfway point in this year-long project. It has been good fun and I’ve learned a great deal. If I had to speculate, I would guess that this project will keep going beyond the one year mark, though maybe with a more lenient publishing schedule!

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Short: The Halt Command

Today's article is intentionally short because we're simply going to learn about the basics of…

7 hours ago

Installing Flatpaks In Linux

Today we're going to have a pretty easy article where you'll learn about installing Flatpaks…

2 days ago

A Quick Look At The Shutdown Command

This is going to be just a quick article about a command many of you…

4 days ago

Setting Up Coding Environments on Linux for Educational Use

With so many strong attributes, such as robustness and flexibility, Linux stands as a powerful…

6 days ago

View Detailed Hardware Information

There are many tools for showing your hardware information and today we'll get to view…

1 week ago

How To: Install Wine In Lubuntu

Today's article isn't going to be complicated or long as we are going to cover…

1 week ago