Process ID of a program in Ubuntu

We need to first understand – what the Process ID (or PID) is? Thereafter, we would cover how to find the Process ID of a program in Ubuntu.

When we open a program/application we create an instance for it. And, if we open multiple windows of the same program, we create multiple instances of it. Similarly, if that program is opened by multiple users even in that case, multiple instances are created.

And, if you delve deeper, these instances are nothing but processes. In other words, we can say a Process is an instance of a program. Furthermore, each Process has got a Process ID or PID. The Process ID is used to identify the associated process.

It is a unique ID which will be associated to a particular process till the time we exit the program. Once we exit the program, the system frees the Process ID and it can now be allocated to some other program.

We discuss how to find the Process ID of a program next.

Process ID of a program in Ubuntu

I. Identifying the Process ID of a particular program is pretty straight-forward. Just use pidof command-line utility. It displays the results as standard output. So, to check for a particular program –

pidof <process_name>

For instance, to know the PID of atril (Document Viewer) –

pidof atril

It would return with the Process ID.

Now, close the program for which you have checked the Process ID just now. And, again open the same program. Now, use pidof command again. You will see that Process ID of that program has now changed.

II. Alternatively, we can also know the PID through the following command –

ps aux

It will show you the list of all running processes. To filter these, use pipe ( | ) and grep

ps aux | grep -i <program_name>

For instance,

ps aux | grep -i atril

More about ps aux here.

Although, at this stage this may seem trivial. But, if we know the PID of a program – then we can basically control the amount of resources it uses. Furthermore, we can even close the program, if it gets stuck. We will cover all of these in coming articles.

In conclusion, we discussed how to find the Process ID of a program in Ubuntu here.